From a7386454a6c71ee3c650a6c86c1ebf9bcb63c1db Mon Sep 17 00:00:00 2001 From: Pablo Moreno Date: Sat, 23 Nov 2024 00:24:35 +0100 Subject: [PATCH] chore: improve coverage --- .coveragerc | 10 +++++++++ shop/tests/api/test_api_product_batches.py | 26 ++++++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/.coveragerc b/.coveragerc index ff6415d..b2b81fc 100644 --- a/.coveragerc +++ b/.coveragerc @@ -5,3 +5,13 @@ exclude_lines = # Don't complain if tests don't hit defensive assertion code: raise NotImplementedError + +[run] +omit = + # omit anything in a .local directory anywhere + */.idea/* + */src/* + */**/admin.py + */**/asgi.py + */**/wsgi.py + */**/celery.py diff --git a/shop/tests/api/test_api_product_batches.py b/shop/tests/api/test_api_product_batches.py index 04a83f4..e67c439 100644 --- a/shop/tests/api/test_api_product_batches.py +++ b/shop/tests/api/test_api_product_batches.py @@ -92,3 +92,29 @@ class TestProductBatchesAPI(APITestCase, TestUserAuthenticationMixin): response = self.client.get(f"/api/v1/shop/product-batches/{pk}/") assert response.status_code == status.HTTP_200_OK assert Decimal(response.data.get("quantity")) == Decimal("10") + + def test_create_delete_product_batch(self): + self.login() + self.create_product() + provider = self.create_provider() + + response = self.client.post( + "/api/v1/shop/product-batches/", + { + "code": "B00001", + "product": self.product.pk, + "quantity": "5", + "provider": provider.pk, + }, + ) + assert response.status_code == status.HTTP_201_CREATED + pk = response.data.get("id") + + response = self.client.get(f"/api/v1/shop/product-batches/{pk}/") + assert response.status_code == status.HTTP_200_OK + + self.product.refresh_from_db() + assert self.product.stock == Decimal("5") + + response = self.client.delete(f"/api/v1/shop/product-batches/{pk}/") + assert response.status_code == status.HTTP_204_NO_CONTENT