コード例 #1
0
ファイル: test_views.py プロジェクト: erafighi/CTS
 def setUp(self):
     super(PackageDeleteViewTestCase, self).setUp()
     self.package = PackageFactory(shipment=self.shipment)
     self.package_items = [
         PackageItemFactory(package=self.package),
         PackageItemFactory(package=self.package),
     ]
     self.url = reverse('package_delete', kwargs={'pk': self.package.pk})
コード例 #2
0
ファイル: test_db_views.py プロジェクト: trendspotter/CTS
 def test_prices_and_num_items(self):
     pkg = PackageFactory()
     PackageItemFactory(package=pkg,
                        quantity=2, price_usd=Decimal("3.0"), price_local=Decimal("4.0"))
     PackageItemFactory(package=pkg,
                        quantity=3, price_usd=Decimal("1.0"), price_local=Decimal("0.3"))
     pkg = PackageDBView.objects.get(pk=pkg.pk)
     self.assertEqual(Decimal("9.0"), pkg.price_usd)
     self.assertEqual(Decimal("8.9"), pkg.price_local)
     self.assertEqual(5, pkg.num_items)
コード例 #3
0
ファイル: test_db_views.py プロジェクト: trendspotter/CTS
 def test_shipment_db_view_one_package_with_items(self):
     # 1 package, with items
     package = PackageFactory(shipment=self.shipment)
     PackageItemFactory(package=package, quantity=1,
                        price_usd=Decimal('1.00'), price_local=Decimal('0.001'))
     PackageItemFactory(package=package, quantity=2,
                        price_usd=Decimal('2.00'), price_local=Decimal('0.002'))
     shipment = ShipmentDBView.objects.get(pk=self.shipment.pk)
     self.assertEqual(1, shipment.packages.count())
     self.assertEqual(1, shipment.num_packages)
     self.assertEqual(3, shipment.num_items)
     self.assertEqual(0, shipment.num_received_items)
     self.assertEqual(Decimal('5.0'), shipment.price_usd)
     self.assertEqual(Decimal('0.005'), shipment.price_local)
コード例 #4
0
 def test_package_price(self):
     shipment = ShipmentFactory()
     package = PackageFactory(shipment=shipment)
     item1 = PackageItemFactory(package=package,
                                price_usd=Decimal('1.23'),
                                quantity=2)
     item2 = PackageItemFactory(package=package,
                                price_usd=Decimal('9.11'),
                                quantity=3)
     expected_price = quantize_usd(Decimal(item1.quantity * item1.price_usd
                                           + item2.quantity * item2.price_usd))
     pkg = PackageDBView.objects.get(pk=package.pk)
     price = pkg.price_usd
     self.assertEqual(expected_price, price)
コード例 #5
0
    def test_delete_referenced_kit(self):
        kit = KitFactory()
        KitItemFactory(kit=kit)
        PackageItemFactory(package__kit=kit)

        url = reverse('kit_delete', kwargs={'pk': kit.pk})
        rsp = self.client.post(url)
        success_url = reverse('catalog_list')
        self.assertRedirects(rsp, success_url)
        self.assertFalse(Kit.objects.filter(pk=kit.pk).exists())
コード例 #6
0
 def test_shipment_price(self):
     shipment = ShipmentFactory()
     package1 = PackageFactory(shipment=shipment)
     PackageItemFactory(package=package1,
                        price_usd=Decimal('1.23'),
                        quantity=2)
     PackageItemFactory(package=package1,
                        price_usd=Decimal('9.11'),
                        quantity=3)
     package2 = PackageFactory(shipment=shipment)
     PackageItemFactory(package=package2,
                        price_usd=Decimal('3.14'),
                        quantity=13)
     pkgs = PackageDBView.objects.filter(pk__in=[package1.pk, package2.pk])
     price_sum = sum([pkg.price_usd for pkg in pkgs])
     expected_price = quantize_usd(price_sum)
     ship = ShipmentDBView.objects.get(pk=shipment.pk)
     price = ship.price_usd
     self.assertEqual(expected_price, price)
コード例 #7
0
    def setUpClass(cls):
        super(ReportTestMixin, cls).setUpClass()
        bootstrap_permissions()

        cls.partner1 = PartnerFactory()
        cls.partner2 = PartnerFactory()
        cls.partner3 = PartnerFactory()

        cls.donor1 = DonorFactory()
        cls.donor2 = DonorFactory()
        cls.donor3 = DonorFactory()

        cls.category1 = ItemCategoryFactory()
        cls.category2 = ItemCategoryFactory()
        cls.category3 = ItemCategoryFactory()

        cls.shipment1 = ShipmentFactory(partner=cls.partner1,
                                        shipment_date=cls.day_before,
                                        status=Shipment.STATUS_IN_TRANSIT)

        cls.package1 = PackageFactory(shipment=cls.shipment1,
                                      status=Shipment.STATUS_IN_TRANSIT)
        cls.item1 = PackageItemFactory(package=cls.package1,
                                       donor=cls.donor1,
                                       item_category=cls.category1)

        cls.shipment2 = ShipmentFactory(partner=cls.partner2,
                                        shipment_date=cls.important_date,
                                        status=Shipment.STATUS_RECEIVED)
        cls.package2 = PackageFactory(shipment=cls.shipment2,
                                      status=Shipment.STATUS_RECEIVED)
        cls.item2 = PackageItemFactory(package=cls.package2,
                                       donor=cls.donor2,
                                       item_category=cls.category2)

        cls.shipment3 = ShipmentFactory(partner=cls.partner3,
                                        shipment_date=cls.day_after,
                                        status=Shipment.STATUS_CANCELED)
        cls.package3 = PackageFactory(shipment=cls.shipment3,
                                      status=Shipment.STATUS_CANCELED)
        cls.item3 = PackageItemFactory(package=cls.package3,
                                       donor=cls.donor3,
                                       item_category=cls.category3)
コード例 #8
0
ファイル: test_db_views.py プロジェクト: trendspotter/CTS
 def test_shipment_db_view_two_packages_with_items(self):
     # 2 packages, with items, one of them received
     self.shipment.date_received = now()
     self.shipment.status = Shipment.STATUS_RECEIVED
     self.shipment.save()
     package1 = PackageFactory(shipment=self.shipment)
     package2 = PackageFactory(shipment=self.shipment, status=Shipment.STATUS_RECEIVED)
     PackageItemFactory(package=package1, quantity=1,
                        price_usd=Decimal('1.00'), price_local=Decimal('0.001'))
     PackageItemFactory(package=package2, quantity=2,
                        price_usd=Decimal('2.00'), price_local=Decimal('0.002'))
     PackageItemFactory(package=package2, quantity=3,
                        price_usd=Decimal('3.00'), price_local=Decimal('0.003'))
     shipment = ShipmentDBView.objects.get(pk=self.shipment.pk)
     self.assertEqual(2, shipment.packages.count())
     self.assertEqual(2, shipment.num_packages)
     self.assertEqual(6, shipment.num_items)
     self.assertEqual(5, shipment.num_received_items)
     self.assertEqual(Decimal('14.0'), shipment.price_usd)
     self.assertEqual(Decimal('0.014'), shipment.price_local)
コード例 #9
0
ファイル: test_views.py プロジェクト: erafighi/CTS
 def test_it(self):
     self.packages = [
         PackageFactory(shipment=self.shipment) for i in range(5)
     ]
     for pkg in self.packages:
         for i in range(5):
             PackageItemFactory(package=pkg)
     url = reverse('summary_manifests', kwargs={'pk': self.shipment.pk})
     rsp = self.client.get(url)
     self.assertEqual(200, rsp.status_code)
     # Summary manifest doesn't change shipment status
     shipment = Shipment.objects.get(pk=self.shipment.pk)
     self.assertEqual(Shipment.STATUS_IN_PROGRESS, shipment.status)
コード例 #10
0
ファイル: test_views.py プロジェクト: erafighi/CTS
    def test_get(self):
        # Pass package item pks in a header
        # get back a modal with a form
        pkg = PackageFactory(shipment=self.shipment)
        pkg_items = [PackageItemFactory(package=pkg) for i in range(10)]
        items_to_edit = pkg_items[:5]
        pks_to_edit = [item.pk for item in items_to_edit]

        rsp = self.client.get(self.url,
                              HTTP_SELECTED_ITEMS=','.join(
                                  [str(pk) for pk in pks_to_edit]))
        self.assertEqual(200, rsp.status_code)
        form = rsp.context['form']
        self.assertIn('supplier', form.fields)
        self.assertNotIn('weight', form.fields)
コード例 #11
0
ファイル: test_views.py プロジェクト: erafighi/CTS
 def test_it(self):
     self.packages = [
         PackageFactory(shipment=self.shipment) for i in range(5)
     ]
     for pkg in self.packages:
         for i in range(5):
             PackageItemFactory(package=pkg)
     url = reverse('full_manifests',
                   kwargs={
                       'pk': self.shipment.pk,
                       'size': 6
                   })
     rsp = self.client.get(url)
     self.assertEqual(200, rsp.status_code)
     # Printing barcodes updates status from inprogress to ready for pickup
     shipment = Shipment.objects.get(pk=self.shipment.pk)
     self.assertEqual(Shipment.STATUS_READY, shipment.status)
     for pkg in self.packages:
         pkg = Package.objects.get(pk=pkg.pk)
         self.assertEqual(Shipment.STATUS_READY, pkg.status)
コード例 #12
0
ファイル: test_views.py プロジェクト: erafighi/CTS
    def test_post_extra_comma(self):
        # sometimes we get an extra comma in the list of pks
        pkg = PackageFactory(shipment=self.shipment)
        pkg_items = [PackageItemFactory(package=pkg) for i in range(3)]
        items_to_edit = pkg_items[:2]
        pks_to_edit = [item.pk for item in items_to_edit]

        data = {
            'donor': '',
            'donor_t1': '',
            'supplier': '',
            'item_category': '',
            'selected_items': ','.join([str(pk) for pk in pks_to_edit]),
        }
        # Append the extra comma that was breaking us
        data['selected_items'] += ','
        rsp = self.client.post(
            self.url,
            data=data,
        )
        self.assertEqual(200, rsp.status_code)
コード例 #13
0
ファイル: test_views.py プロジェクト: erafighi/CTS
    def test_post(self):
        # Pass changes and package item pks in a form
        # Selected package items ought to be updated
        donor1 = DonorFactory()
        donor2 = DonorFactory()
        supplier1 = SupplierFactory()
        supplier2 = SupplierFactory()
        pkg = PackageFactory(shipment=self.shipment)
        pkg_items = [
            PackageItemFactory(package=pkg, supplier=supplier1, donor=donor1)
            for i in range(10)
        ]
        items_to_edit = pkg_items[:5]
        pks_to_edit = [item.pk for item in items_to_edit]

        data = {
            'donor': donor2.pk,
            'donor_t1': '',
            'supplier': supplier2.pk,
            'item_category': '',
            'selected_items': ','.join([str(pk) for pk in pks_to_edit]),
        }
        rsp = self.client.post(
            self.url,
            data=data,
        )
        self.assertEqual(200, rsp.status_code)
        # refresh package item objects from database
        pkg_items = [PackageItem.objects.get(pk=item.pk) for item in pkg_items]
        # check that the right changes were made
        for item in pkg_items:
            if item.pk in pks_to_edit:
                self.assertEqual(item.supplier, supplier2)
                self.assertEqual(item.donor, donor2)
            else:
                self.assertEqual(item.supplier, supplier1)
                self.assertEqual(item.donor, donor1)
コード例 #14
0
ファイル: test_views.py プロジェクト: erafighi/CTS
 def setUp(self):
     super(ShipmentDeleteViewTest, self).setUp()
     self.shipment = ShipmentFactory()
     self.package = PackageFactory(shipment=self.shipment)
     self.item = PackageItemFactory(package=self.package)
     self.url = reverse('delete_shipment', kwargs={'pk': self.shipment.pk})
コード例 #15
0
ファイル: test_views.py プロジェクト: erafighi/CTS
 def setUp(self):
     super(PackageItemEditModalViewTest, self).setUp()
     self.package = PackageFactory(shipment=self.shipment)
     self.item = PackageItemFactory(package=self.package)
     self.url = reverse('package_item_edit', args=[self.item.pk])
コード例 #16
0
ファイル: test_db_views.py プロジェクト: trendspotter/CTS
 def test_prices(self):
     item = PackageItemFactory(quantity=2, price_usd=Decimal("3.0"), price_local=Decimal("4.0"))
     item = PackageItemDBView.objects.get(pk=item.pk)
     self.assertEqual(Decimal("6.0"), item.extended_price_usd)
     self.assertEqual(Decimal("8.0"), item.extended_price_local)
コード例 #17
0
 def item_for_partner(self, user):
     item = PackageItemFactory()
     item.package.shipment.partner = user
     item.package.shipment.save()
     return item