Exemplo n.º 1
0
 def setUpTestData(cls):
     cls.user = get_user_model().objects.create_superuser(
         username='******',
         email='*****@*****.**',
         password='******',
         is_active=True)
     cls.product = ProductFactory()
     cls.item = WarehouseItemFactory(product=cls.product)
     warehouse_item_component = WarehouseItemComponentFactory(item=cls.item,
                                                              quantity=2)
     cls.component = warehouse_item_component.component
     cls.detail_url = reverse('warehouse-items-detail',
                              kwargs={'pk': cls.product.pk})
     cls.list_url = reverse('warehouse-items-list')
Exemplo n.º 2
0
    def test_create(self):
        product = ProductFactory()
        component = WarehouseComponentFactory()
        data = {
            'product_id':
            product.id,
            'warehouse_components_list': [{
                'component_id': component.id,
                'quantity': 2
            }],
        }

        response = self.client.post(self.list_url,
                                    data=json.dumps(data),
                                    content_type='application/json')
        self.assertTrue(is_success(response.status_code), response.data)

        data = response.data

        self.assertEqual(data['product']['id'], product.id, data)
        self.assertEqual(data['product']['name'], product.name, data)
        self.assertEqual(data['warehouse_components'][0]['component']['name'],
                         component.name, data)
Exemplo n.º 3
0
    def test_update(self):
        product = ProductFactory()
        WarehouseItemFactory(product=product)
        detail_url = reverse('warehouse-items-detail',
                             kwargs={'pk': product.pk})
        data = {
            'warehouse_components_list': [{
                'component_id': self.component.id,
                'quantity': 3
            }],
            'product_id':
            product.id,
        }

        response = self.client.patch(detail_url,
                                     data=json.dumps(data),
                                     content_type='application/json')

        self.assertTrue(is_success(response.status_code))

        data = response.data

        self.assertEqual(data['warehouse_components'][0]['quantity'], 3, data)
        self.assertEqual(data['product']['id'], product.id, data)
Exemplo n.º 4
0
from django.test import TestCase

from shop.factories.product import ProductFactory
from utils.test_clients import ModelStrTestCaseMixin
from warehouse.factories.storage import StorageUnitFactory
from warehouse.factories.warehouse import (
    WarehouseComponentFactory, WarehouseItemFactory
)
from warehouse.models.storage import (
    StorageUnitComponent, StorageUnit,
)
from warehouse.models.warehouse import (
    WarehouseComponent, WarehouseItem, WarehouseItemComponent,
)
product = ProductFactory()
storage_unit = StorageUnitFactory()
warehouse_component = WarehouseComponentFactory()
warehouse_item = WarehouseItemFactory(product=product)


class WarehouseComponentTestCase(TestCase, ModelStrTestCaseMixin):
    obj = WarehouseComponent(name='A')
    string = 'A'


class WarehouseItemTestCase(TestCase, ModelStrTestCaseMixin):
    obj = WarehouseItem(product=product)
    string = product.__str__()


class WarehouseItemComponentTestCase(TestCase, ModelStrTestCaseMixin):
Exemplo n.º 5
0
class ProductNameTestCase(TestCase, ModelStrTestCaseMixin):
    obj = ProductFactory(name='A')
    string = 'A'
Exemplo n.º 6
0
 def setUp(self) -> None:
     self.product = ProductFactory()
Exemplo n.º 7
0
class ProductModelTestCase(TestCase):
    def setUp(self) -> None:
        self.product = ProductFactory()

    def test_publish(self):
        self.product.publish()
        self.product.save()
        self.assertEqual(self.product.status, Product.PUBLISHED)

    def test_unpublish(self):
        self.product.publish()
        self.product.save()
        self.assertEqual(self.product.status, Product.PUBLISHED)
        self.product.unpublish()
        self.product.save()
        self.assertEqual(self.product.status, Product.DRAFT)

    def test_get_published(self):
        self.product.publish()
        self.product.save()
        self.assertIn(self.product, Product.objects.get_published())