def test_updating_item_with_product(self): Product.objects.create(supply=self.supply, supplier=self.supplier, cost=Decimal('12.11'), purchasing_units="yd") context = {'po': self.po, 'supplier': self.supplier} data = {'supply': self.supply.id, 'unit_cost': Decimal('11.22'), 'quantity': 4, 'units': 'm'} # Verify there is a product products = Product.objects.filter(supply=self.supply, supplier=self.supplier) self.assertEqual(products.count(), 1) self.assertEqual(products[0].cost, Decimal('12.11')) self.assertEqual(products[0].purchasing_units, 'yd') # Update item item_serializer = ItemSerializer(self.item, context=context, data=data) if item_serializer.is_valid(raise_exception=True): item_serializer.save() # Verify product is created products2 = Product.objects.filter(supply=self.supply, supplier=self.supplier) self.assertEqual(products2.count(), 1) self.assertEqual(products2[0].cost, Decimal('11.22')) self.assertEqual(products2[0].purchasing_units, 'm') # Verify item resp_data = item_serializer.data self.assertEqual(resp_data['description'], 'Pattern: Maxx, Col: Blue') self.assertEqual(resp_data['units'], 'm') self.assertEqual(Decimal(resp_data['quantity']), Decimal('4')) self.assertEqual(Decimal(resp_data['total']), Decimal('44.88'))
def test_updating_item_without_product(self): context = {'po': self.po, 'supplier': self.supplier} data = {'supply': self.supply.id, 'unit_cost': Decimal('11.22'), 'quantity': 4, 'units': 'yd'} # Verify there is no product self.assertEqual(Product.objects.filter(supply=self.supply, supplier=self.supplier).count(), 0) # Update item item_serializer = ItemSerializer(self.item, context=context, data=data) if item_serializer.is_valid(raise_exception=True): item_serializer.save() # Verify product is created self.assertEqual(Product.objects.filter(supply=self.supply, supplier=self.supplier).count(), 1) # Verify item resp_data = item_serializer.data self.assertEqual(resp_data['description'], 'Pattern: Maxx, Col: Blue') self.assertEqual(resp_data['units'], 'yd') self.assertEqual(Decimal(resp_data['quantity']), Decimal('4')) self.assertEqual(Decimal(resp_data['total']), Decimal('44.88'))
def test_creating_item_with_product_with_no_unit_cost(self): """Test creating a item via the serializer where there is no product """ Product.objects.create(supply=self.supply, supplier=self.supplier, cost=Decimal('12.11'), purchasing_units="yd") context = {'po': self.po, 'supplier': self.supplier} data = {'supply': self.supply.id, 'quantity': 5, 'units': 'yd'} item_serializer = ItemSerializer(context=context, data=data) if item_serializer.is_valid(raise_exception=True): item_serializer.save() # Verify product is created self.assertEqual(Product.objects.filter(supply=self.supply, supplier=self.supplier).count(), 1) # Verify item resp_data = item_serializer.data self.assertEqual(resp_data['description'], 'Pattern: Maxx, Col: Blue') self.assertEqual(resp_data['units'], 'yd') self.assertEqual(Decimal(resp_data['quantity']), Decimal('5')) self.assertEqual(Decimal(resp_data['total']), Decimal('60.55'))
def test_updating_item_without_product(self): context = {'po': self.po, 'supplier': self.supplier} data = { 'supply': { 'id': self.supply.id }, 'unit_cost': Decimal('11.22'), 'quantity': 4, 'units': 'yd' } # Verify there is no product self.assertEqual( Product.objects.filter(supply=self.supply, supplier=self.supplier).count(), 0) # Update item item_serializer = ItemSerializer(self.item, context=context, data=data) if item_serializer.is_valid(raise_exception=True): item_serializer.save() # Verify product is created self.assertEqual( Product.objects.filter(supply=self.supply, supplier=self.supplier).count(), 1) # Verify item resp_data = item_serializer.data self.assertEqual(resp_data['description'], 'Pattern: Maxx, Col: Blue') self.assertEqual(resp_data['units'], 'yd') self.assertEqual(Decimal(resp_data['quantity']), Decimal('4')) self.assertEqual(Decimal(resp_data['total']), Decimal('44.88'))
def test_creating_item_with_product_with_no_unit_cost(self): """Test creating a item via the serializer where there is no product """ Product.objects.create(supply=self.supply, supplier=self.supplier, cost=Decimal('12.11'), purchasing_units="yd") context = {'po': self.po, 'supplier': self.supplier} data = {'supply': {'id': self.supply.id}, 'quantity': 5, 'units': 'yd'} item_serializer = ItemSerializer(context=context, data=data) if item_serializer.is_valid(raise_exception=True): item_serializer.save() # Verify product is created self.assertEqual( Product.objects.filter(supply=self.supply, supplier=self.supplier).count(), 1) # Verify item resp_data = item_serializer.data self.assertEqual(resp_data['description'], 'Pattern: Maxx, Col: Blue') self.assertEqual(resp_data['units'], 'yd') self.assertEqual(Decimal(resp_data['quantity']), Decimal('5')) self.assertEqual(Decimal(resp_data['total']), Decimal('60.55'))
def test_updating_item_with_product(self): Product.objects.create(supply=self.supply, supplier=self.supplier, cost=Decimal('12.11'), purchasing_units="yd") context = {'po': self.po, 'supplier': self.supplier} data = { 'supply': { 'id': self.supply.id }, 'unit_cost': Decimal('11.22'), 'quantity': 4, 'units': 'm' } # Verify there is a product products = Product.objects.filter(supply=self.supply, supplier=self.supplier) self.assertEqual(products.count(), 1) self.assertEqual(products[0].cost, Decimal('12.11')) self.assertEqual(products[0].purchasing_units, 'yd') # Update item item_serializer = ItemSerializer(self.item, context=context, data=data) if item_serializer.is_valid(raise_exception=True): item_serializer.save() # Verify product is created products2 = Product.objects.filter(supply=self.supply, supplier=self.supplier) self.assertEqual(products2.count(), 1) self.assertEqual(products2[0].cost, Decimal('11.22')) self.assertEqual(products2[0].purchasing_units, 'm') # Verify item resp_data = item_serializer.data self.assertEqual(resp_data['description'], 'Pattern: Maxx, Col: Blue') self.assertEqual(resp_data['units'], 'm') self.assertEqual(Decimal(resp_data['quantity']), Decimal('4')) self.assertEqual(Decimal(resp_data['total']), Decimal('44.88'))