コード例 #1
0
def test_interactions_to_es_documents(setup_es):
    """Test converting 2 orders to Elasticsearch documents."""
    interactions = CompanyInteractionFactory.create_batch(2)

    result = Interaction.db_objects_to_es_documents(interactions)

    assert {item['_id'] for item in result} == {str(item.pk) for item in interactions}
コード例 #2
0
def test_service_delivery_to_dict(setup_es):
    """Test converting an interaction to a dict."""
    interaction = ServiceDeliveryFactory()

    result = Interaction.db_object_to_dict(interaction)

    assert result == {
        'id': str(interaction.pk),
        'kind': interaction.kind,
        'date': interaction.date,
        'company': {
            'id': str(interaction.company.pk),
            'name': interaction.company.name,
            'trading_name': interaction.company.alias,
        },
        'company_sector': {
            'id': str(interaction.company.sector.pk),
            'name': interaction.company.sector.name,
            'ancestors': [{
                'id': str(ancestor.pk),
            } for ancestor in interaction.company.sector.get_ancestors()],
        },
        'contact': {
            'id': str(interaction.contact.pk),
            'first_name': interaction.contact.first_name,
            'name': interaction.contact.name,
            'last_name': interaction.contact.last_name,
        },
        'is_event': interaction.is_event,
        'event': None,
        'service': {
            'id': str(interaction.service.pk),
            'name': interaction.service.name,
        },
        'subject': interaction.subject,
        'dit_adviser': {
            'id': str(interaction.dit_adviser.pk),
            'first_name': interaction.dit_adviser.first_name,
            'name': interaction.dit_adviser.name,
            'last_name': interaction.dit_adviser.last_name,
        },
        'notes': interaction.notes,
        'dit_team': {
            'id': str(interaction.dit_team.pk),
            'name': interaction.dit_team.name,
        },
        'communication_channel': None,
        'investment_project': None,
        'investment_project_sector': None,
        'service_delivery_status': {
            'id': str(interaction.service_delivery_status.pk),
            'name': interaction.service_delivery_status.name,
        },
        'grant_amount_offered': interaction.grant_amount_offered,
        'net_company_receipt': interaction.net_company_receipt,
        'created_on': interaction.created_on,
        'modified_on': interaction.modified_on,
    }
コード例 #3
0
ファイル: test_models.py プロジェクト: uktrade/data-hub-api
def test_interactions_to_documents(opensearch):
    """Test converting 2 orders to OpenSearch documents."""
    interactions = CompanyInteractionFactory.create_batch(2)

    result = Interaction.db_objects_to_documents(interactions)

    assert {item['_id']
            for item in result} == {item.pk
                                    for item in interactions}
コード例 #4
0
def test_interaction_to_dict(setup_es, factory_cls):
    """Test converting an interaction to a dict."""
    interaction = factory_cls()

    result = Interaction.db_object_to_dict(interaction)
    result['contacts'].sort(key=itemgetter('id'))
    result['dit_participants'].sort(
        key=lambda dit_participant: dit_participant['adviser']['id'])
    result['policy_areas'].sort(key=itemgetter('id'))
    result['policy_issue_types'].sort(key=itemgetter('id'))

    assert result == {
        'id':
        interaction.pk,
        'kind':
        interaction.kind,
        'date':
        interaction.date,
        'company': {
            'id': str(interaction.company.pk),
            'name': interaction.company.name,
            'trading_names': interaction.company.trading_names,
        } if interaction.company else None,
        'company_sector': {
            'id':
            str(interaction.company.sector.pk),
            'name':
            interaction.company.sector.name,
            'ancestors': [{
                'id': str(ancestor.pk),
            } for ancestor in interaction.company.sector.get_ancestors()],
        } if interaction.company else None,
        'contacts': [{
            'id': str(obj.pk),
            'first_name': obj.first_name,
            'name': obj.name,
            'last_name': obj.last_name,
        } for obj in sorted(interaction.contacts.all(), key=attrgetter('id'))],
        'is_event':
        interaction.is_event,
        'event':
        None,
        'service': {
            'id': str(interaction.service.pk),
            'name': interaction.service.name,
        },
        'subject':
        interaction.subject,
        'dit_adviser': {
            'id': str(interaction.dit_adviser.pk),
            'first_name': interaction.dit_adviser.first_name,
            'name': interaction.dit_adviser.name,
            'last_name': interaction.dit_adviser.last_name,
        },
        'dit_participants': [{
            'adviser': {
                'id': str(dit_participant.adviser.pk),
                'first_name': dit_participant.adviser.first_name,
                'name': dit_participant.adviser.name,
                'last_name': dit_participant.adviser.last_name,
            },
            'team': {
                'id': str(dit_participant.team.pk),
                'name': dit_participant.team.name,
            },
        } for dit_participant in interaction.dit_participants.order_by(
            'adviser__pk')],
        'notes':
        interaction.notes,
        'dit_team': {
            'id': str(interaction.dit_team.pk),
            'name': interaction.dit_team.name,
        },
        'communication_channel': {
            'id': str(interaction.communication_channel.pk),
            'name': interaction.communication_channel.name,
        },
        'investment_project': {
            'id': str(interaction.investment_project.pk),
            'name': interaction.investment_project.name,
        } if interaction.investment_project else None,
        'investment_project_sector': {
            'id':
            str(interaction.investment_project.sector.pk),
            'name':
            interaction.investment_project.sector.name,
            'ancestors': [{
                'id': str(ancestor.pk),
            } for ancestor in interaction.investment_project.sector.
                          get_ancestors()],
        } if interaction.investment_project else None,
        'policy_areas': [{
            'id': str(obj.pk),
            'name': obj.name,
        } for obj in sorted(interaction.policy_areas.all(),
                            key=attrgetter('id'))],
        'policy_issue_types': [{
            'id': str(obj.pk),
            'name': obj.name,
        } for obj in sorted(interaction.policy_issue_types.all(),
                            key=attrgetter('id'))],
        'service_delivery_status':
        None,
        'grant_amount_offered':
        None,
        'net_company_receipt':
        None,
        'was_policy_feedback_provided':
        interaction.was_policy_feedback_provided,
        'created_on':
        interaction.created_on,
        'modified_on':
        interaction.modified_on,
    }
コード例 #5
0
ファイル: test_models.py プロジェクト: uktrade/data-hub-api
def test_service_delivery_to_dict(opensearch):
    """Test converting an interaction to a dict."""
    interaction = ServiceDeliveryFactory()

    result = Interaction.db_object_to_dict(interaction)
    result['contacts'].sort(key=itemgetter('id'))
    result['companies'].sort(key=itemgetter('id'))
    result['dit_participants'].sort(
        key=lambda dit_participant: dit_participant['adviser']['id'])

    assert result == {
        '_document_type':
        InteractionSearchApp.name,
        'id':
        interaction.pk,
        'kind':
        interaction.kind,
        'date':
        interaction.date,
        'company': {
            'id': str(interaction.company.pk),
            'name': interaction.company.name,
            'trading_names': interaction.company.trading_names,
        },
        'companies': [{
            'id': str(company.pk),
            'name': company.name,
            'trading_names': company.trading_names,
        } for company in sorted(interaction.companies.all(),
                                key=attrgetter('id'))],
        'company_sector': {
            'id':
            str(interaction.company.sector.pk),
            'name':
            interaction.company.sector.name,
            'ancestors': [{
                'id': str(ancestor.pk),
            } for ancestor in interaction.company.sector.get_ancestors()],
        },
        'company_one_list_group_tier': {
            'id': interaction.company.get_one_list_group_tier().pk,
            'name': interaction.company.get_one_list_group_tier().name,
        } if interaction.company.get_one_list_group_tier() else None,
        'contacts': [{
            'id': str(obj.pk),
            'first_name': obj.first_name,
            'name': obj.name,
            'last_name': obj.last_name,
        } for obj in sorted(interaction.contacts.all(), key=attrgetter('id'))],
        'is_event':
        interaction.is_event,
        'event':
        None,
        'service': {
            'id': str(interaction.service.pk),
            'name': interaction.service.name,
        },
        'subject':
        interaction.subject,
        'dit_participants': [{
            'adviser': {
                'id': str(dit_participant.adviser.pk),
                'first_name': dit_participant.adviser.first_name,
                'name': dit_participant.adviser.name,
                'last_name': dit_participant.adviser.last_name,
            },
            'team': {
                'id': str(dit_participant.team.pk),
                'name': dit_participant.team.name,
            },
        } for dit_participant in interaction.dit_participants.order_by(
            'adviser__pk')],
        'notes':
        interaction.notes,
        'communication_channel':
        None,
        'investment_project':
        None,
        'investment_project_sector':
        None,
        'policy_areas': [],
        'policy_issue_types': [],
        'service_delivery_status': {
            'id': str(interaction.service_delivery_status.pk),
            'name': interaction.service_delivery_status.name,
        },
        'grant_amount_offered':
        interaction.grant_amount_offered,
        'net_company_receipt':
        interaction.net_company_receipt,
        'was_policy_feedback_provided':
        interaction.was_policy_feedback_provided,
        'export_countries': [],
        'were_countries_discussed':
        None,
        'created_on':
        interaction.created_on,
        'modified_on':
        interaction.modified_on,
    }