def test_update_company_from_dnb_data_does_not_exist(dnb_response_uk, caplog): """ Test the update_company_from_dnb_data command when the company does not exist in Data Hub. """ task_result = update_company_from_dnb_data.apply_async(args=[dnb_response_uk['results'][0]]) assert not task_result.successful() assert 'Company matching duns_number was not found' in caplog.text
def test_update_company_from_dnb_data_partial_fields(dnb_response_uk, base_company_dict): """ Test the update_company_from_dnb_data command when a subset of DNB fields are updated. """ company = CompanyFactory(duns_number='123456789') original_company = Company.objects.get(id=company.id) task_result = update_company_from_dnb_data.apply_async( args=[dnb_response_uk['results'][0]], kwargs={'fields_to_update': ['global_ultimate_duns_number']}, ) assert task_result.successful() company.refresh_from_db() assert model_to_dict(company) == { **base_company_dict, 'address_1': original_company.address_1, 'address_2': original_company.address_2, 'address_country': original_company.address_country_id, 'address_county': original_company.address_county, 'address_postcode': original_company.address_postcode, 'address_area': original_company.address_area, 'address_town': original_company.address_town, 'archived_documents_url_path': original_company.archived_documents_url_path, 'business_type': original_company.business_type_id, 'created_by': original_company.created_by_id, 'duns_number': original_company.duns_number, 'employee_range': original_company.employee_range_id, 'export_experience_category': original_company.export_experience_category_id, 'global_ultimate_duns_number': '291332174', 'id': original_company.id, 'is_number_of_employees_estimated': original_company.is_number_of_employees_estimated, 'is_turnover_estimated': original_company.is_turnover_estimated, 'modified_by': original_company.modified_by_id, 'name': original_company.name, 'number_of_employees': original_company.number_of_employees, 'registered_address_1': original_company.registered_address_1, 'registered_address_2': original_company.registered_address_2, 'registered_address_country': original_company.registered_address_country_id, 'registered_address_county': original_company.registered_address_county, 'registered_address_area': original_company.registered_address_area, 'registered_address_postcode': original_company.registered_address_postcode, 'registered_address_town': original_company.registered_address_town, 'sector': original_company.sector_id, 'export_segment': original_company.export_segment, 'export_sub_segment': original_company.export_sub_segment, 'trading_names': original_company.trading_names, 'turnover': original_company.turnover, 'turnover_range': original_company.turnover_range_id, 'uk_region': original_company.uk_region_id, 'website': original_company.website, 'dnb_modified_on': now(), }
def test_update_company_from_dnb_data_fails_validation(dnb_response_uk, caplog): """ Test the update_company_from_dnb_data command when the company data does not pass validation checks. """ CompanyFactory(duns_number='123456789') dnb_response_uk['results'][0]['primary_name'] = 'a' * 9999 task_result = update_company_from_dnb_data.apply_async(args=[dnb_response_uk['results'][0]]) assert not task_result.successful() assert 'Data from D&B did not pass the Data Hub validation checks.' in caplog.text
def test_update_company_from_dnb_data(dnb_response_uk, base_company_dict): """ Test the update_company_from_dnb_data command when all DNB fields are updated. """ company = CompanyFactory(duns_number='123456789') original_company = Company.objects.get(id=company.id) update_descriptor = 'foobar' task_result = update_company_from_dnb_data.apply_async( args=[dnb_response_uk['results'][0]], kwargs={'update_descriptor': update_descriptor}, ) assert task_result.successful() company.refresh_from_db() uk_country = Country.objects.get(iso_alpha2_code='GB') assert model_to_dict_company(company) == { **base_company_dict, 'address_1': 'Unit 10, Ockham Drive', 'address_2': '', 'address_country': uk_country.id, 'address_county': '', 'address_postcode': 'UB6 0F2', 'address_area': None, 'address_town': 'GREENFORD', 'archived_documents_url_path': original_company.archived_documents_url_path, 'business_type': original_company.business_type_id, 'company_number': '01261539', 'created_by': original_company.created_by_id, 'duns_number': '123456789', 'employee_range': original_company.employee_range_id, 'export_experience_category': original_company.export_experience_category_id, 'global_ultimate_duns_number': '291332174', 'id': original_company.id, 'is_number_of_employees_estimated': True, 'modified_by': original_company.modified_by_id, 'name': 'FOO BICYCLE LIMITED', 'number_of_employees': 260, 'sector': original_company.sector_id, 'export_segment': original_company.export_segment, 'export_sub_segment': original_company.export_sub_segment, 'turnover': 50651895, 'turnover_range': original_company.turnover_range_id, 'uk_region': original_company.uk_region_id, 'dnb_modified_on': now(), } versions = list(Version.objects.get_for_object(company)) assert len(versions) == 1 version = versions[0] assert version.revision.comment == f'Updated from D&B [{update_descriptor}]'
def test_update_company_from_dnb_data_partial_fields(dnb_response_uk): """ Test the update_company_from_dnb_data command when a subset of DNB fields are updated. """ company = CompanyFactory(duns_number='123456789') original_company = Company.objects.get(id=company.id) task_result = update_company_from_dnb_data.apply_async( args=[dnb_response_uk['results'][0]], kwargs={'fields_to_update': ['global_ultimate_duns_number']}, ) assert task_result.successful() company.refresh_from_db() assert model_to_dict(company) == { 'address_1': original_company.address_1, 'address_2': original_company.address_2, 'address_country': original_company.address_country_id, 'address_county': original_company.address_county, 'address_postcode': original_company.address_postcode, 'address_town': original_company.address_town, 'archived': original_company.archived, 'archived_by': original_company.archived_by, 'archived_documents_url_path': original_company.archived_documents_url_path, 'archived_on': original_company.archived_on, 'archived_reason': original_company.archived_reason, 'business_type': original_company.business_type_id, 'company_number': original_company.company_number, 'created_by': original_company.created_by_id, 'description': original_company.description, 'dnb_investigation_data': original_company.dnb_investigation_data, 'duns_number': original_company.duns_number, 'employee_range': original_company.employee_range_id, 'export_experience_category': original_company.export_experience_category_id, 'export_potential': original_company.export_potential, 'export_to_countries': [], 'future_interest_countries': [], 'global_headquarters': original_company.global_headquarters, 'global_ultimate_duns_number': '291332174', 'great_profile_status': original_company.great_profile_status, 'headquarter_type': original_company.headquarter_type, 'id': original_company.id, 'is_number_of_employees_estimated': original_company.is_number_of_employees_estimated, 'is_turnover_estimated': original_company.is_turnover_estimated, 'modified_by': original_company.modified_by_id, 'name': original_company.name, 'number_of_employees': original_company.number_of_employees, 'one_list_account_owner': original_company.one_list_account_owner, 'one_list_tier': original_company.one_list_tier, 'pending_dnb_investigation': original_company.pending_dnb_investigation, 'reference_code': original_company.reference_code, 'registered_address_1': original_company.registered_address_1, 'registered_address_2': original_company.registered_address_2, 'registered_address_country': original_company.registered_address_country_id, 'registered_address_county': original_company.registered_address_county, 'registered_address_postcode': original_company.registered_address_postcode, 'registered_address_town': original_company.registered_address_town, 'sector': original_company.sector_id, 'trading_names': original_company.trading_names, 'transfer_reason': original_company.transfer_reason, 'transferred_by': None, 'transferred_on': None, 'transferred_to': None, 'turnover': original_company.turnover, 'turnover_range': original_company.turnover_range_id, 'uk_region': original_company.uk_region_id, 'vat_number': original_company.vat_number, 'website': original_company.website, 'dnb_modified_on': now(), }