コード例 #1
0
    def test_country(self):
        instance = PublicsCountryFactory.build(name='xyz')
        self.assertEqual(str(instance), 'xyz')

        # Island (Iceland)
        instance = PublicsCountryFactory.build(name='\xccsland')
        self.assertEqual(str(instance), '\xccsland')
コード例 #2
0
    def test_dsa_region(self):
        country = PublicsCountryFactory.build(name='xyz')
        instance = PublicsDSARegionFactory.build(area_name='xyz', country=country)
        self.assertEqual(str(instance), 'xyz - xyz')

        # Island (Iceland)
        country = PublicsCountryFactory.build(name='\xccsland')
        instance = PublicsDSARegionFactory.build(area_name='xyz', country=country)
        self.assertEqual(str(instance), '\xccsland - xyz')
コード例 #3
0
    def test_dsa_rate(self):
        country = PublicsCountryFactory.build(name='xyz')
        region = PublicsDSARegionFactory.build(area_name='xyz', country=country)
        instance = PublicsDSARateFactory.build(region=region)
        self.assertTrue(str(instance).startswith('xyz - xyz'))

        country = PublicsCountryFactory.build(name='\xccsland')
        region = PublicsDSARegionFactory.build(area_name='xyz', country=country)
        instance = PublicsDSARateFactory.build(region=region)
        self.assertTrue(str(instance).startswith('\xccsland - xyz'))
コード例 #4
0
    def setUpTestData(cls):
        cls.unicef_staff = UserFactory(is_staff=True)

        cls.currency_usd = PublicsCurrencyFactory(code='USD')
        cls.currency_huf = PublicsCurrencyFactory(name='Hungarian Forint',
                                                  code='HUF')

        cls.user_et_1 = PublicsTravelExpenseTypeFactory(
            title='Train cost',
            vendor_number=TravelExpenseType.USER_VENDOR_NUMBER_PLACEHOLDER)
        cls.user_et_2 = PublicsTravelExpenseTypeFactory(
            title='Other expenses',
            vendor_number=TravelExpenseType.USER_VENDOR_NUMBER_PLACEHOLDER)
        cls.ta_et = PublicsTravelExpenseTypeFactory(title='Travel agent')

        netherlands = PublicsCountryFactory(name='Netherlands',
                                            long_name='Netherlands')
        hungary = PublicsCountryFactory(name='Hungary', long_name='Hungary')
        denmark = PublicsCountryFactory(name='Denmark', long_name='Denmark')
        germany = PublicsCountryFactory(name='Germany', long_name='Germany')

        cls.amsterdam = PublicsDSARegionFactory(country=netherlands,
                                                area_name='Amsterdam',
                                                area_code='ds1')
        PublicsDSARateFactory(region=cls.amsterdam,
                              dsa_amount_usd=100,
                              dsa_amount_60plus_usd=60)

        cls.budapest = PublicsDSARegionFactory(country=hungary,
                                               area_name='Budapest',
                                               area_code='ds2')
        PublicsDSARateFactory(region=cls.budapest,
                              dsa_amount_usd=200,
                              dsa_amount_60plus_usd=120)

        cls.copenhagen = PublicsDSARegionFactory(country=denmark,
                                                 area_name='Copenhagen',
                                                 area_code='ds3')
        PublicsDSARateFactory(region=cls.copenhagen,
                              dsa_amount_usd=300,
                              dsa_amount_60plus_usd=180)

        cls.dusseldorf = PublicsDSARegionFactory(country=germany,
                                                 area_name='Duesseldorf',
                                                 area_code='ds4')
        PublicsDSARateFactory(region=cls.dusseldorf,
                              dsa_amount_usd=400,
                              dsa_amount_60plus_usd=240)

        # Delete default items created by factory
        cls.travel = TravelFactory(currency=cls.currency_huf)
        cls.travel.itinerary.all().delete()
        cls.travel.expenses.all().delete()
        cls.travel.deductions.all().delete()
コード例 #5
0
    def test_dsa_regions_view(self):
        workspace = self.unicef_staff.profile.country
        workspace.business_area_code = '1234'
        workspace.save()

        business_area = PublicsBusinessAreaFactory(
            code=workspace.business_area_code)
        country = PublicsCountryFactory(business_area=business_area)

        region_1 = PublicsDSARegionFactory(country=country)
        region_2 = PublicsDSARegionFactory(country=country)
        region_3 = PublicsDSARegionFactory(country=country)

        PublicsDSARateFactory(region=region_1)
        PublicsDSARateFactory(region=region_2)
        PublicsDSARateFactory(region=region_3)

        with self.assertNumQueries(4):
            response = self.forced_auth_req('get',
                                            reverse('publics:dsa_regions'),
                                            user=self.unicef_staff)

        response_json = json.loads(response.rendered_content)

        self.assertEqual(len(response_json), 3)

        expected_keys = [
            'unique_name', 'dsa_amount_usd', 'country', 'area_name',
            'area_code', 'label', 'dsa_amount_60plus_usd', 'long_name',
            'effective_from_date', 'dsa_amount_60plus_local', 'id',
            'unique_id', 'dsa_amount_local'
        ]
        self.assertKeysIn(expected_keys, response_json[0], exact=True)
コード例 #6
0
    def test_dsa_regions_view(self):
        workspace = self.unicef_staff.profile.country
        workspace.business_area_code = '1234'
        workspace.save()

        business_area = PublicsBusinessAreaFactory(
            code=workspace.business_area_code)
        country = PublicsCountryFactory(business_area=business_area)

        region = PublicsDSARegionFactory(country=country, rates=[])

        with self.assertNumQueries(1):
            response = self.forced_auth_req('get',
                                            reverse('publics:dsa_regions'),
                                            user=self.unicef_staff)
        response_json = json.loads(response.rendered_content)
        self.assertEqual(len(response_json), 0)

        rate = PublicsDSARateFactory(region=region)

        response = self.forced_auth_req('get',
                                        reverse('publics:dsa_regions'),
                                        user=self.unicef_staff)
        response_json = json.loads(response.rendered_content)
        self.assertEqual(len(response_json), 1)
        self.assertEqual(response_json[0]['id'], region.id)

        # Expire rate - region should be excluded
        rate.delete()

        response = self.forced_auth_req('get',
                                        reverse('publics:dsa_regions'),
                                        user=self.unicef_staff)
        response_json = json.loads(response.rendered_content)
        self.assertEqual(len(response_json), 0)
コード例 #7
0
    def test_endpoint(self):
        # This line is duplicated on purpose. Currency will have always 1+N number of queries
        # because of the exchange rate
        factory.build_batch(PublicsCurrencyFactory, 4)

        # Create one of each model to check if all serializers are working fine
        PublicsAirlineCompanyFactory()
        country = PublicsCountryFactory(currency=None)
        PublicsDSARegionFactory(country=country)
        PublicsBusinessAreaFactory()
        PublicsWBSFactory(business_area=None)
        PublicsGrantFactory()
        PublicsFundFactory()
        PublicsTravelExpenseTypeFactory()

        with self.assertNumQueries(11):
            response = self.forced_auth_req('get',
                                            reverse('publics:static'),
                                            user=self.unicef_staff)

        response_json = json.loads(response.rendered_content)
        self.assertKeysIn([
            'currencies', 'travel_types', 'countries', 'airlines',
            'travel_modes', 'expense_types', 'business_areas'
        ],
                          response_json,
                          exact=True)
コード例 #8
0
    def test_values_history_retrieval(self):
        workspace = self.unicef_staff.profile.country
        workspace.business_area_code = '1234'
        workspace.save()

        business_area = PublicsBusinessAreaFactory(
            code=workspace.business_area_code)
        country = PublicsCountryFactory(business_area=business_area)

        region = PublicsDSARegionFactory(country=country, rates=[])

        with freeze_time('2017-04-01'):
            rate_1 = PublicsDSARateFactory(region=region,
                                           effective_from_date=date(
                                               2017, 4, 1),
                                           dsa_amount_usd=50)
        with freeze_time('2017-04-10'):
            rate_2 = PublicsDSARateFactory(region=region,
                                           effective_from_date=date(
                                               2017, 4, 10),
                                           dsa_amount_usd=80)

        date_str = date(2017, 4, 12).isoformat()
        response = self.forced_auth_req('get',
                                        reverse('publics:dsa_regions'),
                                        data={'values_at': date_str},
                                        user=self.unicef_staff)
        response_json = json.loads(response.rendered_content)
        self.assertEqual(Decimal(response_json[0]['dsa_amount_usd']),
                         rate_2.dsa_amount_usd)

        date_str = date(2017, 4, 6).isoformat()
        response = self.forced_auth_req('get',
                                        reverse('publics:dsa_regions'),
                                        data={'values_at': date_str},
                                        user=self.unicef_staff)
        response_json = json.loads(response.rendered_content)
        self.assertEqual(Decimal(response_json[0]['dsa_amount_usd']),
                         rate_1.dsa_amount_usd)

        date_str = date(2017, 3, 31).isoformat()
        response = self.forced_auth_req('get',
                                        reverse('publics:dsa_regions'),
                                        data={'values_at': date_str},
                                        user=self.unicef_staff)
        response_json = json.loads(response.rendered_content)
        self.assertEqual(len(response_json), 0)

        rate_2.effective_to_date = date(2017, 4, 15)
        rate_2.save()

        date_str = datetime(2017, 4, 16, tzinfo=UTC).isoformat()
        response = self.forced_auth_req('get',
                                        reverse('publics:dsa_regions'),
                                        data={'values_at': date_str},
                                        user=self.unicef_staff)
        response_json = json.loads(response.rendered_content)
        self.assertEqual(len(response_json), 0)
コード例 #9
0
 def test_save_records_update(self):
     """Travel record exists, check that travel country updated"""
     country_new = PublicsCountryFactory(
         vision_code=self.data["VENDOR_CTRY_CODE"]
     )
     country_old = PublicsCountryFactory(vision_code="321")
     travel = TravelAgentFactory(
         code=self.data["VENDOR_CODE"],
         country=country_old
     )
     travel_expense_qs = TravelExpenseType.objects.filter(
         vendor_number=self.data["VENDOR_CODE"]
     )
     self.assertFalse(travel_expense_qs.exists())
     self.adapter._save_records({"ROWSET": {"ROW": [self.data]}})
     self.assertTrue(travel_expense_qs.exists())
     travel_updated = TravelAgent.objects.get(pk=travel.pk)
     self.assertEqual(travel_updated.country, country_new)
コード例 #10
0
 def test_save_records(self):
     """Ensure records are created'"""
     PublicsCountryFactory(vision_code=self.data["VENDOR_CTRY_CODE"])
     travel_qs = TravelAgent.objects.filter(code=self.data["VENDOR_CODE"])
     travel_expense_qs = TravelExpenseType.objects.filter(
         vendor_number=self.data["VENDOR_CODE"]
     )
     self.assertFalse(travel_qs.exists())
     self.assertFalse(travel_expense_qs.exists())
     self.adapter._save_records({"ROWSET": {"ROW": [self.data]}})
     self.assertTrue(travel_qs.exists())
     self.assertTrue(travel_expense_qs.exists())