コード例 #1
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)
コード例 #2
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)
コード例 #3
0
ファイル: test_dsa_rates.py プロジェクト: unicef/etools
    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)
コード例 #4
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'))
コード例 #5
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()
コード例 #6
0
    def test_effective_from_date(self):
        region = PublicsDSARegionFactory(rates=[])

        now_date = now().date()
        rate_1 = PublicsDSARateFactory(region=region, effective_from_date=None)

        self.assertEqual(rate_1.effective_from_date, now_date)

        effective_from_date = date(2017, 4, 1)
        rate_2 = PublicsDSARateFactory(region=region,
                                       effective_from_date=effective_from_date)

        self.assertEqual(rate_2.effective_from_date, effective_from_date)
コード例 #7
0
ファイル: test_dsa_rates.py プロジェクト: unicef/etools
    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)
コード例 #8
0
    def test_new_rate_addition(self):
        region = PublicsDSARegionFactory(rates=[])

        rate_1 = PublicsDSARateFactory(region=region,
                                       effective_from_date=date(2017, 4, 17))
        self.assertEqual(rate_1.effective_to_date,
                         DSARate.DEFAULT_EFFECTIVE_TILL)

        rate_2 = PublicsDSARateFactory(region=region,
                                       effective_from_date=date(2017, 4, 18))
        rate_1.refresh_from_db()

        self.assertNotEqual(rate_1.effective_to_date,
                            DSARate.DEFAULT_EFFECTIVE_TILL)
        self.assertNotEqual(rate_1.effective_to_date,
                            DSARate.DEFAULT_EFFECTIVE_TILL)
        self.assertLess(rate_1.effective_to_date, rate_2.effective_from_date)
コード例 #9
0
ファイル: test_dsa_rates.py プロジェクト: unicef/etools
    def test_new_rate_addition(self):
        region = PublicsDSARegionFactory(rates=[])

        rate_1 = PublicsDSARateFactory(
            region=region,
            effective_from_date=date(2017, 4, 17)
        )
        self.assertEqual(rate_1.effective_to_date, DSARate.DEFAULT_EFFECTIVE_TILL)

        rate_2 = PublicsDSARateFactory(
            region=region,
            effective_from_date=date(2017, 4, 18)
        )
        rate_1.refresh_from_db()

        self.assertNotEqual(rate_1.effective_to_date, DSARate.DEFAULT_EFFECTIVE_TILL)
        self.assertNotEqual(rate_1.effective_to_date, DSARate.DEFAULT_EFFECTIVE_TILL)
        self.assertLess(rate_1.effective_to_date, rate_2.effective_from_date)
コード例 #10
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)
コード例 #11
0
    def prepare_travel(self):
        # Currencies
        huf = PublicsCurrencyFactory(name='HUF', code='huf')

        # Add wbs/grant/fund
        wbs_1 = PublicsWBSFactory(name='WBS #1')
        grant_1 = PublicsGrantFactory(name='Grant #1')
        wbs_1.grants.add(grant_1)
        fund_1 = PublicsFundFactory(name='Fund #1')
        grant_1.funds.add(fund_1)

        dsa_region = PublicsDSARegionFactory()
        PublicsDSARateFactory(region=dsa_region)

        # Expense types
        et_t_food = PublicsTravelExpenseTypeFactory(
            title='Food',
            vendor_number=TravelExpenseType.USER_VENDOR_NUMBER_PLACEHOLDER
        )

        # Make a travel
        travel = Travel.objects.create(traveler=self.traveler,
                                       supervisor=self.unicef_staff,
                                       currency=huf)

        # Add expenses
        Expense.objects.create(travel=travel,
                               type=et_t_food,
                               currency=huf,
                               amount=35)

        ItineraryItemFactory(travel=travel,
                             departure_date=datetime(2017, 5, 10, tzinfo=UTC),
                             arrival_date=datetime(2017, 5, 11, tzinfo=UTC),
                             dsa_region=dsa_region)
        ItineraryItemFactory(travel=travel,
                             departure_date=datetime(2017, 5, 20, tzinfo=UTC),
                             arrival_date=datetime(2017, 5, 21, tzinfo=UTC),
                             dsa_region=dsa_region)

        # Add cost assignments
        CostAssignment.objects.create(travel=travel,
                                      share=100,
                                      wbs=wbs_1,
                                      grant=grant_1,
                                      fund=fund_1)

        return travel
コード例 #12
0
    def test_almost_overlapping_trips(self):
        currency = PublicsCurrencyFactory()
        expense_type = PublicsTravelExpenseTypeFactory()
        dsa_rate = PublicsDSARateFactory(effective_from_date=datetime(2017, 4, 10, 16, 00, tzinfo=UTC))
        dsa_region = dsa_rate.region

        data = {'deductions': [],
                'itinerary': [{'origin': 'Berlin',
                               'destination': 'Budapest',
                               'departure_date': '2017-04-14T17:06:55.821490',
                               'arrival_date': '2017-04-15T17:06:55.821490',
                               'dsa_region': dsa_region.id,
                               'overnight_travel': False,
                               'mode_of_travel': ModeOfTravel.RAIL,
                               'airlines': []},
                              {'origin': 'Budapest',
                               'destination': 'Berlin',
                               'departure_date': '2017-05-20T12:06:55.821490',
                               'arrival_date': '2017-05-21T12:06:55.821490',
                               'dsa_region': dsa_region.id,
                               'overnight_travel': False,
                               'mode_of_travel': ModeOfTravel.RAIL,
                               'airlines': []}],
                'activities': [],
                'cost_assignments': [],
                'clearances': {'medical_clearance': 'requested',
                               'security_clearance': 'requested',
                               'security_course': 'requested'},
                'ta_required': True,
                'international_travel': False,
                'mode_of_travel': [ModeOfTravel.BOAT],
                'traveler': self.traveler.id,
                'supervisor': self.unicef_staff.id,
                'start_date': '2017-04-14T16:05:00+00:00',
                'end_date': '2017-05-22T15:02:13+00:00',
                'currency': currency.id,
                'purpose': 'Purpose',
                'additional_note': 'Notes',
                'expenses': [{'amount': '120',
                              'type': expense_type.id,
                              'currency': currency.id,
                              'document_currency': currency.id}]}

        response = self.forced_auth_req('post', reverse('t2f:travels:list:index'),
                                        data=data, user=self.traveler)
        response_json = json.loads(response.rendered_content)

        with freeze_time(datetime(2017, 4, 14, 16, 00, tzinfo=UTC)):
            response = self.forced_auth_req('post', reverse('t2f:travels:details:state_change',
                                                            kwargs={'travel_pk': response_json['id'],
                                                                    'transition_name': 'submit_for_approval'}),
                                            data=response_json, user=self.traveler)
        # No error should appear, expected 200
        response_json = json.loads(response.rendered_content)
        self.assertEqual(response.status_code, 200, response_json)
        response_json = json.loads(response.rendered_content)

        travel = Travel.objects.get(id=response_json['id'])
        travel.approve()
        travel.save()

        response = self.forced_auth_req('post', reverse('t2f:travels:details:state_change',
                                                        kwargs={'travel_pk': response_json['id'],
                                                                'transition_name': 'send_for_payment'}),
                                        data=response_json, user=self.traveler)
        self.assertEqual(response.status_code, 200)
コード例 #13
0
    def setUp(self):
        super(InvoiceMaking, self).setUp()
        self.unicef_staff = UserFactory(is_staff=True)
        self.traveler = UserFactory()

        profile = self.traveler.profile
        profile.vendor_number = 'user0001'
        profile.save()

        country = profile.country
        country.business_area_code = '0060'
        country.save()

        dsa_region = PublicsDSARegionFactory()
        PublicsDSARateFactory(region=dsa_region)

        # Currencies
        self.huf = PublicsCurrencyFactory(name='HUF', code='huf')
        self.usd = PublicsCurrencyFactory(name='USD', code='usd')

        # Add wbs/grant/fund
        self.wbs_1 = PublicsWBSFactory(name='WBS #1')
        self.wbs_2 = PublicsWBSFactory(name='WBS #2')

        self.grant_1 = PublicsGrantFactory(name='Grant #1')
        self.grant_2 = PublicsGrantFactory(name='Grant #2')
        self.grant_3 = PublicsGrantFactory(name='Grant #3')

        self.wbs_1.grants.add(self.grant_1)
        self.wbs_2.grants.add(self.grant_2, self.grant_3)

        self.fund_1 = PublicsFundFactory(name='Fund #1')
        self.fund_2 = PublicsFundFactory(name='Fund #4')

        self.grant_1.funds.add(self.fund_1)
        self.grant_3.funds.add(self.fund_2)

        # Expense types
        self.et_t_food = PublicsTravelExpenseTypeFactory(
            title='Food',
            vendor_number=TravelExpenseType.USER_VENDOR_NUMBER_PLACEHOLDER)
        self.et_t_travel = PublicsTravelExpenseTypeFactory(
            title='Travel',
            vendor_number=TravelExpenseType.USER_VENDOR_NUMBER_PLACEHOLDER)
        self.et_t_other = PublicsTravelExpenseTypeFactory(
            title='Other',
            vendor_number=TravelExpenseType.USER_VENDOR_NUMBER_PLACEHOLDER)

        self.et_a_nico = PublicsTravelExpenseTypeFactory(
            title='Nico Travel', vendor_number='a_nico')
        self.et_a_torben = PublicsTravelExpenseTypeFactory(
            title='Torben Travel', vendor_number='a_torben')

        # Make a travel
        self.travel = Travel.objects.create(traveler=self.traveler,
                                            supervisor=self.unicef_staff,
                                            currency=self.huf)

        ItineraryItemFactory(travel=self.travel,
                             departure_date=datetime(2017, 5, 10, tzinfo=UTC),
                             arrival_date=datetime(2017, 5, 11, tzinfo=UTC),
                             dsa_region=dsa_region)
        ItineraryItemFactory(travel=self.travel,
                             departure_date=datetime(2017, 5, 20, tzinfo=UTC),
                             arrival_date=datetime(2017, 5, 21, tzinfo=UTC),
                             dsa_region=dsa_region)
コード例 #14
0
    def test_almost_overlapping_trips(self):
        currency = PublicsCurrencyFactory()
        dsa_rate = PublicsDSARateFactory(effective_from_date=datetime.datetime(
            2017, 4, 10, 16, 00, tzinfo=UTC))
        dsa_region = dsa_rate.region

        data = {
            'itinerary': [{
                'origin': 'Berlin',
                'destination': 'Budapest',
                'departure_date': '2017-04-14T17:06:55.821490',
                'arrival_date': '2017-04-15T17:06:55.821490',
                'dsa_region': dsa_region.id,
                'overnight_travel': False,
                'mode_of_travel': ModeOfTravel.RAIL,
                'airlines': []
            }, {
                'origin': 'Budapest',
                'destination': 'Berlin',
                'departure_date': '2017-05-20T12:06:55.821490',
                'arrival_date': '2017-05-21T12:06:55.821490',
                'dsa_region': dsa_region.id,
                'overnight_travel': False,
                'mode_of_travel': ModeOfTravel.RAIL,
                'airlines': []
            }],
            'activities': [],
            'ta_required':
            True,
            'international_travel':
            False,
            'mode_of_travel': [ModeOfTravel.BOAT],
            'traveler':
            self.traveler.id,
            'supervisor':
            self.unicef_staff.id,
            'start_date':
            '2017-04-14T16:05:00+00:00',
            'end_date':
            '2017-05-22T15:02:13+00:00',
            'currency':
            currency.id,
            'purpose':
            'Purpose',
            'additional_note':
            'Notes'
        }

        response = self.forced_auth_req('post',
                                        reverse('t2f:travels:list:index'),
                                        data=data,
                                        user=self.traveler)
        response_json = json.loads(response.rendered_content)

        with freeze_time(datetime.datetime(2017, 4, 14, 16, 00, tzinfo=UTC)):
            response = self.forced_auth_req(
                'post',
                reverse('t2f:travels:details:state_change',
                        kwargs={
                            'travel_pk': response_json['id'],
                            'transition_name': Travel.SUBMIT_FOR_APPROVAL
                        }),
                data=response_json,
                user=self.traveler)
        # No error should appear, expected 200
        response_json = json.loads(response.rendered_content)
        self.assertEqual(response.status_code, 200, response_json)
コード例 #15
0
    def test_travel_admin_export(self):
        dsa_brd = PublicsDSARegionFactory(area_code='BRD')
        PublicsDSARateFactory(region=dsa_brd)
        dsa_lan = PublicsDSARegionFactory(area_code='LAN')
        PublicsDSARateFactory(region=dsa_lan)

        airline_jetstar = PublicsAirlineCompanyFactory(name='JetStar')
        airline_spiceair = PublicsAirlineCompanyFactory(name='SpiceAir')

        # First travel setup
        travel_1 = TravelFactory(traveler=self.traveler, supervisor=self.unicef_staff)
        travel_1.itinerary.all().delete()

        itinerary_item_1 = ItineraryItemFactory(travel=travel_1,
                                                origin='Origin1',
                                                destination='Origin2',
                                                departure_date=datetime(2016, 12, 3, 11, tzinfo=UTC),
                                                arrival_date=datetime(2016, 12, 3, 12, tzinfo=UTC),
                                                mode_of_travel=ModeOfTravel.CAR,
                                                dsa_region=dsa_brd)
        itinerary_item_1.airlines.all().delete()

        itinerary_item_2 = ItineraryItemFactory(travel=travel_1,
                                                origin='Origin2',
                                                destination='Origin3',
                                                departure_date=datetime(2016, 12, 5, 11, tzinfo=UTC),
                                                arrival_date=datetime(2016, 12, 5, 12, tzinfo=UTC),
                                                mode_of_travel=ModeOfTravel.PLANE,
                                                dsa_region=dsa_lan)
        itinerary_item_2.airlines.all().delete()
        itinerary_item_2.airlines.add(airline_jetstar)

        itinerary_item_3 = ItineraryItemFactory(travel=travel_1,
                                                origin='Origin3',
                                                destination='Origin1',
                                                departure_date=datetime(2016, 12, 6, 11, tzinfo=UTC),
                                                arrival_date=datetime(2016, 12, 6, 12, tzinfo=UTC),
                                                mode_of_travel=ModeOfTravel.PLANE,
                                                dsa_region=None)
        itinerary_item_3.airlines.all().delete()
        itinerary_item_3.airlines.add(airline_spiceair)

        # Second travel setup
        another_traveler = UserFactory(first_name='Max', last_name='Mustermann')
        travel_2 = TravelFactory(traveler=another_traveler, supervisor=self.unicef_staff)
        travel_2.itinerary.all().delete()

        itinerary_item_4 = ItineraryItemFactory(travel=travel_2,
                                                origin='Origin2',
                                                destination='Origin1',
                                                departure_date=datetime(2016, 12, 5, 11, tzinfo=UTC),
                                                arrival_date=datetime(2016, 12, 5, 12, tzinfo=UTC),
                                                mode_of_travel=ModeOfTravel.PLANE,
                                                dsa_region=dsa_lan)
        itinerary_item_4.airlines.all().delete()
        itinerary_item_4.airlines.add(airline_jetstar)

        itinerary_item_5 = ItineraryItemFactory(travel=travel_2,
                                                origin='Origin3',
                                                destination='Origin1',
                                                departure_date=datetime(2016, 12, 6, 11, tzinfo=UTC),
                                                arrival_date=datetime(2016, 12, 6, 12, tzinfo=UTC),
                                                mode_of_travel=ModeOfTravel.CAR,
                                                dsa_region=None)
        itinerary_item_5.airlines.all().delete()
        itinerary_item_5.airlines.add(airline_spiceair)

        with self.assertNumQueries(6):
            response = self.forced_auth_req('get', reverse('t2f:travels:list:travel_admin_export'),
                                            user=self.unicef_staff)
        export_csv = csv.reader(StringIO(response.content.decode('utf-8')))
        rows = [r for r in export_csv]

        self.assertEqual(len(rows), 6)

        # check header
        self.assertEqual(rows[0],
                         ['reference_number',
                          'traveler',
                          'office',
                          'section',
                          'status',
                          'origin',
                          'destination',
                          'departure_time',
                          'arrival_time',
                          'dsa_area',
                          'overnight_travel',
                          'mode_of_travel',
                          'airline'])

        self.assertEqual(rows[1],
                         ['{}/1'.format(datetime.now().year),
                          'John Doe',
                          'An Office',
                          travel_1.sector.name,
                          'planned',
                          'Origin1',
                          'Origin2',
                          '03-Dec-2016 11:00 AM',
                          '03-Dec-2016 12:00 PM',
                          'BRD',
                          '',
                          'Car',
                          ''])

        self.assertEqual(rows[2],
                         ['{}/1'.format(datetime.now().year),
                          'John Doe',
                          'An Office',
                          travel_1.sector.name,
                          'planned',
                          'Origin2',
                          'Origin3',
                          '05-Dec-2016 11:00 AM',
                          '05-Dec-2016 12:00 PM',
                          'LAN',
                          '',
                          'Plane',
                          'JetStar'])

        self.assertEqual(rows[3],
                         ['{}/1'.format(datetime.now().year),
                          'John Doe',
                          'An Office',
                          travel_1.sector.name,
                          'planned',
                          'Origin3',
                          'Origin1',
                          '06-Dec-2016 11:00 AM',
                          '06-Dec-2016 12:00 PM',
                          'NODSA',
                          '',
                          'Plane',
                          'SpiceAir'])

        self.assertEqual(rows[4],
                         ['{}/2'.format(datetime.now().year),
                          'Max Mustermann',
                          'An Office',
                          travel_2.sector.name,
                          'planned',
                          'Origin2',
                          'Origin1',
                          '05-Dec-2016 11:00 AM',
                          '05-Dec-2016 12:00 PM',
                          'LAN',
                          '',
                          'Plane',
                          'JetStar'])

        self.assertEqual(rows[5],
                         ['{}/2'.format(datetime.now().year),
                          'Max Mustermann',
                          'An Office',
                          travel_2.sector.name,
                          'planned',
                          'Origin3',
                          'Origin1',
                          '06-Dec-2016 11:00 AM',
                          '06-Dec-2016 12:00 PM',
                          'NODSA',
                          '',
                          'Car',
                          'SpiceAir'])