feat: added tests for web

This commit is contained in:
2024-11-22 22:09:10 +01:00
parent b057b70a31
commit 8d6eb3d61c
17 changed files with 61 additions and 8 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"