Browse Source

SlugStr should have a max length

David Burke 9 months ago
parent
commit
7acd4cc9c6
2 changed files with 4 additions and 1 deletions
  1. 1 1
      apps/shared/schema/fields.py
  2. 3 0
      apps/teams/tests/test_api.py

+ 1 - 1
apps/shared/schema/fields.py

@@ -2,4 +2,4 @@ from typing import Annotated
 
 from pydantic import Field
 
-SlugStr = Annotated[str, Field(pattern=r"^[-a-zA-Z0-9_]+$")]
+SlugStr = Annotated[str, Field(pattern=r"^[-a-zA-Z0-9_]+$", max_length=50)]

+ 3 - 0
apps/teams/tests/test_api.py

@@ -63,6 +63,9 @@ class TeamAPITestCase(TestCase):
         data = {"slug": "te$m"}
         res = self.client.post(url, data, content_type="application/json")
         self.assertEqual(res.status_code, 422)
+        data["slug"] = "t" * 51
+        res = self.client.post(url, data, content_type="application/json")
+        self.assertEqual(res.status_code, 422)
         data["slug"] = "team"
         res = self.client.post(url, data, content_type="application/json")
         self.assertContains(res, data["slug"], status_code=201)