feat: added lots of tests

This commit is contained in:
2024-05-13 12:35:58 +02:00
parent 05caeb9607
commit 9d83c3b30f
8 changed files with 545 additions and 0 deletions
+66
View File
@@ -0,0 +1,66 @@
from rest_framework import status
from rest_framework.test import APITestCase
from config.tests.mixins import TestUserAuthenticationMixin
class TestCustomersAPI(APITestCase, TestUserAuthenticationMixin):
model_name = "customer"
def setUp(self):
self.create_user()
def test_create_retrieve_customer(self):
self.login()
response = self.client.post(
f"/api/v1/shop/customers/",
{
"vat_id": "11111111H",
"first_name": "Darth",
"last_name": "Maull",
"email": "darth@maul.com",
"address": "Dathomir",
"city": "Dathomir",
"state": "Dathomir",
"country": "Dathomir",
"zip": "00001",
},
)
assert response.status_code == status.HTTP_201_CREATED
pk = response.data.get("id")
response = self.client.get(f"/api/v1/shop/customers/{pk}/")
assert response.status_code == status.HTTP_200_OK
def test_create_update_customer(self):
self.login()
response = self.client.post(
f"/api/v1/shop/customers/",
{
"vat_id": "11111111H",
"first_name": "Darth",
"last_name": "Maull",
"email": "darth@maul.com",
"address": "Dathomir",
"city": "Dathomir",
"state": "Dathomir",
"country": "Dathomir",
"zip": "00001",
},
)
assert response.status_code == status.HTTP_201_CREATED
pk = response.data.get("id")
response = self.client.get(f"/api/v1/shop/customers/{pk}/")
assert response.status_code == status.HTTP_200_OK
response = self.client.patch(
f"/api/v1/shop/customers/{pk}/",
{
"address": "Mandalore",
},
)
assert response.status_code == status.HTTP_200_OK
response = self.client.get(f"/api/v1/shop/customers/{pk}/")
assert response.status_code == status.HTTP_200_OK
assert response.data.get("address") == "Mandalore"