コード例 #1
0
 def test_get_item(self):
     item1 = CatalogItemFactory(description='item1')
     CatalogItemFactory(description='item2')
     rsp = self.call_api('/api/catalog/items/%d/' % item1.pk)
     self.assertEqual(200, rsp.status_code)
     data = json.loads(rsp.content)
     self.assertEqual(item1.description, data['description'])
コード例 #2
0
 def test_list_items(self):
     CatalogItemFactory(description='item1')
     CatalogItemFactory(description='item2')
     rsp = self.call_api('/api/catalog/items/')
     self.assertEqual(200, rsp.status_code)
     data = json.loads(rsp.content)['results']
     item_descriptions = [item['description'] for item in data]
     self.assertIn('item1', item_descriptions)
     self.assertIn('item2', item_descriptions)
コード例 #3
0
 def test_add_too_many_of_item_to_kit(self):
     item1 = CatalogItemFactory()
     kit = KitFactory()
     quantity = MAX_QUANTITY + 1
     url = reverse('add_item_to_kit', args=[kit.pk, item1.pk, quantity])
     rsp = self.client.post(url)
     self.assertEqual(400, rsp.status_code)
コード例 #4
0
 def test_update(self):
     # Update an item
     cat = ItemCategoryFactory()
     description = "The meow of a cat"
     item = CatalogItemFactory(item_category=cat, description=description)
     url = reverse('edit_catalog_item_modal', args=[item.pk])
     rsp = self.client.get(url)
     self.assertEqual(200, rsp.status_code)
     # Submit the new object
     description2 = "The bark of a dog"
     data = {
         'item_code': item.item_code,
         'description': description2,
         'unit': 'purr',
         'weight': str(1.005),
         'price_local': '1.23',
         'price_usd': '4.07',
         'item_category': cat.pk,
         'quantity': 3,
     }
     rsp = self.client.post(url, data=data)
     if rsp.status_code == 400:
         self.fail(rsp.context['form'].errors)
     self.assertEqual(rsp.status_code, 200)
     item2 = CatalogItem.objects.get(description=description2)
     self.assertEqual(item.pk, item2.pk)
コード例 #5
0
 def test_add_items_to_kit(self):
     item1 = CatalogItemFactory()
     item2 = CatalogItemFactory()
     kit = KitFactory()
     quantity1 = 50
     quantity2 = 60
     url = reverse('catalog_list')
     data = {
         'selected_kit': kit.pk,
         'quantity-%d' % item1.pk: quantity1,
         'quantity-%d' % item2.pk: quantity2,
     }
     rsp = self.client.post(url, data)
     self.assertEqual(302, rsp.status_code)
     kit_item = KitItem.objects.get(kit=kit, catalog_item=item1)
     self.assertEqual(quantity1, kit_item.quantity)
     kit_item = KitItem.objects.get(kit=kit, catalog_item=item2)
     self.assertEqual(quantity2, kit_item.quantity)
コード例 #6
0
 def test_add_too_many_items_to_kit(self):
     item1 = CatalogItemFactory()
     item2 = CatalogItemFactory()
     kit = KitFactory()
     quantity1 = 50
     quantity2 = MAX_QUANTITY + 1
     url = reverse('catalog_list')
     data = {
         'selected_kit': kit.pk,
         'quantity-%d' % item1.pk: quantity1,
         'quantity-%d' % item2.pk: quantity2,
     }
     rsp = self.client.post(url, data)
     self.assertEqual(400, rsp.status_code)
     with self.assertRaises(KitItem.DoesNotExist):
         KitItem.objects.get(kit=kit, catalog_item=item1)
     with self.assertRaises(KitItem.DoesNotExist):
         KitItem.objects.get(kit=kit, catalog_item=item2)
コード例 #7
0
 def test_list(self):
     cat = ItemCategoryFactory()
     description = "The meow of a cat"
     CatalogItemFactory(item_category=cat, description=description)
     rsp = self.client.get(reverse('catalog_list'))
     self.assertEqual(200, rsp.status_code)
     self.assertContains(rsp,
                         description,
                         msg_prefix=rsp.content.decode('utf-8'))
コード例 #8
0
 def test_add_item_to_kit(self):
     item1 = CatalogItemFactory()
     kit = KitFactory()
     quantity = 500
     url = reverse('add_item_to_kit', args=[kit.pk, item1.pk, quantity])
     rsp = self.client.post(url)
     self.assertEqual(200, rsp.status_code)
     kit_item = KitItem.objects.get(kit=kit, catalog_item=item1)
     self.assertEqual(quantity, kit_item.quantity)
コード例 #9
0
ファイル: test_views.py プロジェクト: erafighi/CTS
 def setUp(self):
     super(TestPackageItemCreateView, self).setUp()
     self.package = PackageFactory()
     self.catalog_item = CatalogItemFactory()
     self.data = {
         'catalog_item_0': self.catalog_item.description,
         'catalog_item_1': self.catalog_item.pk,
         'quantity': 5,
     }
コード例 #10
0
 def test_delete(self):
     # Delete an item
     cat = ItemCategoryFactory()
     description = "The meow of a cat"
     item = CatalogItemFactory(item_category=cat, description=description)
     url = reverse('catalog_delete', args=[item.pk])
     rsp = self.client.get(url)
     self.assertEqual(200, rsp.status_code)
     self.assertContains(rsp, 'Confirm')
     CatalogItem.objects.get(pk=item.pk)
     # Now delete it!
     rsp = self.client.post(url)
     if rsp.status_code == 400:
         self.fail(rsp.context['form'].errors)
     self.assertRedirects(rsp, reverse('catalog_list'))
     self.assertFalse(CatalogItem.objects.filter(pk=item.pk).exists())
コード例 #11
0
 def test_price_validator(self):
     # No negative price
     cat = ItemCategoryFactory()
     price_local = 5.000
     item = CatalogItemFactory(item_category=cat, price_local=price_local)
     url = reverse('edit_catalog_item_modal', args=[item.pk])
     rsp = self.client.get(url)
     self.assertEqual(200, rsp.status_code)
     # Submit the new object
     data = {
         'item_code': item.item_code,
         'description': 'desc',
         'unit': 'purr',
         'weight': str(item.weight),
         'price_local': '-1.23',
         'price_usd': '4.07',
         'item_category': cat.pk,
     }
     rsp = self.client.post(url, data=data)
     self.assertEqual(400, rsp.status_code)
     self.assertIn('Ensure this value is greater than',
                   rsp.context['form'].errors.as_text())
コード例 #12
0
 def test_item_code(self):
     item = CatalogItemFactory(item_code='hello world')
     qs = self.lookup.get_query(None, 'hello')
     self.assertEqual(len(qs), 1)
     self.assertEqual(qs.get(), item)
コード例 #13
0
 def setUp(self):
     super(TestCatalogItemLookup, self).setUp()
     self.lookup = CatalogItemLookup()
     for i in range(5):
         CatalogItemFactory()
コード例 #14
0
ファイル: test_models.py プロジェクト: trendspotter/CTS
 def setUp(self):
     super(TestPackageItem, self).setUp()
     self.package = PackageFactory()
     self.catalog_item = CatalogItemFactory()
     self.quantity = 5
コード例 #15
0
ファイル: test_models.py プロジェクト: trendspotter/CTS
 def test_from_kit_item_default_prices(self):
     catalog_item = CatalogItemFactory()
     kit_item = KitItemFactory(catalog_item=catalog_item)
     package = PackageFactory()
     PackageItem.from_kit_item(package, kit_item)
コード例 #16
0
 def test_description(self):
     item = CatalogItemFactory(description='hello world')
     qs = self.lookup.get_query(None, 'hello')
     self.assertEqual(len(qs), 1)
     self.assertEqual(qs.get(), item)
コード例 #17
0
 def test_edit_modal(self):
     item = CatalogItemFactory()
     url = reverse('edit_catalog_item_modal', kwargs={'pk': item.pk})
     rsp = self.client.get(url)
     self.assertEqual(200, rsp.status_code)
     self.assertTemplateUsed(rsp, 'catalog/catalogitem_edit_modal.html')