コード例 #1
0
ファイル: tasks.py プロジェクト: alixedi/data-hub-api-cd-poc
def update_company_from_dnb_data(dnb_company_data,
                                 fields_to_update=None,
                                 update_descriptor=None):
    """
    Update the company with the latest data from dnb-service. This task should be called
    when some other logic interacts with dnb-service to get the company data as the task itself
    will not interact with dnb-service.
    """
    dnb_company = format_dnb_company(dnb_company_data)
    duns_number = dnb_company['duns_number']
    logger.info(f'Updating company with duns_number: {duns_number}')

    try:
        dh_company = Company.objects.get(duns_number=duns_number)
    except Company.DoesNotExist:
        logger.error(
            'Company matching duns_number was not found',
            extra={
                'duns_number': duns_number,
                'dnb_company': dnb_company,
            },
        )
        raise

    if not update_descriptor:
        update_descriptor = 'celery:company_update'

    update_company_from_dnb(
        dh_company,
        dnb_company,
        fields_to_update=fields_to_update,
        update_descriptor=update_descriptor,
    )
    return str(dh_company.pk)
コード例 #2
0
ファイル: conftest.py プロジェクト: uktrade/data-hub-api
def formatted_dnb_company_area(dnb_response_uk):
    """
    Get formatted DNB company data.
    """
    dnb_response_area = dnb_response_uk['results'][0].copy()
    dnb_response_area.update(
        address_area_abbrev_name=AdministrativeArea.texas.value.area_code,
    )
    return format_dnb_company(dnb_response_area)
コード例 #3
0
 def test_turnover_usd(self, dnb_response_uk):
     """
     Test that the function returns `turnover`
     and `is_turnover_estimated` when `annual_sales`
     are in USD.
     """
     dnb_company = dnb_response_uk['results'][0]
     company = format_dnb_company(dnb_company)
     assert company['turnover'] == dnb_company['annual_sales']
     assert company['is_turnover_estimated'] == dnb_company['is_annual_sales_estimated']
コード例 #4
0
 def test_turnover_non_usd(self, dnb_response_uk):
     """
     Test that the function does not return `turnover`
     and `is_turnover_estimated` when `annual_sales`
     are not in USD.
     """
     dnb_company = dnb_response_uk['results'][0]
     dnb_company['annual_sales_currency'] = 'GBP'
     company = format_dnb_company(dnb_company)
     assert company['turnover'] is None
     assert company['is_turnover_estimated'] is None
コード例 #5
0
ファイル: conftest.py プロジェクト: uktrade/data-hub-api
def formatted_dnb_company(dnb_response_uk):
    """
    Get formatted DNB company data.
    """
    return format_dnb_company(dnb_response_uk['results'][0])