Skip to content

Commit

Permalink
server/custom_field: allow underscores in custom field slugs
Browse files Browse the repository at this point in the history
  • Loading branch information
frankie567 committed Nov 12, 2024
1 parent 339723f commit dbbc109
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
4 changes: 1 addition & 3 deletions server/polar/custom_field/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
IDSchema,
Schema,
SetSchemaReference,
SlugValidator,
TimestampedSchema,
)
from polar.models.custom_field import (
Expand All @@ -26,8 +25,7 @@

Slug = Annotated[
str,
SlugValidator,
StringConstraints(to_lower=True, min_length=1),
StringConstraints(to_lower=True, min_length=1, pattern=r"^[a-z0-9-_]+$"),
Field(
description=(
"Identifier of the custom field. "
Expand Down
4 changes: 4 additions & 0 deletions server/tests/custom_field/test_schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
"input",
(
pytest.param({"slug": ""}, id="empty slug"),
pytest.param({"slug": "aaa bbb"}, id="invalid slug 1"),
pytest.param({"slug": "888!"}, id="invalid slug 2"),
pytest.param({"name": ""}, id="empty name"),
pytest.param({"properties": {"form_label": ""}}, id="empty form label"),
pytest.param({"properties": {"form_help_text": ""}}, id="empty form help text"),
Expand Down Expand Up @@ -72,6 +74,8 @@ def test_invalid_create(input: dict[str, Any]) -> None:
CustomFieldType.select,
id="select",
),
pytest.param({"slug": "valid_slug"}, CustomFieldType.text, id="valid slug 1"),
pytest.param({"slug": "_valid_slug2"}, CustomFieldType.text, id="valid slug 2"),
),
)
def test_valid_create(input: dict[str, Any], expected_type: CustomFieldType) -> None:
Expand Down

0 comments on commit dbbc109

Please sign in to comment.