67 lines
2.1 KiB
Python
67 lines
2.1 KiB
Python
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"
|