aboutsummaryrefslogtreecommitdiffstats
path: root/pydis_site/apps/api/tests
diff options
context:
space:
mode:
authorGravatar mbaruh <[email protected]>2023-01-27 23:37:26 +0200
committerGravatar mbaruh <[email protected]>2023-01-28 03:09:23 +0200
commit5f538e9e876adc7f4a459fe230b46bdde61b3f64 (patch)
tree566637dc16d73e0c2cd025db46b85999f136246b /pydis_site/apps/api/tests
parentMerge branch 'main' into new-filter-schema (diff)
Make filter unique constraint use NULLS NOT DISTINCT
The existing constraint was ineffective as null values were considered distinct, and so two filters with the same content and no overrides were considered different. This change uses a new PSQL 15 feature unsupported in django currently, and so it is added with raw SQL.
Diffstat (limited to 'pydis_site/apps/api/tests')
-rw-r--r--pydis_site/apps/api/tests/test_filters.py12
1 files changed, 12 insertions, 0 deletions
diff --git a/pydis_site/apps/api/tests/test_filters.py b/pydis_site/apps/api/tests/test_filters.py
index cae78cd6..73c8e0d9 100644
--- a/pydis_site/apps/api/tests/test_filters.py
+++ b/pydis_site/apps/api/tests/test_filters.py
@@ -327,3 +327,15 @@ class FilterValidationTests(AuthenticatedAPITestCase):
f"{base_filter_list.url()}/{case_fl.id}", data=clean_test_json(filter_list_settings)
)
self.assertEqual(response.status_code, response_code)
+
+ def test_filter_unique_constraint(self) -> None:
+ test_filter = get_test_sequences()["filter"]
+ test_filter.model.objects.all().delete()
+ test_filter_object = test_filter.model(**test_filter.object)
+ save_nested_objects(test_filter_object, False)
+
+ response = self.client.post(test_filter.url(), data=clean_test_json(test_filter.object))
+ self.assertEqual(response.status_code, 201)
+
+ response = self.client.post(test_filter.url(), data=clean_test_json(test_filter.object))
+ self.assertEqual(response.status_code, 400)