Skip to content
This repository has been archived by the owner on Jun 8, 2023. It is now read-only.

Commit

Permalink
✅ Add tests for VerzoekProduct unique together validation
Browse files Browse the repository at this point in the history
  • Loading branch information
stevenbal committed Dec 23, 2020
1 parent 260f7df commit 36590be
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions src/verzoeken/api/tests/test_verzoekproduct.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,22 @@ def test_create_verzoekproduct_with_invalid_product_url(self):
error = get_validation_errors(response, "product")
self.assertEqual(error["code"], "bad-url")

def test_create_verzoekproduct_with_product_url_not_unique(self):
verzoek = VerzoekFactory.create()
verzoek_url = reverse(verzoek)

VerzoekProductFactory.create(verzoek=verzoek, product="https://example.com/")

list_url = reverse(VerzoekProduct)
data = {"verzoek": verzoek_url, "product": "https://example.com/"}

response = self.client.post(list_url, data)

self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)

error = get_validation_errors(response, "nonFieldErrors")
self.assertEqual(error["code"], "unique")

def test_create_verzoekproduct_with_product_id(self):
verzoek = VerzoekFactory.create()
verzoek_url = reverse(verzoek)
Expand All @@ -133,6 +149,22 @@ def test_create_verzoekproduct_with_product_id(self):
verzoekproduct.product_code, data["productIdentificatie"]["code"]
)

def test_create_verzoekproduct_with_product_id_not_unique(self):
verzoek = VerzoekFactory.create()
verzoek_url = reverse(verzoek)

VerzoekProductFactory.create(verzoek=verzoek, product_code="test")

list_url = reverse(VerzoekProduct)
data = {"verzoek": verzoek_url, "productIdentificatie": {"code": "test"}}

response = self.client.post(list_url, data)

self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)

error = get_validation_errors(response, "nonFieldErrors")
self.assertEqual(error["code"], "unique")

def test_create_verzoekproduct_without_product(self):
verzoek = VerzoekFactory.create()
verzoek_url = reverse(verzoek)
Expand Down

0 comments on commit 36590be

Please sign in to comment.