コード例 #1
0
def test_sync_company_with_dnb_all_fields(
    requests_mock,
    dnb_response_uk,
    base_company_dict,
    update_descriptor,
):
    """
    Test the sync_company_with_dnb task when all fields should be synced.
    """
    requests_mock.post(
        DNB_SEARCH_URL,
        json=dnb_response_uk,
    )
    company = CompanyFactory(duns_number='123456789')
    original_company = Company.objects.get(id=company.id)
    task_result = sync_company_with_dnb.apply_async(
        args=[company.id],
        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_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,
        '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]
    expected_update_descriptor = f'celery:sync_company_with_dnb:{task_result.id}'
    if update_descriptor:
        expected_update_descriptor = update_descriptor
    assert version.revision.comment == f'Updated from D&B [{expected_update_descriptor}]'
    assert version.revision.user is None
コード例 #2
0
def test_sync_company_with_dnb_partial_fields(
    requests_mock,
    dnb_response_uk,
    base_company_dict,
):
    """
    Test the sync_company_with_dnb task when only a subset of fields should be synced.
    """
    requests_mock.post(
        DNB_SEARCH_URL,
        json=dnb_response_uk,
    )
    company = CompanyFactory(duns_number='123456789')
    original_company = Company.objects.get(id=company.id)
    task_result = sync_company_with_dnb.apply_async(
        args=[company.id],
        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_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_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,
        '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(),
    }
コード例 #3
0
    def _process_row(self, row, simulate=False, fields=None, **options):
        """Process one single row."""
        self.processed_count += 1
        pk = parse_uuid(row['id'])
        company = Company.objects.get(pk=pk)

        if not company.duns_number:
            raise CompanyNotDunsLinkedError()

        if simulate:
            return

        self._limit_call_rate()

        sync_company_with_dnb.apply_async(
            args=(pk, fields, self.update_descriptor),
            throw=True,
        )
        self.processed_ids.append(pk)
        self.success_count += 1
コード例 #4
0
def test_sync_company_with_dnb_partial_fields(
    requests_mock,
    dnb_response_uk,
):
    """
    Test the sync_company_with_dnb task when only a subset of fields should be synced.
    """
    requests_mock.post(
        DNB_SEARCH_URL,
        json=dnb_response_uk,
    )
    company = CompanyFactory(duns_number='123456789')
    original_company = Company.objects.get(id=company.id)
    task_result = sync_company_with_dnb.apply_async(
        args=[company.id],
        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(),
    }