feat: added brand model
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
from rest_framework import status
|
||||
from rest_framework.test import APITestCase
|
||||
|
||||
from config.tests.mixins import TestUserAuthenticationMixin
|
||||
from shop.models import Brand
|
||||
|
||||
|
||||
class TestBrandsAPI(APITestCase, TestUserAuthenticationMixin):
|
||||
model_name = "brand"
|
||||
|
||||
def setUp(self):
|
||||
self.create_user()
|
||||
|
||||
def create_brands(self):
|
||||
Brand.objects.create(
|
||||
name="Marca",
|
||||
)
|
||||
|
||||
def test_fetch_brands(self):
|
||||
self.create_brands()
|
||||
self.login()
|
||||
response = self.client.get("/api/v1/shop/brands/")
|
||||
assert response.status_code == status.HTTP_200_OK
|
||||
assert len(response.data.get("results")) == 1
|
||||
|
||||
def test_create_retrieve_brand(self):
|
||||
self.login()
|
||||
response = self.client.post("/api/v1/shop/brands/", {"name": "Marca 1"})
|
||||
assert response.status_code == status.HTTP_201_CREATED
|
||||
pk = response.data.get("id")
|
||||
|
||||
response = self.client.get(f"/api/v1/shop/brands/{pk}/")
|
||||
assert response.status_code == status.HTTP_200_OK
|
||||
|
||||
def test_create_update_brand(self):
|
||||
self.login()
|
||||
response = self.client.post("/api/v1/shop/brands/", {"name": "Marca 1"})
|
||||
assert response.status_code == status.HTTP_201_CREATED
|
||||
pk = response.data.get("id")
|
||||
|
||||
response = self.client.get(f"/api/v1/shop/brands/{pk}/")
|
||||
assert response.status_code == status.HTTP_200_OK
|
||||
|
||||
response = self.client.patch(f"/api/v1/shop/brands/{pk}/", {"name": "Marca 2"})
|
||||
assert response.status_code == status.HTTP_200_OK
|
||||
|
||||
response = self.client.get(f"/api/v1/shop/brands/{pk}/")
|
||||
assert response.status_code == status.HTTP_200_OK
|
||||
|
||||
assert response.data.get("name") == "Marca 2"
|
||||
Reference in New Issue
Block a user