def test_business_area(self): instance = PublicsBusinessAreaFactory.build(name='xyz') self.assertEqual(str(instance), 'xyz') # Ost (East) instance = PublicsBusinessAreaFactory.build(name='\xd6st') self.assertEqual(str(instance), '\xd6st')
def test_business_area_code(self): workspace = CountryFactory(schema_name='test1', business_area_code='0001') workspace_override = CountryFactory(schema_name='test2', business_area_code='0002') workspace_invalid_business_area = CountryFactory( schema_name='test3', business_area_code='0003') business_area_0001 = PublicsBusinessAreaFactory(code='0001') business_area_0002 = PublicsBusinessAreaFactory(code='0002') profile = self.unicef_staff.profile # Check if no country set response = self.forced_auth_req('get', '/users/api/profile/', user=self.unicef_staff) response_json = json.loads(response.rendered_content) self.assertEqual(response_json['t2f']['business_area'], None) # Check if country set profile.country = workspace profile.save() response = self.forced_auth_req('get', '/users/api/profile/', user=self.unicef_staff) response_json = json.loads(response.rendered_content) self.assertEqual(response_json['t2f']['business_area'], business_area_0001.id) # Check if country override set profile.country_override = workspace_override profile.save() response = self.forced_auth_req('get', '/users/api/profile/', user=self.unicef_staff) response_json = json.loads(response.rendered_content) self.assertEqual(response_json['t2f']['business_area'], business_area_0002.id) # Check if no matching business area found profile.country_override = workspace_invalid_business_area profile.save() response = self.forced_auth_req('get', '/users/api/profile/', user=self.unicef_staff) response_json = json.loads(response.rendered_content) self.assertEqual(response_json['t2f']['business_area'], None)
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)
def setUpTestData(cls): business_area = PublicsBusinessAreaFactory() cls.traveler = UserFactory(is_staff=True) cls.traveler.profile.vendor_number = 'usrvnd' cls.traveler.profile.save() workspace = cls.traveler.profile.country workspace.business_area_code = business_area.code workspace.save() cls.unicef_staff = UserFactory(is_staff=True) cls.travel = TravelFactory( reference_number=make_travel_reference_number(), traveler=cls.traveler, supervisor=cls.unicef_staff, start_date=datetime(2017, 4, 4, 12, 00, tzinfo=UTC), end_date=datetime(2017, 4, 14, 16, 00, tzinfo=UTC)) cls.travel.expenses.all().delete() ItineraryItemFactory(travel=cls.travel) ItineraryItemFactory(travel=cls.travel) cls.travel.submit_for_approval() cls.travel.approve() cls.travel.send_for_payment() cls.travel.save()
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)
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)
def test_wbs_grant_fund_view(self): # Create a few wbs/grant/fund to see if the query count grows PublicsWBSFactory(business_area=self.business_area) PublicsWBSFactory(business_area=self.business_area) PublicsWBSFactory(business_area=self.business_area) PublicsWBSFactory(business_area=self.business_area) wbs = PublicsWBSFactory(business_area=self.business_area) wbs.grants.clear() with self.assertNumQueries(4): response = self.forced_auth_req('get', reverse('publics:wbs_grants_funds'), user=self.unicef_staff) response_json = json.loads(response.rendered_content) self.assertEqual(len(response_json['wbs']), 5) self.assertKeysIn(['wbs', 'grants', 'funds'], response_json) self.assertEqual(response_json['wbs'][4]['grants'], []) # Check different business area lookup business_area_2 = PublicsBusinessAreaFactory() PublicsWBSFactory(business_area=business_area_2) PublicsWBSFactory(business_area=business_area_2) with self.assertNumQueries(4): response = self.forced_auth_req('get', reverse('publics:wbs_grants_funds'), data={'business_area': business_area_2.id}, user=self.unicef_staff) response_json = json.loads(response.rendered_content) self.assertEqual(len(response_json['wbs']), 2)
def setUpTestData(cls): cls.unicef_staff = UserFactory(is_staff=True) cls.business_area = PublicsBusinessAreaFactory() workspace = cls.unicef_staff.profile.country workspace.business_area_code = cls.business_area.code workspace.save()
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)
def test_mailing(self): tenant_country = self.travel.traveler.profile.country tenant_country.business_area_code = '0' tenant_country.save() PublicsBusinessAreaFactory(code=self.travel.traveler.profile.country.business_area_code) self.travel.submit_for_approval() self.travel.approve() self.travel.report_note = 'Note' self.travel.mark_as_completed() self.assertEqual(len(mail.outbox), 3) for email in mail.outbox: self.assertIn(self.travel.reference_number, email.subject, email.subject)
def test_state_machine_flow_invoice_disabled(self): currency = PublicsCurrencyFactory() expense_type = PublicsTravelExpenseTypeFactory() business_area = PublicsBusinessAreaFactory() dsa_region = PublicsDSARegionFactory() wbs = PublicsWBSFactory(business_area=business_area) grant = wbs.grants.first() fund = grant.funds.first() workspace = self.unicef_staff.profile.country workspace.business_area_code = business_area.code workspace.save() data = { 'cost_assignments': [{ 'wbs': wbs.id, 'grant': grant.id, 'fund': fund.id, 'share': 100 }], 'deductions': [{ 'date': '2016-11-03', 'breakfast': True, 'lunch': True, 'dinner': False, 'accomodation': True }], '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': [] }], 'traveler': self.traveler.id, 'ta_required': True, 'currency': currency.id, '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.unicef_staff) 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) travel = Travel.objects.get(id=travel_id) self.assertIsNotNone(travel.submitted_at) self.assertIsNotNone(travel.first_submission_date) response = self.forced_auth_req('post', reverse( 't2f:travels:details:state_change', kwargs={ 'travel_pk': travel_id, 'transition_name': 'approve' }), data=response_json, user=self.traveler) response_json = json.loads(response.rendered_content) # Go straight to sent for payment when invoicing is disabled. self.assertEqual(response_json['status'], Travel.SENT_FOR_PAYMENT) # No email has been sent regarding SENT_FOR_PAYMENT status when invoicing is disabled. subjects = [x.subject for x in mail.outbox] self.assertNotIn( 'Travel #{} sent for payment.'.format( response_json["reference_number"]), subjects) response = self.forced_auth_req('post', reverse( 't2f:travels:details:state_change', kwargs={ 'travel_pk': travel_id, 'transition_name': 'mark_as_certified' }), data=response_json, user=self.traveler) response_json = json.loads(response.rendered_content) # No pending invoice check when invoicing is disabled. self.assertEqual(response_json['status'], Travel.CERTIFIED) response = self.forced_auth_req('post', reverse( 't2f:travels:details:state_change', kwargs={ 'travel_pk': travel_id, 'transition_name': 'mark_as_completed' }), data=data, user=self.traveler) response_json = json.loads(response.rendered_content) self.assertEqual(response_json['non_field_errors'], ['Field report has to be filled.']) self.assertEqual(travel.report_note, '') # None should be handled as empty string travel.report_note = None # This has to be set explicitly since serializer does not accept None response = self.forced_auth_req('post', reverse( 't2f:travels:details:state_change', kwargs={ 'travel_pk': travel_id, 'transition_name': 'mark_as_completed' }), data=data, user=self.traveler) response_json = json.loads(response.rendered_content) self.assertEqual(response_json['non_field_errors'], ['Field report has to be filled.']) self.assertEqual(travel.report_note, None) data = response_json data['report'] = 'Something' response = self.forced_auth_req('post', reverse( 't2f:travels:details:state_change', kwargs={ 'travel_pk': travel_id, 'transition_name': 'mark_as_completed' }), data=data, user=self.traveler) response_json = json.loads(response.rendered_content) self.assertEqual(response_json['status'], Travel.COMPLETED)
def test_expense_required_on_send_for_payment(self): business_area = PublicsBusinessAreaFactory() dsa_region = PublicsDSARegionFactory() currency = PublicsCurrencyFactory() workspace = self.unicef_staff.profile.country workspace.business_area_code = business_area.code workspace.save() 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': [] }], 'traveler': self.traveler.id, 'ta_required': True, 'supervisor': self.unicef_staff.id, 'currency': currency.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'] 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.unicef_staff) response_json = json.loads(response.rendered_content) response = self.forced_auth_req('post', reverse( 't2f:travels:details:state_change', kwargs={ 'travel_pk': travel_id, 'transition_name': 'approve' }), data=response_json, user=self.unicef_staff) self.assertEqual(response.status_code, 200)
def test_completed_counts(self): currency = PublicsCurrencyFactory() expense_type = PublicsTravelExpenseTypeFactory() business_area = PublicsBusinessAreaFactory() dsa_region = PublicsDSARegionFactory() wbs = PublicsWBSFactory(business_area=business_area) grant = wbs.grants.first() fund = grant.funds.first() traveler = UserFactory(is_staff=True) traveler.profile.vendor_number = 'usrvend' traveler.profile.save() travel = TravelFactory(reference_number=make_travel_reference_number(), traveler=traveler, status=Travel.CERTIFIED, supervisor=self.unicef_staff) data = { 'cost_assignments': [{ 'wbs': wbs.id, 'grant': grant.id, 'fund': fund.id, 'share': 100 }], 'deductions': [{ 'date': '2016-11-03', 'breakfast': True, 'lunch': True, 'dinner': False, 'accomodation': True }], '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': [] }], 'traveler': traveler.id, 'ta_required': True, 'report': 'Some report', 'currency': currency.id, 'supervisor': self.unicef_staff.id, 'expenses': [{ 'amount': '120', 'type': expense_type.id, 'currency': currency.id, 'document_currency': currency.id }] } act1 = TravelActivityFactory( travel_type=TravelType.PROGRAMME_MONITORING, primary_traveler=traveler) act2 = TravelActivityFactory(travel_type=TravelType.SPOT_CHECK, primary_traveler=traveler) act1.travels.add(travel) act2.travels.add(travel) partner_programmatic_visits = PartnerOrganization.objects.get( id=act1.partner.id) partner_spot_checks = PartnerOrganization.objects.get( id=act2.partner.id) response = self.forced_auth_req('post', reverse( 't2f:travels:details:state_change', kwargs={ 'travel_pk': travel.id, 'transition_name': 'mark_as_completed' }), user=traveler, data=data) response_json = json.loads(response.rendered_content) partner_programmatic_visits_after_complete = PartnerOrganization.objects.get( id=act1.partner.id) partner_spot_checks_after_complete = PartnerOrganization.objects.get( id=act2.partner.id) self.assertEqual(response_json['status'], Travel.COMPLETED) self.assertEqual( partner_programmatic_visits.hact_values['programmatic_visits'] ['completed']['total'] + 1, partner_programmatic_visits_after_complete. hact_values['programmatic_visits']['completed']['total']) self.assertEqual( partner_spot_checks.hact_values['spot_checks']['completed'] ['total'] + 1, partner_spot_checks_after_complete.hact_values['spot_checks'] ['completed']['total'])
def test_expense_required_on_send_for_payment(self): business_area = PublicsBusinessAreaFactory() dsa_region = PublicsDSARegionFactory() currency = PublicsCurrencyFactory() wbs = PublicsWBSFactory(business_area=business_area) grant = wbs.grants.first() fund = grant.funds.first() workspace = self.unicef_staff.profile.country workspace.business_area_code = business_area.code workspace.save() data = { 'cost_assignments': [{ 'wbs': wbs.id, 'grant': grant.id, 'fund': fund.id, 'share': 100 }], 'deductions': [{ 'date': '2016-11-03', 'breakfast': True, 'lunch': True, 'dinner': False, 'accomodation': True }], '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': [] }], 'traveler': self.traveler.id, 'ta_required': True, 'supervisor': self.unicef_staff.id, 'expenses': [], 'currency': currency.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) 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.unicef_staff) response_json = json.loads(response.rendered_content) response = self.forced_auth_req('post', reverse( 't2f:travels:details:state_change', kwargs={ 'travel_pk': travel_id, 'transition_name': 'approve' }), data=response_json, user=self.unicef_staff) response_json = json.loads(response.rendered_content) response = self.forced_auth_req('post', reverse( 't2f:travels:details:state_change', kwargs={ 'travel_pk': travel_id, 'transition_name': 'send_for_payment' }), data=response_json, user=self.unicef_staff) response_json = json.loads(response.rendered_content) self.assertEqual(response.status_code, 200) self.assertEqual( Decimal(response_json['cost_summary']['preserved_expenses']), Decimal('0.00'))
def test_state_machine_flow(self): currency = PublicsCurrencyFactory() business_area = PublicsBusinessAreaFactory() dsa_region = PublicsDSARegionFactory() workspace = self.unicef_staff.profile.country workspace.business_area_code = business_area.code workspace.save() 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': [] }], 'traveler': self.traveler.id, 'ta_required': True, 'currency': currency.id, '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'] 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.traveler) response_json = json.loads(response.rendered_content) travel = Travel.objects.get(id=travel_id) self.assertIsNotNone(travel.submitted_at) self.assertIsNotNone(travel.first_submission_date) response = self.forced_auth_req( 'post', reverse('t2f:travels:details:state_change', kwargs={ 'travel_pk': travel_id, 'transition_name': Travel.APPROVE }), data=response_json, user=self.traveler) response_json = json.loads(response.rendered_content) self.assertEqual(response_json['status'], Travel.APPROVED) response = self.forced_auth_req( 'post', reverse('t2f:travels:details:state_change', kwargs={ 'travel_pk': travel_id, 'transition_name': Travel.COMPLETE }), data=data, user=self.traveler) response_json = json.loads(response.rendered_content) self.assertEqual(response_json['non_field_errors'], ['Field report has to be filled.']) self.assertEqual(travel.report_note, '') # None should be handled as empty string travel.report_note = None # This has to be set explicitly since serializer does not accept None response = self.forced_auth_req( 'post', reverse('t2f:travels:details:state_change', kwargs={ 'travel_pk': travel_id, 'transition_name': Travel.COMPLETE }), data=data, user=self.traveler) response_json = json.loads(response.rendered_content) self.assertEqual(response_json['non_field_errors'], ['Field report has to be filled.']) self.assertEqual(travel.report_note, None) # data = response_json data['report'] = 'Something' response = self.forced_auth_req( 'post', reverse('t2f:travels:details:state_change', kwargs={ 'travel_pk': travel_id, 'transition_name': Travel.COMPLETE }), data=data, user=self.traveler) response_json = json.loads(response.rendered_content) self.assertEqual(response_json['status'], Travel.COMPLETED)
def test_state_machine_flow(self): currency = PublicsCurrencyFactory() expense_type = PublicsTravelExpenseTypeFactory() business_area = PublicsBusinessAreaFactory() dsa_region = PublicsDSARegionFactory() wbs = PublicsWBSFactory(business_area=business_area) grant = wbs.grants.first() fund = grant.funds.first() workspace = self.unicef_staff.profile.country workspace.business_area_code = business_area.code workspace.save() data = { 'cost_assignments': [{ 'wbs': wbs.id, 'grant': grant.id, 'fund': fund.id, 'share': 100 }], 'deductions': [{ 'date': '2016-11-03', 'breakfast': True, 'lunch': True, 'dinner': False, 'accomodation': True }], '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': [] }], 'traveler': self.traveler.id, 'ta_required': True, 'currency': currency.id, '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.unicef_staff) 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) travel = Travel.objects.get(id=travel_id) self.assertIsNotNone(travel.submitted_at) self.assertIsNotNone(travel.first_submission_date) response = self.forced_auth_req('post', reverse( 't2f:travels:details:state_change', kwargs={ 'travel_pk': travel_id, 'transition_name': 'approve' }), data=response_json, user=self.traveler) response_json = json.loads(response.rendered_content) response = self.forced_auth_req('post', reverse( 't2f:travels:details:state_change', kwargs={ 'travel_pk': travel_id, 'transition_name': 'send_for_payment' }), data=response_json, user=self.traveler) response_json = json.loads(response.rendered_content) response = self.forced_auth_req('post', reverse( 't2f:travels:details:state_change', kwargs={ 'travel_pk': travel_id, 'transition_name': 'mark_as_certified' }), data=response_json, user=self.traveler) response_json = json.loads(response.rendered_content) self.assertEqual(response_json['non_field_errors'], [ 'Your TA has pending payments to be processed through ' 'VISION. Until payments are completed, you can not certify' ' your TA. Please check with your Finance focal point on ' 'how to proceed.' ]) travel = Travel.objects.get(id=travel_id) travel.invoices.all().update(status=Invoice.SUCCESS) response = self.forced_auth_req('post', reverse( 't2f:travels:details:state_change', kwargs={ 'travel_pk': travel_id, 'transition_name': 'mark_as_certified' }), data=data, user=self.traveler) response_json = json.loads(response.rendered_content) self.assertEqual(response_json['status'], Travel.CERTIFIED) response = self.forced_auth_req('post', reverse( 't2f:travels:details:state_change', kwargs={ 'travel_pk': travel_id, 'transition_name': 'mark_as_completed' }), data=data, user=self.traveler) response_json = json.loads(response.rendered_content) self.assertEqual(response_json['non_field_errors'], ['Field report has to be filled.']) self.assertEqual(travel.report_note, '') # None should be handled as empty string travel.report_note = None # This has to be set explicitly since serializer does not accept None response = self.forced_auth_req('post', reverse( 't2f:travels:details:state_change', kwargs={ 'travel_pk': travel_id, 'transition_name': 'mark_as_completed' }), data=data, user=self.traveler) response_json = json.loads(response.rendered_content) self.assertEqual(response_json['non_field_errors'], ['Field report has to be filled.']) self.assertEqual(travel.report_note, None) data = response_json data['report'] = 'Something' response = self.forced_auth_req('post', reverse( 't2f:travels:details:state_change', kwargs={ 'travel_pk': travel_id, 'transition_name': 'mark_as_completed' }), data=data, user=self.traveler) response_json = json.loads(response.rendered_content) self.assertEqual(response_json['status'], Travel.COMPLETED)
def setUpTestData(cls): cls.country = Country.objects.first() cls.business = PublicsBusinessAreaFactory(code="666")