Skip to content

Commit

Permalink
update api spec
Browse files Browse the repository at this point in the history
  • Loading branch information
Floris272 committed Sep 17, 2024
1 parent 00dd2c8 commit f0292ee
Show file tree
Hide file tree
Showing 2 changed files with 163 additions and 219 deletions.
30 changes: 15 additions & 15 deletions src/open_producten/products/tests/api/test_product.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def test_read_product_without_credentials_returns_error(self):
response = self.client.get(self.path)
self.assertEqual(response.status_code, 401)

def create_product(self):
def _create_product(self):
return ProductFactory.create(bsn="111222333")

def test_create_product(self):
Expand Down Expand Up @@ -218,7 +218,7 @@ def test_create_product_with_data_for_field_not_part_of_product_type_returns_err
self.assertEqual(Field.objects.count(), 1)

def test_update_product(self):
product = self.create_product()
product = self._create_product()

data = self.data | {"end_date": datetime.date(2025, 12, 31)}
response = self.put(product.id, data)
Expand All @@ -227,7 +227,7 @@ def test_update_product(self):
self.assertEqual(Product.objects.count(), 1)

def test_update_product_without_bsn_or_kvk(self):
product = self.create_product()
product = self._create_product()

data = self.data.copy()
data.pop("bsn")
Expand All @@ -250,7 +250,7 @@ def test_update_product_data(self):
field = FieldFactory.create(
product_type=self.product_type, type=FieldTypes.TEXTFIELD, is_required=True
)
product = self.create_product()
product = self._create_product()
data_instance = DataFactory.create(product=product, field=field, value="abc")

data = self.data | {"data": [{"id": data_instance.id, "value": "123"}]}
Expand All @@ -267,7 +267,7 @@ def test_update_product_with_duplicate_data_ids_returns_error(self):
field = FieldFactory.create(
product_type=self.product_type, type=FieldTypes.TEXTFIELD, is_required=True
)
product = self.create_product()
product = self._create_product()
data_instance = DataFactory.create(product=product, field=field, value="abc")

data = self.data | {
Expand Down Expand Up @@ -298,9 +298,9 @@ def test_update_product_with_data_not_part_of_product_returns_error(
field = FieldFactory.create(
product_type=self.product_type, type=FieldTypes.TEXTFIELD, is_required=True
)
product = self.create_product()
product = self._create_product()
data_instance = DataFactory.create(
product=self.create_product(), field=field, value="abc"
product=self._create_product(), field=field, value="abc"
)

data = self.data | {
Expand Down Expand Up @@ -329,7 +329,7 @@ def test_update_product_with_no_existing_data_object_returns_error(
FieldFactory.create(
product_type=self.product_type, type=FieldTypes.TEXTFIELD, is_required=True
)
product = self.create_product()
product = self._create_product()

dummy_id = uuid.uuid4()

Expand Down Expand Up @@ -357,7 +357,7 @@ def test_update_product_with_invalid_data_returns_error(self):
field = FieldFactory.create(
product_type=self.product_type, type=FieldTypes.NUMBER, is_required=True
)
product = self.create_product()
product = self._create_product()
data_instance = DataFactory.create(product=product, field=field, value="123")

data = self.data | {
Expand All @@ -381,7 +381,7 @@ def test_update_product_with_invalid_data_returns_error(self):
)

def test_partial_update_product(self):
product = self.create_product()
product = self._create_product()

data = {"end_date": datetime.date(2025, 12, 31)}
response = self.patch(product.id, data)
Expand All @@ -393,7 +393,7 @@ def test_partial_update_product_data(self):
field = FieldFactory.create(
product_type=self.product_type, type=FieldTypes.TEXTFIELD, is_required=True
)
product = self.create_product()
product = self._create_product()
data_instance = DataFactory.create(product=product, field=field, value="abc")

data = {"data": [{"id": data_instance.id, "value": "123"}]}
Expand All @@ -407,23 +407,23 @@ def test_partial_update_product_data(self):
self.assertEqual(data_instance.value, "123")

def test_read_products(self):
product = self.create_product()
product = self._create_product()

response = self.get()

self.assertEqual(response.status_code, 200)
self.assertEqual(response.data, [product_to_dict(product)])

def test_read_product(self):
product = self.create_product()
product = self._create_product()

response = self.get(product.id)

self.assertEqual(response.status_code, 200)
self.assertEqual(response.data, product_to_dict(product))

def test_read_product_with_data(self):
product = self.create_product()
product = self._create_product()
field = FieldFactory.create(
product_type=self.product_type, is_required=True, type="textfield"
)
Expand All @@ -433,7 +433,7 @@ def test_read_product_with_data(self):
self.assertEqual(response.data, product_to_dict(product))

def test_delete_product(self):
product = self.create_product()
product = self._create_product()
response = self.delete(product.id)

self.assertEqual(response.status_code, 204)
Expand Down
Loading

0 comments on commit f0292ee

Please sign in to comment.