コード例 #1
0
ファイル: test_ghost_data.py プロジェクト: alhadheri/etools
    def test_multiendpoint(self):
        airline = PublicsAirlineCompanyFactory()

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

        airline.delete()

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

        response = self.forced_auth_req('get',
                                        reverse('publics:missing_static'),
                                        data={'values': [airline.pk]},
                                        user=self.unicef_staff)
        self.assertEqual(response.status_code, 400)
        response_json = json.loads(response.rendered_content)
        self.assertEqual(response_json,
                         {'category': ['This field is required.']})

        response = self.forced_auth_req('get',
                                        reverse('publics:missing_static'),
                                        data={
                                            'values': [airline.pk],
                                            'category': 'airlines'
                                        },
                                        user=self.unicef_staff)
        self.assertEqual(response.status_code, 200)
コード例 #2
0
    def test_airline(self):
        instance = PublicsAirlineCompanyFactory.build(name='xyz')
        self.assertEqual(str(instance), 'xyz')

        # Myflug (Iceland)
        instance = PublicsAirlineCompanyFactory.build(name='M\xfdflug')
        self.assertEqual(str(instance), 'M\xfdflug')
コード例 #3
0
    def test_save_with_ghost_data(self):
        dsa_region = DSARegion.objects.first()
        airline = PublicsAirlineCompanyFactory()

        data = {'itinerary': [{'origin': 'Budapest',
                               'destination': 'Berlin',
                               'departure_date': '2016-11-16T12:06:55.821490',
                               'arrival_date': '2016-11-17T12:06:55.821490',
                               'dsa_region': dsa_region.id,
                               'overnight_travel': False,
                               'mode_of_travel': ModeOfTravel.PLANE,
                               'airlines': [airline.id]}],
                'traveler': self.traveler.id,
                'ta_required': True,
                'supervisor': self.unicef_staff.id}
        response = self.forced_auth_req('post', reverse('t2f:travels:list:index'), data=data, user=self.unicef_staff)
        response_json = json.loads(response.rendered_content)
        travel_id = response_json['id']

        airline.delete()

        response = self.forced_auth_req('put', reverse('t2f:travels:details:index',
                                                       kwargs={'travel_pk': travel_id}),
                                        data=response_json,
                                        user=self.unicef_staff)
        self.assertEqual(response.status_code, 200)
コード例 #4
0
    def test_airlines(self):
        dsaregion = DSARegion.objects.first()
        airlines_1 = PublicsAirlineCompanyFactory()
        airlines_2 = PublicsAirlineCompanyFactory()
        airlines_3 = PublicsAirlineCompanyFactory()

        data = {'itinerary': [{'origin': 'Budapest',
                               'destination': 'Berlin',
                               'departure_date': '2016-11-16T12:06:55.821490',
                               'arrival_date': '2016-11-17T12:06:55.821490',
                               'dsa_region': dsaregion.id,
                               'overnight_travel': False,
                               'mode_of_travel': ModeOfTravel.PLANE,
                               'airlines': [airlines_1.id, airlines_2.id]}],
                'traveler': self.traveler.id,
                'ta_required': True,
                'supervisor': self.unicef_staff.id}
        response = self.forced_auth_req('post', reverse('t2f:travels:list:index'), data=data, user=self.traveler)
        response_json = json.loads(response.rendered_content)

        travel_id = response_json['id']

        data = response_json
        data['itinerary'][0]['airlines'] = [airlines_1.id, airlines_3.id]
        response = self.forced_auth_req('patch', reverse('t2f:travels:details:index',
                                                         kwargs={'travel_pk': travel_id}),
                                        data=data, user=self.traveler)
        response_json = json.loads(response.rendered_content)
        self.assertEqual(sorted(response_json['itinerary'][0]['airlines']), sorted([airlines_1.id, airlines_3.id]))
コード例 #5
0
ファイル: test_ghost_data.py プロジェクト: unicef/etools
    def test_multiendpoint(self):
        airline = PublicsAirlineCompanyFactory()

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

        airline.delete()

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

        response = self.forced_auth_req('get', reverse('publics:missing_static'),
                                        data={'values': [airline.pk]},
                                        user=self.unicef_staff)
        self.assertEqual(response.status_code, 400)
        response_json = json.loads(response.rendered_content)
        self.assertEqual(response_json,
                         {'category': ['This field is required.']})

        response = self.forced_auth_req('get', reverse('publics:missing_static'),
                                        data={'values': [airline.pk],
                                              'category': 'airlines'},
                                        user=self.unicef_staff)
        self.assertEqual(response.status_code, 200)
コード例 #6
0
    def test_itinerary_origin_destination(self):
        dsaregion = DSARegion.objects.first()
        airlines = PublicsAirlineCompanyFactory()

        data = {'itinerary': [{'origin': 'Berlin',
                               'destination': 'Budapest',
                               'departure_date': '2016-11-15T12:06:55.821490',
                               'arrival_date': '2016-11-16T12:06:55.821490',
                               'dsa_region': dsaregion.id,
                               'overnight_travel': False,
                               'mode_of_travel': ModeOfTravel.RAIL,
                               'airlines': [airlines.id]},
                              {'origin': 'Something else',
                               'destination': 'Berlin',
                               'departure_date': '2016-11-16T12:06:55.821490',
                               'arrival_date': '2016-11-17T12:06:55.821490',
                               'dsa_region': dsaregion.id,
                               'overnight_travel': False,
                               'mode_of_travel': ModeOfTravel.RAIL,
                               'airlines': [airlines.id]}],
                'activities': [],
                'supervisor': self.unicef_staff.id,
                'ta_required': True}
        response = self.forced_auth_req('post', reverse('t2f:travels:list:index'), data=data,
                                        user=self.unicef_staff)
        response_json = json.loads(response.rendered_content)
        self.assertEqual(response_json, {'itinerary': ['Origin should match with the previous destination']})
コード例 #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
ファイル: test_threshold.py プロジェクト: alhadheri/etools
    def _prepare_test(self):
        currency = PublicsCurrencyFactory()
        expense_type = PublicsTravelExpenseTypeFactory()
        dsaregion = PublicsDSARegionFactory()
        airlines = PublicsAirlineCompanyFactory()

        data = {'cost_assignments': [],
                'deductions': [{'date': '2016-11-03',
                                'breakfast': True,
                                'lunch': True,
                                'dinner': False,
                                'accomodation': True}],
                'itinerary': [{'origin': 'Berlin',
                               'destination': 'Budapest',
                               'departure_date': '2016-11-15T12:06:55.821490',
                               'arrival_date': '2016-11-16T12:06:55.821490',
                               'dsa_region': dsaregion.id,
                               'overnight_travel': False,
                               'mode_of_travel': ModeOfTravel.RAIL,
                               'airlines': [airlines.id]},
                              {'origin': 'Budapest',
                               'destination': 'Berlin',
                               'departure_date': '2016-11-16T12:06:55.821490',
                               'arrival_date': '2016-11-17T12:06:55.821490',
                               'dsa_region': dsaregion.id,
                               'overnight_travel': False,
                               'mode_of_travel': ModeOfTravel.RAIL,
                               'airlines': [airlines.id]}],
                'traveler': self.traveler.id,
                'ta_required': True,
                'supervisor': self.unicef_staff.id,
                '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)
        self.assertEqual(response_json['cost_summary']['preserved_expenses'], None)

        travel_id = response_json['id']

        response = self.forced_auth_req('post', reverse('t2f:travels:details:state_change',
                                                        kwargs={'travel_pk': travel_id,
                                                                'transition_name': 'submit_for_approval'}),
                                        data=data, user=self.traveler)

        response_json = json.loads(response.rendered_content)
        self.assertEqual(response_json['cost_summary']['preserved_expenses'], None)

        return travel_id, data
コード例 #9
0
    def test_itinerary_dsa_regions(self):
        dsaregion = DSARegion.objects.first()
        airlines = PublicsAirlineCompanyFactory()

        data = {'itinerary': [{'origin': 'Budapest',
                               'destination': 'Berlin',
                               'departure_date': '2016-11-15T12:06:55.821490',
                               'arrival_date': '2016-11-16T12:06:55.821490',
                               'dsa_region': None,
                               'overnight_travel': False,
                               'mode_of_travel': ModeOfTravel.RAIL,
                               'airlines': [airlines.id]},
                              {'origin': 'Berlin',
                               'destination': 'Budapest',
                               'departure_date': '2016-11-16T12:06:55.821490',
                               'arrival_date': '2016-11-17T12:06:55.821490',
                               'dsa_region': dsaregion.id,
                               'overnight_travel': False,
                               'mode_of_travel': ModeOfTravel.RAIL,
                               'airlines': [airlines.id]}],
                'activities': [],
                'ta_required': True}
        response = self.forced_auth_req('post', reverse('t2f:travels:list:index'), data=data,
                                        user=self.unicef_staff)
        response_json = json.loads(response.rendered_content)
        travel_id = response_json['id']

        response = self.forced_auth_req('post', reverse('t2f:travels:details:state_change',
                                                        kwargs={'travel_pk': travel_id,
                                                                'transition_name': Travel.SUBMIT_FOR_APPROVAL}),
                                        data=data, user=self.unicef_staff)
        response_json = json.loads(response.rendered_content)
        self.assertEqual(response_json, {'non_field_errors': ['All itinerary items has to have DSA region assigned']})

        # Non ta trip
        data = {'itinerary': [{'origin': 'Budapest',
                               'destination': 'Berlin',
                               'departure_date': '2016-11-15T12:06:55.821490',
                               'arrival_date': '2016-11-16T12:06:55.821490',
                               'dsa_region': None,
                               'overnight_travel': False,
                               'mode_of_travel': ModeOfTravel.RAIL,
                               'airlines': [airlines.id]},
                              {'origin': 'Berlin',
                               'destination': 'Budapest',
                               'departure_date': '2016-11-16T12:06:55.821490',
                               'arrival_date': '2016-11-17T12:06:55.821490',
                               'dsa_region': dsaregion.id,
                               'overnight_travel': False,
                               'mode_of_travel': ModeOfTravel.RAIL,
                               'airlines': [airlines.id]}],
                'activities': [],
                'supervisor': self.unicef_staff.id,
                'ta_required': False}
        response = self.forced_auth_req('post', reverse('t2f:travels:list:index'), data=data,
                                        user=self.unicef_staff)
        response_json = json.loads(response.rendered_content)
        travel_id = response_json['id']

        response = self.forced_auth_req('post', reverse('t2f:travels:details:state_change',
                                                        kwargs={'travel_pk': travel_id,
                                                                'transition_name': Travel.SUBMIT_FOR_APPROVAL}),
                                        data=data, user=self.unicef_staff)
        self.assertEqual(response.status_code, 200)
コード例 #10
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'])
コード例 #11
0
ファイル: factories.py プロジェクト: azizur77/etools
 def populate_airlines(self, create, extracted, **kwargs):
     airline = PublicsAirlineCompanyFactory()
     self.airlines.add(airline)