def test_company_get_suggestions( self, name, trading_names, archived, registered_address_country, expected_input_suggestions, expected_contexts, ): """Test get an autocomplete search suggestions for a company""" db_company = CompanyFactory( name=name, trading_names=trading_names, archived=archived, registered_address_country_id=registered_address_country, address_country_id=CountryConstant.united_kingdom.value.id, ) result = get_suggestions(db_company) if result: assert Counter( result['input']) == Counter(expected_input_suggestions) assert 'country' in result['contexts'] assert Counter( result['contexts']['country']) == Counter(expected_contexts) else: assert Counter(result) == Counter(expected_input_suggestions)
def test_company_get_suggestions( self, name, trading_names, archived, expected_suggestions, ): """Test get an autocomplete search suggestions for a company""" db_company = CompanyFactory( name=name, trading_names=trading_names, archived=archived, ) result = get_suggestions(db_company) assert Counter(result) == Counter(expected_suggestions)
def test_response_body(self, es_with_collector): """Tests the response body of a search query.""" one_list_account_owner = AdviserFactory() company = CompanyFactory( company_number='123', trading_names=['Xyz trading', 'Abc trading'], global_headquarters=None, one_list_tier=None, one_list_account_owner=one_list_account_owner, ) es_with_collector.flush_and_refresh() url = reverse('api-v4:search:company') response = self.api_client.post(url) assert response.status_code == status.HTTP_200_OK assert response.json() == { 'count': 1, 'results': [ { 'id': str(company.pk), 'created_on': company.created_on.isoformat(), 'modified_on': company.modified_on.isoformat(), 'name': company.name, 'reference_code': company.reference_code, 'company_number': company.company_number, 'vat_number': company.vat_number, 'duns_number': company.duns_number, 'trading_names': company.trading_names, 'address': { 'line_1': company.address_1, 'line_2': company.address_2 or '', 'town': company.address_town, 'county': company.address_county or '', 'postcode': company.address_postcode or '', 'country': { 'id': str(company.address_country.id), 'name': company.address_country.name, }, }, 'registered_address': { 'line_1': company.registered_address_1, 'line_2': company.registered_address_2 or '', 'town': company.registered_address_town, 'county': company.registered_address_county or '', 'postcode': company.registered_address_postcode or '', 'country': { 'id': str(company.registered_address_country.id), 'name': company.registered_address_country.name, }, }, 'one_list_group_global_account_manager': { 'id': str(one_list_account_owner.id), 'first_name': one_list_account_owner.first_name, 'last_name': one_list_account_owner.last_name, 'name': one_list_account_owner.name, }, 'uk_based': (company.address_country.id == uuid.UUID( constants.Country.united_kingdom.value.id, )), 'uk_region': { 'id': str(company.uk_region.id), 'name': company.uk_region.name, }, 'business_type': { 'id': str(company.business_type.id), 'name': company.business_type.name, }, 'description': company.description, 'employee_range': { 'id': str(company.employee_range.id), 'name': company.employee_range.name, }, 'export_experience_category': { 'id': str(company.export_experience_category.id), 'name': company.export_experience_category.name, }, 'export_to_countries': [], 'future_interest_countries': [], 'headquarter_type': company.headquarter_type, 'sector': { 'id': str(company.sector.id), 'name': company.sector.name, 'ancestors': [{ 'id': str(ancestor.id) } for ancestor in company.sector.get_ancestors()], }, 'turnover_range': { 'id': str(company.turnover_range.id), 'name': company.turnover_range.name, }, 'website': company.website, 'global_headquarters': None, 'archived': False, 'archived_by': None, 'archived_on': None, 'archived_reason': None, 'suggest': get_suggestions(company), 'latest_interaction_date': None, }, ], }
def test_response_body(self, setup_es): """Tests the response body of a search query.""" ch_company = CompaniesHouseCompanyFactory(company_number='123', ) company = CompanyFactory( company_number='123', trading_names=['Xyz trading', 'Abc trading'], global_headquarters=None, one_list_tier=None, one_list_account_owner=None, ) setup_es.indices.refresh() url = reverse('api-v3:search:company') response = self.api_client.post(url) assert response.status_code == status.HTTP_200_OK assert response.json() == { 'count': 1, 'results': [ { 'id': str(company.pk), 'companies_house_data': { 'id': str(ch_company.id), 'company_number': ch_company.company_number, }, 'created_on': company.created_on.isoformat(), 'modified_on': company.modified_on.isoformat(), 'name': company.name, 'reference_code': company.reference_code, 'company_number': company.company_number, 'vat_number': company.vat_number, 'duns_number': company.duns_number, 'trading_names': company.trading_names, 'registered_address_1': company.registered_address_1, 'registered_address_2': company.registered_address_2, 'registered_address_town': company.registered_address_town, 'registered_address_county': company.registered_address_county, 'registered_address_postcode': company.registered_address_postcode, 'registered_address_country': { 'id': str(Country.united_kingdom.value.id), 'name': Country.united_kingdom.value.name, }, 'trading_address_1': company.trading_address_1, 'trading_address_2': company.trading_address_2, 'trading_address_country': { 'id': str(company.trading_address_country.id), 'name': company.trading_address_country.name, }, 'trading_address_county': company.trading_address_county, 'trading_address_postcode': company.trading_address_postcode, 'trading_address_town': company.trading_address_town, 'uk_based': (company.address_country.id == uuid.UUID( Country.united_kingdom.value.id)), 'uk_region': { 'id': str(company.uk_region.id), 'name': company.uk_region.name, }, 'business_type': { 'id': str(company.business_type.id), 'name': company.business_type.name, }, 'description': company.description, 'employee_range': { 'id': str(company.employee_range.id), 'name': company.employee_range.name, }, 'export_experience_category': { 'id': str(company.export_experience_category.id), 'name': company.export_experience_category.name, }, 'export_to_countries': [], 'future_interest_countries': [], 'headquarter_type': company.headquarter_type, 'sector': { 'id': str(company.sector.id), 'name': company.sector.name, 'ancestors': [{ 'id': str(ancestor.id) } for ancestor in company.sector.get_ancestors()], }, 'turnover_range': { 'id': str(company.turnover_range.id), 'name': company.turnover_range.name, }, 'website': company.website, 'global_headquarters': None, 'archived': False, 'archived_by': None, 'archived_on': None, 'archived_reason': None, 'suggest': get_suggestions(company), }, ], }