Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/add textarea node #11

Merged
merged 4 commits into from
Jan 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
dist/
db.sqlite3
db.sqlite3
.coverage
3 changes: 1 addition & 2 deletions formkit_ninja/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,8 +359,7 @@ def preferred_name(self):
return disambiguate_name(make_name_valid_id(self.name), self.parent_names)
elif self.label is not None:
return disambiguate_name(make_name_valid_id(self.label), self.parent_names)
else:
return f"{uuid4().hex[:8]}_unnamed"
return make_name_valid_id(f"{uuid4().hex[:8]}_unnamed")

class Config:
allow_population_by_field_name = True
Expand Down
8 changes: 8 additions & 0 deletions formkit_ninja/formkit_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,11 @@ class TextNode(FormKitSchemaProps):
text: str | None


class TextAreaNode(TextNode):
formkit: Literal["textarea"] = Field(default="textarea", alias="$formkit")
text: str | None


class DateNode(TextNode):
formkit: Literal["date"] = Field(default="date", alias="$formkit")

Expand Down Expand Up @@ -233,6 +238,7 @@ class GroupNode(TextNode):
# which do not work with "Annotated" below
FormKitType = (
TextNode
| TextAreaNode
| CheckBoxNode
| PasswordNode
| SelectNode
Expand All @@ -254,6 +260,7 @@ class GroupNode(TextNode):
FormKitSchemaFormKit = Annotated[
Union[
TextNode,
TextAreaNode,
CheckBoxNode,
PasswordNode,
SelectNode,
Expand Down Expand Up @@ -385,6 +392,7 @@ def handle_data(self, data):
NODE_TYPE = Literal["condition", "formkit", "element", "component"]
FORMKIT_TYPE = Literal[
"text",
"textarea",
"tel",
"currency",
"select",
Expand Down
2 changes: 1 addition & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "formkit-ninja"
version = "0.7.2"
version = "0.7.4"
description = "A Django-Ninja backend to specify FormKit schemas"
authors = ["Josh Brooks <josh@catalpa.io>"]
license = "GPLv3"
Expand All @@ -19,6 +19,7 @@ django-stubs = {extras = ["compatible-mypy"], version = "^4.2.3"}
django-pgtrigger = "^4.7.0"
rich = "*"
django-pghistory = "^3.0.1"
pytest-cov = "^4.1.0"

[tool.poetry.group.dev]
optional = true
Expand Down
22 changes: 22 additions & 0 deletions tests/test_formkit_in.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,25 @@ def test_node_create(admin_client: Client):
content_type="application/json",
)
assert node_post_4.json()["node"]["name"] == "name_of_my_input"


@pytest.mark.django_db
def test_textarea_create(admin_client: Client):
"""
Test creation of a Formkit TextArea node through the API
"""
path = reverse("api-1.0.0:create_or_update_node")
# Add a group node
# This is a 'partisipa' type group node with
# an icon and a label
group = FormKitNodeIn(
**{"$formkit": "textarea"}
)
data = group.json(exclude_none=True)

response = admin_client.post(
path=path,
data=data,
content_type="application/json",
)
assert response.status_code == HTTPStatus.OK
10 changes: 2 additions & 8 deletions tests/test_pw.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from django.contrib.auth import get_user_model
from django.contrib.auth.models import User
from playwright.sync_api import Browser, Page
from pytest_django.fixtures import live_server, live_server_helper
from pytest_django.fixtures import live_server, live_server_helper, admin_user
from pytest_playwright.pytest_playwright import page

from formkit_ninja import models
Expand All @@ -31,18 +31,12 @@
os.environ.setdefault("DJANGO_ALLOW_ASYNC_UNSAFE", "true")


@pytest.fixture()
def admin_user():
UserModel: Type[User] = get_user_model()
user = UserModel.objects.create_superuser(username="admin", email="admin@catalpa.io", password="12341234")
return user


@pytest.fixture()
def admin_page(page: Page, live_server: live_server_helper.LiveServer, admin_user: User):
page.goto(f"{live_server.url}/admin", timeout=1000)
page.get_by_label("Username:").fill(admin_user.username)
page.get_by_label("Password:").fill("12341234")
page.get_by_label("Password:").fill("password")
page.get_by_role("button", name="Log in").click()
page.context.set_default_timeout(5000)
yield page
Expand Down
2 changes: 2 additions & 0 deletions tests/test_textarea.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@