コード例 #1
0
 def test_donor_filtering(self):
     donor1 = DonorFactory()
     donor2 = DonorFactory()
     item1 = self.item_for_donor(donor1)
     item2 = self.item_for_donor(donor2)
     queryset = self.filter_class._meta.model.objects.all()
     filter = self.filter_class(data={'donor': donor1.pk}, queryset=queryset, user=self.partner)
     pks = filter.qs.values_list('pk', flat=True)
     self.assertIn(item1.pk, pks)
     self.assertNotIn(item2.pk, pks)
コード例 #2
0
 def test_update_and_create_new_codes(self):
     # Update a donor, create some new codes, and add them to the donor
     donor = DonorFactory()
     url = reverse('edit_donor_modal', args=[donor.pk])
     rsp = self.client.get(url)
     self.assertEqual(200, rsp.status_code)
     t1_codeA = DonorCode.objects.create(code='t1A',
                                         donor_code_type=DonorCode.T1)
     t1_codeB = DonorCode.objects.create(code='t1B',
                                         donor_code_type=DonorCode.T1)
     t3_codeA = DonorCode.objects.create(code='t1A',
                                         donor_code_type=DonorCode.T3)
     # Submit the new object
     name = "edited"
     data = {
         'name': name,
         't1_codes_1': [t1_codeA.pk, t1_codeB.pk],
         'new_t1_codes': 'New code C, t1A',
         't3_codes_1': [t3_codeA.pk],
     }
     rsp = self.client.post(url, data=data)
     if rsp.status_code == 400:
         self.fail(rsp.context['form'].errors)
     self.assertEqual(rsp.status_code, 200)
     donor2 = Donor.objects.get(name=name)
     self.assertEqual(donor.pk, donor2.pk)
     code_c = DonorCode.objects.get(code='New code C',
                                    donor_code_type=DonorCode.T1)
     self.assertIn(code_c, donor2.t1_codes.all())
     self.assertIn(t1_codeA, donor2.t1_codes.all())
     self.assertIn(t3_codeA, donor2.t3_codes.all())
コード例 #3
0
 def test_list(self):
     donor = DonorFactory()
     rsp = self.client.get(reverse('donor_list'))
     self.assertEqual(200, rsp.status_code)
     self.assertContains(rsp,
                         donor.name,
                         msg_prefix=rsp.content.decode('utf-8'))
コード例 #4
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)
コード例 #5
0
 def test_delete(self):
     # Delete a donor
     donor = DonorFactory()
     url = reverse('donor_delete', args=[donor.pk])
     rsp = self.client.get(url)
     self.assertEqual(200, rsp.status_code)
     self.assertContains(rsp, 'Confirm')
     Donor.objects.get(pk=donor.pk)
     # Now delete it!
     rsp = self.client.post(url)
     if rsp.status_code == 400:
         self.fail(rsp.context['form'].errors)
     self.assertRedirects(rsp, reverse('donor_list'))
     self.assertFalse(Donor.objects.filter(pk=donor.pk).exists())
コード例 #6
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)
コード例 #7
0
 def test_update(self):
     # Update a donor
     donor = DonorFactory()
     url = reverse('edit_donor_modal', args=[donor.pk])
     rsp = self.client.get(url)
     self.assertEqual(200, rsp.status_code)
     # Submit the new object
     name = "edited"
     data = {
         'name': name,
     }
     rsp = self.client.post(url, data=data)
     if rsp.status_code == 400:
         self.fail(rsp.context['form'].errors)
     self.assertEqual(rsp.status_code, 200)
     donor2 = Donor.objects.get(name=name)
     self.assertEqual(donor.pk, donor2.pk)
コード例 #8
0
ファイル: test_utils.py プロジェクト: trendspotter/CTS
 def setUp(self):
     self.cat = ItemCategoryFactory(name='test category')
     self.cat_name = self.cat.name
     self.donor_t1 = DonorCodeT1Factory(code='Donor t1 code')
     self.donor = DonorFactory(name='Donor 1', t1_codes=[self.donor_t1])
     supplier = SupplierFactory(name='Supplier 27')
     self.valid_row = {
         'item_code': '0001',
         'item_category': self.cat_name,
         'description': 'thing',
         'donor': self.donor.name,
         'donor_t1': self.donor_t1.code,
         'supplier': supplier.name,
         'weight': '3.14',
         'unit': 'pair of pants',
         'price_local': '2.34',
         'price_usd': '1.23',
     }
コード例 #9
0
 def test_edit_modal(self):
     donor = DonorFactory()
     url = reverse('edit_donor_modal', kwargs={'pk': donor.pk})
     rsp = self.client.get(url)
     self.assertEqual(200, rsp.status_code)
     self.assertTemplateUsed(rsp, 'catalog/donor_edit_modal.html')