def test_accept(self): """Test that a quote can get accepted.""" order = OrderWithOpenQuoteFactory() quote = order.quote url = reverse( f'api-v3:omis-public:quote:accept', kwargs={'public_token': order.public_token}, ) client = self.create_api_client( scope=Scope.public_omis_front_end, grant_type=Application.GRANT_CLIENT_CREDENTIALS, ) with freeze_time('2017-07-12 13:00'): response = client.post(url) assert response.status_code == status.HTTP_200_OK assert response.json() == { 'created_on': format_date_or_datetime(quote.created_on), 'accepted_on': format_date_or_datetime(now()), 'cancelled_on': None, 'expires_on': quote.expires_on.isoformat(), 'content': quote.content, 'terms_and_conditions': TermsAndConditions.objects.first().content, } quote.refresh_from_db() assert quote.is_accepted() assert quote.accepted_on == now()
def get_expected_data_from_interaction(interaction): """Returns expected API response dictionary for an interaction""" return { 'adviser_ids': [ str(x.adviser_id) for x in interaction.dit_participants.all().order_by('pk') ], 'communication_channel__name': get_attr_or_none( interaction, 'communication_channel.name', ), 'company_id': str(interaction.company.id), 'contact_ids': [str(x.id) for x in interaction.contacts.all().order_by('pk')], 'created_by_id': str(interaction.created_by_id), 'created_on': format_date_or_datetime(interaction.created_on), 'date': format_date_or_datetime(interaction.date), 'event_id': ( str(interaction.event_id) if interaction.event_id is not None else None ), 'grant_amount_offered': ( float(interaction.grant_amount_offered) if interaction.grant_amount_offered is not None else None ), 'id': str(interaction.id), 'interaction_link': interaction.get_absolute_url(), 'investment_project_id': ( str(interaction.investment_project_id) if interaction.investment_project is not None else None ), 'kind': interaction.kind, 'modified_on': format_date_or_datetime(interaction.modified_on), 'net_company_receipt': ( float(interaction.net_company_receipt) if interaction.net_company_receipt is not None else None ), 'notes': interaction.notes, 'policy_area_names': ( [x.name for x in interaction.policy_areas.all()] if interaction.policy_areas.exists() else None ), 'policy_feedback_notes': interaction.policy_feedback_notes, 'policy_issue_type_names': ( [x.name for x in interaction.policy_issue_types.all()] if interaction.policy_areas.exists() else None ), 'sector': get_attr_or_none(interaction, 'company.sector.name'), 'service_delivery_status__name': get_attr_or_none( interaction, 'service_delivery_status.name', ), 'service_delivery': get_attr_or_none(interaction, 'service.name'), 'subject': interaction.subject, 'theme': interaction.theme, 'were_countries_discussed': interaction.were_countries_discussed, }
def get_expected_data_from_company_referral(referral): """Returns company referral data as a dictionary""" return { 'company_id': str(referral.company_id), 'completed_by_id': get_attr_or_none(referral, 'completed_by_id'), 'completed_on': format_date_or_datetime(referral.completed_on), 'contact_id': str(referral.contact_id), 'created_by_id': str(referral.created_by_id), 'created_on': format_date_or_datetime(referral.created_on), 'id': str(referral.id), 'interaction_id': (str(referral.interaction_id) if referral.interaction_id is not None else None), 'notes': referral.notes, 'recipient_id': str(referral.recipient_id), 'status': str(referral.status), 'subject': referral.subject, }
def test_accept(self, public_omis_api_client): """Test that a quote can get accepted.""" order = OrderWithOpenQuoteFactory() quote = order.quote url = reverse( 'api-v3:public-omis:quote:accept', kwargs={'public_token': order.public_token}, ) with freeze_time('2017-07-12 13:00'): response = public_omis_api_client.post(url, json_={}) assert response.status_code == status.HTTP_200_OK assert response.json() == { 'created_on': format_date_or_datetime(quote.created_on), 'accepted_on': format_date_or_datetime(now()), 'cancelled_on': None, 'expires_on': quote.expires_on.isoformat(), 'content': quote.content, 'terms_and_conditions': TermsAndConditions.objects.first().content, } quote.refresh_from_db() assert quote.is_accepted() assert quote.accepted_on == now()
def test_retrieve_a_referral(self, factory): """Test that a single referral can be retrieved.""" referral = factory() url = _item_url(referral.pk) response = self.api_client.get(url) assert response.status_code == status.HTTP_200_OK response_data = response.json() assert response_data == { 'company': { 'id': str(referral.company.pk), 'name': referral.company.name, }, 'completed_by': format_expected_adviser(referral.completed_by), 'completed_on': format_date_or_datetime(referral.completed_on), 'contact': { 'id': str(referral.contact.pk), 'name': referral.contact.name, }, 'created_by': format_expected_adviser(referral.created_by), 'created_on': format_date_or_datetime(referral.created_on), 'id': str(referral.pk), 'interaction': { 'id': str(referral.interaction.pk), 'subject': referral.interaction.subject, } if referral.interaction else None, 'notes': referral.notes, 'recipient': format_expected_adviser(referral.recipient), 'status': referral.status, 'subject': referral.subject, }
def test_get_draft_with_cancelled_quote(self): """Test getting a cancelled quote with order in draft is allowed.""" order = OrderFactory( quote=QuoteFactory(cancelled_on=now()), status=OrderStatus.draft, ) url = reverse( 'api-v3:omis-public:quote:detail', kwargs={'public_token': order.public_token}, ) client = self.create_api_client( scope=Scope.public_omis_front_end, grant_type=Application.GRANT_CLIENT_CREDENTIALS, ) response = client.get(url) quote = order.quote assert response.status_code == status.HTTP_200_OK assert response.json() == { 'created_on': format_date_or_datetime(quote.created_on), 'cancelled_on': format_date_or_datetime(quote.cancelled_on), 'accepted_on': None, 'expires_on': quote.expires_on.isoformat(), 'content': quote.content, 'terms_and_conditions': TermsAndConditions.objects.first().content, }
def get_expected_data_from_pipeline_item(item): """Returns pipeline item data as a dictionary""" return { 'adviser_id': str(item.adviser_id), 'archived': item.archived, 'company_id': str(item.company_id), 'contact_ids': [str(contact.id) for contact in item.contacts.all()] or None, 'created_on': format_date_or_datetime(item.created_on), 'expected_win_date': (format_date_or_datetime(item.expected_win_date) if item.expected_win_date else None), 'id': str(item.id), 'likelihood_to_win': item.likelihood_to_win, 'modified_on': format_date_or_datetime(item.modified_on), 'name': item.name, 'potential_value': item.potential_value, 'sector_name': get_attr_or_none(item, 'sector.name'), 'status': item.status, }
def test_document_retrieval(self, permissions, associated, allowed): """Tests retrieval of individual document.""" user = create_test_user(permission_codenames=permissions, dit_team=TeamFactory()) entity_document = create_evidence_document(user, associated=associated) url = reverse( 'api-v3:investment:evidence-document:document-item', kwargs={ 'project_pk': entity_document.investment_project.pk, 'entity_document_pk': entity_document.pk, }, ) api_client = self.create_api_client(user=user) response = api_client.get(url) response_data = response.json() if not allowed: assert response.status_code == status.HTTP_403_FORBIDDEN assert response_data == { 'detail': 'You do not have permission to perform this action.', } return assert response.status_code == status.HTTP_200_OK assert 'tags' in response_data response_data['tags'] = sorted(response_data['tags'], key=itemgetter('name')) assert response_data == { 'id': str(entity_document.pk), 'av_clean': None, 'comment': entity_document.comment, 'investment_project': { 'name': entity_document.investment_project.name, 'project_code': entity_document.investment_project.project_code, 'id': str(entity_document.investment_project.pk), }, 'created_by': { 'id': str(entity_document.created_by.pk), 'first_name': entity_document.created_by.first_name, 'last_name': entity_document.created_by.last_name, 'name': entity_document.created_by.name, }, 'modified_by': None, 'tags': [ {'id': str(tag.id), 'name': tag.name} for tag in sorted(entity_document.tags.all(), key=attrgetter('name')) ], 'original_filename': 'test.txt', 'url': _get_document_url(entity_document), 'status': UPLOAD_STATUSES.not_virus_scanned, 'created_on': format_date_or_datetime(entity_document.created_on), 'modified_on': format_date_or_datetime(entity_document.modified_on), 'uploaded_on': format_date_or_datetime(entity_document.document.uploaded_on), }
def get_expected_data_from_company_export_country(company_export_country): """Returns company_export_country data as a dictionary""" return { 'id': str(company_export_country.id), 'company_id': str(company_export_country.company_id), 'country__name': company_export_country.country.name, 'country__iso_alpha2_code': company_export_country.country.iso_alpha2_code, 'created_on': format_date_or_datetime(company_export_country.created_on), 'modified_on': format_date_or_datetime(company_export_country.modified_on), 'status': company_export_country.status, }
def get_expected_data_from_adviser(adviser): """Returns adviser data as a dictionary""" return { 'id': str(adviser.id), 'date_joined': format_date_or_datetime(adviser.date_joined), 'first_name': adviser.first_name, 'last_login': format_date_or_datetime(adviser.last_login), 'last_name': adviser.last_name, 'telephone_number': adviser.telephone_number, 'contact_email': adviser.contact_email, 'dit_team_id': str(adviser.dit_team.id), 'is_active': adviser.is_active, 'sso_email_user_id': adviser.sso_email_user_id, }
def get_expected_data_from_contact(contact): """Returns expected dictionary based on given contact""" return { 'accepts_dit_email_marketing': contact.accepts_dit_email_marketing, 'address_1': contact.address_1, 'address_2': contact.address_2, 'address_country__name': get_attr_or_none(contact, 'address_country.name'), 'address_county': contact.address_county, 'address_postcode': contact.address_postcode, 'address_same_as_company': contact.address_same_as_company, 'address_town': contact.address_town, 'archived': contact.archived, 'archived_on': format_date_or_datetime(contact.archived_on), 'company_id': str(contact.company_id) if contact.company_id is not None else None, 'created_on': format_date_or_datetime(contact.created_on), 'email': contact.email, 'email_alternative': contact.email_alternative, 'id': str(contact.id), 'job_title': contact.job_title, 'modified_on': format_date_or_datetime(contact.modified_on), 'name': contact.name, 'notes': contact.notes, 'primary': contact.primary, 'telephone_alternative': contact.telephone_alternative, 'telephone_number': contact.telephone_number, }
def test_indexed_doc(setup_es): """Test the ES data of an indexed companies house company.""" ch_company = CompaniesHouseCompanyFactory() doc = ESCompaniesHouseCompany.es_document(ch_company) elasticsearch.bulk(actions=(doc, ), chunk_size=1) setup_es.indices.refresh() indexed_ch_company = setup_es.get( index=ESCompaniesHouseCompany.get_write_index(), doc_type=CompaniesHouseCompanySearchApp.name, id=ch_company.pk, ) assert indexed_ch_company == { '_index': ESCompaniesHouseCompany.get_target_index_name(), '_type': CompaniesHouseCompanySearchApp.name, '_id': str(ch_company.pk), '_version': indexed_ch_company['_version'], 'found': True, '_source': { 'id': str(ch_company.pk), 'name': ch_company.name, 'registered_address_1': ch_company.registered_address_1, 'registered_address_2': ch_company.registered_address_2, 'registered_address_town': ch_company.registered_address_town, 'registered_address_county': ch_company.registered_address_county, 'registered_address_postcode': ch_company.registered_address_postcode, 'registered_address_country': { 'id': str(ch_company.registered_address_country.pk), 'name': ch_company.registered_address_country.name, }, 'company_number': ch_company.company_number, 'company_category': ch_company.company_category, 'company_status': ch_company.company_status, 'sic_code_1': ch_company.sic_code_1, 'sic_code_2': ch_company.sic_code_2, 'sic_code_3': ch_company.sic_code_3, 'sic_code_4': ch_company.sic_code_4, 'uri': ch_company.uri, 'incorporation_date': format_date_or_datetime(ch_company.incorporation_date), }, }
def test_get(self, order_status): """Test a successful call to get a list of payments.""" order = OrderFactory(status=order_status) PaymentFactory.create_batch(2, order=order) PaymentFactory.create_batch(5) # create some extra ones not linked to `order` url = reverse( 'api-v3:omis-public:payment:collection', kwargs={'public_token': order.public_token}, ) client = self.create_api_client( scope=Scope.public_omis_front_end, grant_type=Application.GRANT_CLIENT_CREDENTIALS, ) response = client.get(url) assert response.status_code == status.HTTP_200_OK assert response.json() == [ { 'created_on': format_date_or_datetime(payment.created_on), 'reference': payment.reference, 'transaction_reference': payment.transaction_reference, 'additional_reference': payment.additional_reference, 'amount': payment.amount, 'method': payment.method, 'received_on': payment.received_on.isoformat(), } for payment in order.payments.all() ]
def test_returns_items_in_expected_format(self): """Test that referrals are returned in expected format.""" company_referral = CompanyReferralFactory(created_by=self.user) response = self.api_client.get(collection_url) assert response.status_code == status.HTTP_200_OK results = response.json()['results'] assert len(results) == 1 assert results[0] == { 'id': str(company_referral.pk), 'company': { 'id': str(company_referral.company.pk), 'name': company_referral.company.name, }, 'completed_by': None, 'completed_on': None, 'contact': { 'id': str(company_referral.contact.pk), 'name': company_referral.contact.name, }, 'created_by': format_expected_adviser(company_referral.created_by), 'created_on': format_date_or_datetime(company_referral.created_on), 'interaction': None, 'recipient': format_expected_adviser(company_referral.recipient), 'status': company_referral.status, 'subject': company_referral.subject, 'notes': company_referral.notes, }
def test_list(self, metadata_client): """ Test listing services. Services should include a list of contexts. """ url = reverse(viewname='api-v4:metadata:service') response = metadata_client.get(url) service_queryset = Service.objects.filter(children__isnull=True) service = service_queryset.order_by('order')[0] assert response.status_code == status.HTTP_200_OK services = response.json() disabled_on = format_date_or_datetime( service.disabled_on) if service.disabled_on else None services[0]['contexts'] = sorted(services[0]['contexts']) assert services[0] == { 'id': str(service.pk), 'name': service.name, 'contexts': sorted(service.contexts), 'disabled_on': disabled_on, 'interaction_questions': [], } assert len(services) == service_queryset.count()
def test_get(self): """Test a successful call to get a list of payments.""" order = OrderPaidFactory() PaymentFactory.create_batch(2, order=order) PaymentFactory.create_batch( 5) # create some extra ones not linked to `order` url = reverse('api-v3:omis:payment:collection', kwargs={'order_pk': order.pk}) response = self.api_client.get(url) assert response.status_code == status.HTTP_200_OK assert response.json() == [{ 'created_on': format_date_or_datetime(payment.created_on), 'reference': payment.reference, 'transaction_reference': payment.transaction_reference, 'additional_reference': payment.additional_reference, 'amount': payment.amount, 'method': payment.method, 'received_on': payment.received_on.isoformat(), } for payment in order.payments.all()]
def test_can_successfully_rename_a_list(self): """Test that a list can be renamed.""" company_list = CompanyListFactory(adviser=self.user, name='old name') url = _get_list_detail_url(company_list.pk) new_name = 'new name' response = self.api_client.patch( url, data={ 'name': new_name, }, ) assert response.status_code == status.HTTP_200_OK response_data = response.json() assert response_data == { 'id': str(company_list.pk), 'item_count': 0, 'name': new_name, 'created_on': format_date_or_datetime(company_list.created_on), } company_list.refresh_from_db() assert company_list.name == new_name
def test_country_view(metadata_client): """Test that the country view includes the country field.""" country = Country.objects.filter( overseas_region__isnull=False, ).order_by( 'name', ).first() url = reverse(viewname='api-v4:metadata:country') response = metadata_client.get(url) assert response.status_code == status.HTTP_200_OK first_result_with_overseas_region = next( result for result in response.json() if result['overseas_region'] is not None ) assert first_result_with_overseas_region == { 'id': str(country.pk), 'name': country.name, 'overseas_region': { 'id': str(country.overseas_region.pk), 'name': country.overseas_region.name, }, 'disabled_on': format_date_or_datetime(country.disabled_on), 'iso_alpha2_code': country.iso_alpha2_code, }
def test_get(self): """Test a successful call to get a quote.""" order = OrderWithOpenQuoteFactory() quote = order.quote url = reverse('api-v3:omis:quote:detail', kwargs={'order_pk': order.pk}) response = self.api_client.get(url) assert response.status_code == status.HTTP_200_OK assert response.json() == { 'created_on': format_date_or_datetime(quote.created_on), 'created_by': { 'id': str(quote.created_by.pk), 'first_name': quote.created_by.first_name, 'last_name': quote.created_by.last_name, 'name': quote.created_by.name, }, 'cancelled_on': None, 'cancelled_by': None, 'accepted_on': None, 'accepted_by': None, 'expires_on': quote.expires_on.isoformat(), 'content': quote.content, 'terms_and_conditions': TermsAndConditions.objects.first().content, }
def test_with_different_govuk_payment_status_updates_session( self, govuk_status, payment_url, requests_mock, ): """ Test that if the GOV.UK payment status is not the same as the payment gateway session one, the record is updated. """ # choose an initial status != from the govuk one to test the update initial_status = PaymentGatewaySessionStatus.created if initial_status == govuk_status: initial_status = PaymentGatewaySessionStatus.started session = PaymentGatewaySessionFactory(status=initial_status) # mock GOV.UK call used to get the existing session requests_mock.get( govuk_url(f'payments/{session.govuk_payment_id}'), status_code=200, json={ 'state': { 'status': govuk_status }, 'payment_id': session.govuk_payment_id, '_links': { 'next_url': None if not payment_url else { 'href': payment_url }, }, }, ) # make API call url = reverse( 'api-v3:omis-public:payment-gateway-session:detail', kwargs={ 'public_token': session.order.public_token, 'pk': session.id }, ) client = self.create_api_client( scope=Scope.public_omis_front_end, grant_type=Application.GRANT_CLIENT_CREDENTIALS, ) response = client.get(url) assert response.status_code == status.HTTP_200_OK # refresh record session.refresh_from_db() assert session.status == govuk_status # check API response assert response.json() == { 'id': str(session.id), 'created_on': format_date_or_datetime(session.created_on), 'status': govuk_status, 'payment_url': payment_url, }
def test_list(self, api_client): """ Test listing sectors. Sectors should be sorted by full name (path). """ url = reverse(viewname='sector') response = api_client.get(url) sector = Sector.objects.order_by('lft')[0] assert response.status_code == status.HTTP_200_OK sectors = response.json() disabled_on = format_date_or_datetime( sector.disabled_on) if sector.disabled_on else None assert sectors[0] == { 'id': str(sector.pk), 'name': sector.name, 'segment': sector.segment, 'level': sector.level, 'parent': { 'id': str(sector.parent.pk), 'name': sector.parent.name, } if sector.parent else None, 'disabled_on': disabled_on, } assert sectors == list(sorted(sectors, key=itemgetter('name')))
def test_doesnt_call_govuk_pay_if_session_finished(self, session_status, requests_mock): """ Test a successful call to get a payment gateway session when the session is finished. The system does not call GOV.UK Pay as the record is up-to-date. """ session = PaymentGatewaySessionFactory(status=session_status) # make API call url = reverse( 'api-v3:omis-public:payment-gateway-session:detail', kwargs={ 'public_token': session.order.public_token, 'pk': session.id }, ) client = self.create_api_client( scope=Scope.public_omis_front_end, grant_type=Application.GRANT_CLIENT_CREDENTIALS, ) response = client.get(url) assert response.status_code == status.HTTP_200_OK # check API response assert response.json() == { 'id': str(session.id), 'created_on': format_date_or_datetime(session.created_on), 'status': session.status, 'payment_url': '', } assert not requests_mock.called
def test_can_create_a_referral_with_optional_fields(self): """Test that a referral can be created with all optional values filled in.""" company = CompanyFactory() contact = ContactFactory() recipient = AdviserFactory() subject = 'Test referral' notes = 'Some notes' request_data = { 'subject': subject, 'company': { 'id': company.pk, }, 'recipient': { 'id': recipient.pk, }, 'contact': { 'id': contact.pk, }, 'notes': notes, } response = self.api_client.post(collection_url, data=request_data) assert response.status_code == status.HTTP_201_CREATED response_data = response.json() assert response_data == { 'company': { 'id': str(company.pk), 'name': company.name, }, 'completed_on': None, 'contact': { 'id': str(contact.pk), 'name': contact.name, }, 'created_by': { 'contact_email': self.user.contact_email, 'dit_team': { 'id': str(self.user.dit_team.pk), 'name': self.user.dit_team.name, }, 'id': str(self.user.pk), 'name': self.user.name, }, 'created_on': format_date_or_datetime(FROZEN_DATETIME), 'id': ANY, 'notes': notes, 'recipient': { 'contact_email': recipient.contact_email, 'dit_team': { 'id': str(recipient.dit_team.pk), 'name': recipient.dit_team.name, }, 'id': str(recipient.pk), 'name': recipient.name, }, 'status': CompanyReferral.STATUSES.outstanding, 'subject': subject, }
def get_expected_data_from_user_log(event): """Returns user event log data as a dictionary""" return { 'adviser__id': str(event.adviser.id), 'type': event.type, 'api_url_path': event.api_url_path, 'created_on': format_date_or_datetime(event.timestamp), }
def test_with_item(self, company_factory): """Test serialisation of various companies.""" company = company_factory() list_item = CompanyListItemFactory(list__adviser=self.user, company=company) latest_interaction = company.interactions.order_by( '-date', '-created_by', 'pk').first() url = _get_list_item_collection_url(list_item.list.pk) response = self.api_client.get(url) assert response.status_code == status.HTTP_200_OK response_data = response.json() assert response_data['results'] == [ { 'company': { 'id': str(company.pk), 'archived': company.archived, 'name': company.name, 'trading_names': company.trading_names, }, 'created_on': format_date_or_datetime(list_item.created_on), 'latest_interaction': { 'id': str(latest_interaction.pk), 'created_on': format_date_or_datetime(latest_interaction.created_on), 'date': format_date_or_datetime(latest_interaction.date.date()), 'subject': latest_interaction.subject, 'dit_participants': [{ 'adviser': { 'id': str(dit_participant.adviser.pk), 'name': dit_participant.adviser.name, } if dit_participant.adviser else None, 'team': { 'id': str(dit_participant.team.pk), 'name': dit_participant.team.name, } if dit_participant.team else None, } for dit_participant in latest_interaction. dit_participants.order_by('pk')], } if latest_interaction else None, }, ]
def get_expected_data_from_order(order): """Returns expected dictionary based on given order""" return { 'cancellation_reason__name': get_attr_or_none(order, 'cancellation_reason.name'), 'cancelled_on': format_date_or_datetime(order.cancelled_on), 'company_id': str(order.company_id), 'completed_on': format_date_or_datetime(order.completed_on), 'contact_id': str(order.contact_id), 'created_by__dit_team_id': str(order.created_by.dit_team_id), 'created_on': format_date_or_datetime(order.created_on), 'delivery_date': format_date_or_datetime(order.delivery_date), 'id': str(order.id), 'invoice__subtotal_cost': get_attr_or_none(order, 'invoice.subtotal_cost'), 'paid_on': format_date_or_datetime(order.paid_on), 'primary_market__name': get_attr_or_none(order, 'primary_market.name'), 'quote__accepted_on': format_date_or_datetime(get_attr_or_none(order, 'quote.accepted_on'), ), 'quote__created_on': format_date_or_datetime(get_attr_or_none(order, 'quote.created_on')), 'reference': order.reference, 'refund_created': (format_date_or_datetime( order.refunds.latest('created_on').created_on) if order.refunds.exists() else None), 'refund_total_amount': (sum([x.total_amount for x in order.refunds.all()]) if order.refunds.exists() else None), 'sector_name': get_attr_or_none(order, 'sector.name'), 'services': join_attr_values(order.service_types.order_by('name')), 'status': order.status, 'subtotal_cost': order.subtotal_cost, 'total_cost': order.total_cost, 'uk_region__name': order.uk_region.name, 'vat_cost': order.vat_cost, }
def get_expected_data_from_event(event): """Returns event data as a dictionary""" return { 'address_1': event.address_1, 'address_2': event.address_2, 'address_country__name': event.address_country.name, 'address_county': event.address_county, 'address_postcode': event.address_postcode, 'address_town': event.address_town, 'created_by_id': str(event.created_by_id) if event.created_by is not None else None, 'created_on': format_date_or_datetime(event.created_on), 'disabled_on': format_date_or_datetime(event.disabled_on), 'end_date': format_date_or_datetime(event.end_date), 'event_type__name': event.event_type.name, 'id': str(event.id), 'lead_team_id': str(event.lead_team_id), 'location_type__name': event.location_type.name, 'name': event.name, 'notes': event.notes, 'organiser_id': str(event.organiser_id), 'service_name': event.service.name, 'start_date': format_date_or_datetime(event.start_date), 'team_ids': [str(x.id) for x in event.teams.all().order_by('id')], 'uk_region__name': event.uk_region.name, }
def get_expected_data_from_team(team): """Returns team data as a dictionary""" return { 'country__name': team.country.name, 'disabled_on': format_date_or_datetime(team.disabled_on), 'id': str(team.id), 'name': team.name, 'role__name': team.role.name, 'uk_region__name': team.uk_region.name, }
def test_create_first_session(self, requests_mock, public_omis_api_client): """ Test a successful call to create a payment gateway session. This starts a GOV.UK payment and creates an OMIS payment gateway session object tracking it. """ # mock GOV.UK response govuk_payment_id = '123abc123abc123abc123abc12' next_url = 'https://payment.example.com/123abc' json_response = { 'state': {'status': 'created', 'finished': False}, 'payment_id': govuk_payment_id, '_links': { 'next_url': { 'href': next_url, 'method': 'GET', }, }, } requests_mock.post( govuk_url('payments'), # create payment status_code=201, json=json_response, ) requests_mock.get( govuk_url(f'payments/{govuk_payment_id}'), # get payment status_code=200, json=json_response, ) assert PaymentGatewaySession.objects.count() == 0 # make API call order = OrderWithAcceptedQuoteFactory() url = reverse( 'api-v3:public-omis:payment-gateway-session:collection', kwargs={'public_token': order.public_token}, ) response = public_omis_api_client.post(url, json_={}) assert response.status_code == status.HTTP_201_CREATED # check payment gateway session record created assert PaymentGatewaySession.objects.count() == 1 session = PaymentGatewaySession.objects.first() assert session.govuk_payment_id == govuk_payment_id assert session.status == PaymentGatewaySessionStatus.CREATED # check API response assert response.json() == { 'id': str(session.id), 'created_on': format_date_or_datetime(session.created_on), 'status': PaymentGatewaySessionStatus.CREATED, 'payment_url': next_url, }
def test_get(self, order_factory): """Test a successful call to get a invoice.""" order = order_factory() url = reverse( 'api-v3:omis-public:invoice:detail', kwargs={'public_token': order.public_token}, ) client = self.create_api_client( scope=Scope.public_omis_front_end, grant_type=Application.GRANT_CLIENT_CREDENTIALS, ) response = client.get(url) invoice = order.invoice assert response.status_code == status.HTTP_200_OK assert response.json() == { 'created_on': format_date_or_datetime(invoice.created_on), 'invoice_number': invoice.invoice_number, 'invoice_company_name': invoice.invoice_company_name, 'invoice_address_1': invoice.invoice_address_1, 'invoice_address_2': invoice.invoice_address_2, 'invoice_address_county': invoice.invoice_address_county, 'invoice_address_town': invoice.invoice_address_town, 'invoice_address_postcode': invoice.invoice_address_postcode, 'invoice_address_country': { 'id': str(invoice.invoice_address_country.pk), 'name': invoice.invoice_address_country.name, }, 'invoice_vat_number': invoice.invoice_vat_number, 'payment_due_date': invoice.payment_due_date.isoformat(), 'billing_contact_name': invoice.billing_contact_name, 'billing_company_name': invoice.billing_company_name, 'billing_address_1': invoice.billing_address_1, 'billing_address_2': invoice.billing_address_2, 'billing_address_county': invoice.billing_address_county, 'billing_address_postcode': invoice.billing_address_postcode, 'billing_address_town': invoice.billing_address_town, 'billing_address_country': { 'id': str(invoice.billing_address_country.pk), 'name': invoice.billing_address_country.name, }, 'po_number': invoice.po_number, 'vat_status': invoice.vat_status, 'vat_number': invoice.vat_number, 'vat_verified': invoice.vat_verified, 'net_cost': invoice.net_cost, 'subtotal_cost': invoice.subtotal_cost, 'vat_cost': invoice.vat_cost, 'total_cost': invoice.total_cost, }