from rest_framework import status from rest_framework.test import APITestCase from config.tests.mixins import TestUserAuthenticationMixin class TestProvidersAPI(APITestCase, TestUserAuthenticationMixin): model_name = "provider" def setUp(self): self.create_user() def test_create_retrieve_provider(self): self.login() response = self.client.post( f"/api/v1/shop/providers/", { "vat_id": "11111111H", "name": "Darth Maul", "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/providers/{pk}/") assert response.status_code == status.HTTP_200_OK def test_create_update_provider(self): self.login() response = self.client.post( f"/api/v1/shop/providers/", { "vat_id": "11111111H", "name": "Darth Maul", "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/providers/{pk}/") assert response.status_code == status.HTTP_200_OK response = self.client.patch( f"/api/v1/shop/providers/{pk}/", { "address": "Mandalore", }, ) assert response.status_code == status.HTTP_200_OK response = self.client.get(f"/api/v1/shop/providers/{pk}/") assert response.status_code == status.HTTP_200_OK assert response.data.get("address") == "Mandalore"