def test_nested_id_name_dict_returns_none_on_invalid_path(): """Tests nested id name dict raises exception on invalid path. We assume that first part of path exists. """ obj = mock.Mock(company=None) res = dict_utils.computed_nested_id_name_dict('company.sector')(obj) assert res is None
def test_nested_id_name_dict(): """Tests nested id name dict.""" obj = mock.Mock() obj.company.sector.id = 123 obj.company.sector.name = 'Cats' res = dict_utils.computed_nested_id_name_dict('company.sector')(obj) assert res == { 'id': str(obj.company.sector.id), 'name': obj.company.sector.name, }
def test_nested_id_name_dict_raises_exception_on_invalid_argument(): """Tests nested id name dict raises exception on invalid argument.""" obj = mock.Mock() with raises(ValueError): dict_utils.computed_nested_id_name_dict('company')(obj)
def test_nested_id_name_dict(obj, expected_dict): """Tests nested id name dict.""" res = dict_utils.computed_nested_id_name_dict('company.sector')(obj) assert res == expected_dict
class Contact(BaseSearchModel): """OpenSearch representation of Contact model.""" id = Keyword() address_1 = Text() address_2 = Text() address_town = fields.NormalizedKeyword() address_county = fields.NormalizedKeyword() address_postcode = Text() address_country = fields.id_name_field() address_area = fields.id_name_field() address_same_as_company = Boolean() adviser = fields.contact_or_adviser_field() archived = Boolean() archived_by = fields.contact_or_adviser_field() archived_on = Date() archived_reason = Text() company = fields.company_field() company_sector = fields.sector_field() company_uk_region = fields.id_name_field() created_by = fields.contact_or_adviser_field(include_dit_team=True) created_on = Date() email = fields.NormalizedKeyword() first_name = Text(fields={ 'keyword': fields.NormalizedKeyword(), }, ) job_title = Text(fields={ 'keyword': fields.NormalizedKeyword(), 'trigram': fields.TrigramText(), }, ) last_name = Text(fields={ 'keyword': fields.NormalizedKeyword(), }, ) modified_on = Date() name = Text(fields={ 'keyword': fields.NormalizedKeyword(), 'trigram': fields.TrigramText(), }, ) name_with_title = Text(fields={ 'keyword': fields.NormalizedKeyword(), 'trigram': fields.TrigramText(), }, ) notes = fields.EnglishText() primary = Boolean() full_telephone_number = Keyword() title = fields.id_name_field() MAPPINGS = { 'adviser': dict_utils.contact_or_adviser_dict, 'archived_by': dict_utils.contact_or_adviser_dict, 'company': dict_utils.company_dict, 'created_by': dict_utils.adviser_dict_with_team, 'title': dict_utils.id_name_dict, } COMPUTED_MAPPINGS = { 'address_1': contact_dict_utils.computed_address_field('address_1'), 'address_2': contact_dict_utils.computed_address_field('address_2'), 'address_town': contact_dict_utils.computed_address_field('address_town'), 'address_county': contact_dict_utils.computed_address_field('address_county'), 'address_postcode': contact_dict_utils.computed_address_field('address_postcode'), 'address_country': contact_dict_utils.computed_address_field('address_country'), 'address_area': contact_dict_utils.computed_address_field('address_area'), 'company_sector': dict_utils.computed_nested_sector_dict('company.sector'), 'company_uk_region': dict_utils.computed_nested_id_name_dict('company.uk_region'), } SEARCH_FIELDS = ( 'id', 'name', 'name.trigram', 'name_with_title', 'name_with_title.trigram', 'email', 'company.name', 'company.name.trigram', 'job_title', 'job_title.trigram', 'full_telephone_number', )
class InvestmentProject(BaseESModel): """Elasticsearch representation of InvestmentProject.""" id = Keyword() actual_land_date = Date() actual_uk_regions = fields.nested_id_name_field() address_1 = Text() address_2 = Text() address_town = fields.SortableCaseInsensitiveKeywordText() address_postcode = Text() approved_commitment_to_invest = Boolean() approved_fdi = Boolean() approved_good_value = Boolean() approved_high_value = Boolean() approved_landed = Boolean() approved_non_fdi = Boolean() allow_blank_estimated_land_date = Boolean(index=False) allow_blank_possible_uk_regions = Boolean(index=False) anonymous_description = fields.EnglishText() archived = Boolean() archived_by = fields.nested_contact_or_adviser_field('archived_by') archived_on = Date() archived_reason = Text() associated_non_fdi_r_and_d_project = _nested_investment_project_field() average_salary = fields.nested_id_name_field() business_activities = fields.nested_id_name_field() client_cannot_provide_foreign_investment = Boolean() client_cannot_provide_total_investment = Boolean() client_contacts = fields.nested_contact_or_adviser_field('client_contacts') client_relationship_manager = fields.nested_contact_or_adviser_field( 'client_relationship_manager', include_dit_team=True, ) client_requirements = fields.TextWithKeyword() comments = fields.EnglishText() country_lost_to = _country_lost_to_mapping() created_on = Date() created_by = fields.nested_contact_or_adviser_field( 'created_by', include_dit_team=True, ) date_abandoned = Date() date_lost = Date() delivery_partners = fields.nested_id_name_field() description = fields.EnglishText() estimated_land_date = Date() export_revenue = Boolean() fdi_type = fields.nested_id_name_field() fdi_value = fields.nested_id_name_field() foreign_equity_investment = Double() government_assistance = Boolean() intermediate_company = fields.nested_id_name_field() investor_company = fields.nested_id_name_partial_field('investor_company') investor_company_country = fields.nested_id_name_field() investment_type = fields.nested_id_name_field() investor_type = fields.nested_id_name_field() level_of_involvement = fields.nested_id_name_field() likelihood_of_landing = Long() project_assurance_adviser = fields.nested_contact_or_adviser_field( 'project_assurance_adviser', include_dit_team=True, ) project_manager = fields.nested_contact_or_adviser_field( 'project_manager', include_dit_team=True, ) name = fields.SortableText(copy_to=['name_keyword', 'name_trigram']) name_keyword = fields.SortableCaseInsensitiveKeywordText() name_trigram = fields.TrigramText() new_tech_to_uk = Boolean() non_fdi_r_and_d_budget = Boolean() number_new_jobs = Integer() number_safeguarded_jobs = Long() modified_on = Date() project_arrived_in_triage_on = Date() project_code = fields.SortableCaseInsensitiveKeywordText( copy_to='project_code_trigram') project_code_trigram = fields.TrigramText() proposal_deadline = Date() other_business_activity = fields.TextWithKeyword() quotable_as_public_case_study = Boolean() r_and_d_budget = Boolean() reason_abandoned = fields.TextWithKeyword() reason_delayed = fields.TextWithKeyword() reason_lost = fields.TextWithKeyword() referral_source_activity = fields.nested_id_name_field() referral_source_activity_event = fields.SortableCaseInsensitiveKeywordText( ) referral_source_activity_marketing = fields.nested_id_name_field() referral_source_activity_website = fields.nested_id_name_field() referral_source_adviser = _referral_source_adviser_mapping() sector = fields.nested_sector_field() site_decided = Boolean() some_new_jobs = Boolean() specific_programme = fields.nested_id_name_field() stage = fields.nested_id_name_field() status = fields.SortableCaseInsensitiveKeywordText() team_members = fields.nested_contact_or_adviser_field( 'team_members', include_dit_team=True) total_investment = Double() uk_company = fields.nested_id_name_partial_field('uk_company') uk_company_decided = Boolean() uk_region_locations = fields.nested_id_name_field() will_new_jobs_last_two_years = Boolean() MAPPINGS = { 'id': str, 'actual_uk_regions': lambda col: [dict_utils.id_name_dict(c) for c in col.all()], 'archived_by': dict_utils.contact_or_adviser_dict, 'associated_non_fdi_r_and_d_project': dict_utils.investment_project_dict, 'average_salary': dict_utils.id_name_dict, 'business_activities': lambda col: [dict_utils.id_name_dict(c) for c in col.all()], 'client_contacts': lambda col: [dict_utils.contact_or_adviser_dict(c) for c in col.all()], 'client_relationship_manager': dict_utils.adviser_dict_with_team, 'country_lost_to': dict_utils.id_name_dict, 'created_by': dict_utils.adviser_dict_with_team, 'delivery_partners': lambda col: [dict_utils.id_name_dict(c) for c in col.all()], 'fdi_type': dict_utils.id_name_dict, 'fdi_value': dict_utils.id_name_dict, 'intermediate_company': dict_utils.id_name_dict, 'investment_type': dict_utils.id_name_dict, 'investor_company': dict_utils.id_name_dict, 'investor_type': dict_utils.id_name_dict, 'level_of_involvement': dict_utils.id_name_dict, 'project_assurance_adviser': dict_utils.adviser_dict_with_team, 'project_code': str, 'project_manager': dict_utils.adviser_dict_with_team, 'referral_source_activity': dict_utils.id_name_dict, 'referral_source_activity_marketing': dict_utils.id_name_dict, 'referral_source_activity_website': dict_utils.id_name_dict, 'referral_source_adviser': dict_utils.contact_or_adviser_dict, 'sector': dict_utils.sector_dict, 'specific_programme': dict_utils.id_name_dict, 'stage': dict_utils.id_name_dict, 'team_members': lambda col: [ dict_utils.contact_or_adviser_dict(c.adviser, include_dit_team=True) for c in col.all() ], 'uk_company': dict_utils.id_name_dict, 'uk_region_locations': lambda col: [dict_utils.id_name_dict(c) for c in col.all()], } COMPUTED_MAPPINGS = { 'investor_company_country': dict_utils.computed_nested_id_name_dict( 'investor_company.registered_address_country', ), } SEARCH_FIELDS = ( 'name', 'name_trigram', 'uk_company.name', 'uk_company.name_trigram', 'investor_company.name', 'investor_company.name_trigram', 'project_code_trigram', ) class Meta: """Default document meta data.""" doc_type = 'investment_project'
class Contact(BaseESModel): """Elasticsearch representation of Contact model.""" id = Keyword() address_1 = Text() address_2 = Text() address_town = fields.NormalizedKeyword() address_county = fields.NormalizedKeyword() address_postcode = Text() address_country = fields.id_name_field() address_same_as_company = Boolean() adviser = fields.contact_or_adviser_field() archived = Boolean() archived_by = fields.contact_or_adviser_field() archived_on = Date() archived_reason = Text() company = fields.company_field() company_sector = fields.sector_field() company_uk_region = fields.id_name_field() created_by = fields.contact_or_adviser_field(include_dit_team=True) created_on = Date() email = fields.NormalizedKeyword() email_alternative = Text() first_name = Text(fields={ 'keyword': fields.NormalizedKeyword(), }, ) job_title = fields.NormalizedKeyword() last_name = Text(fields={ 'keyword': fields.NormalizedKeyword(), }, ) modified_on = Date() name = Text(fields={ 'keyword': fields.NormalizedKeyword(), 'trigram': fields.TrigramText(), }, ) notes = fields.EnglishText() primary = Boolean() telephone_alternative = Text() telephone_countrycode = Keyword() telephone_number = Keyword() title = fields.id_name_field() MAPPINGS = { 'adviser': dict_utils.contact_or_adviser_dict, 'archived_by': dict_utils.contact_or_adviser_dict, 'company': dict_utils.company_dict, 'created_by': dict_utils.adviser_dict_with_team, 'title': dict_utils.id_name_dict, } COMPUTED_MAPPINGS = { 'address_1': contact_dict_utils.computed_address_field('address_1'), 'address_2': contact_dict_utils.computed_address_field('address_2'), 'address_town': contact_dict_utils.computed_address_field('address_town'), 'address_county': contact_dict_utils.computed_address_field('address_county'), 'address_postcode': contact_dict_utils.computed_address_field('address_postcode'), 'address_country': contact_dict_utils.computed_address_field('address_country'), 'company_sector': dict_utils.computed_nested_sector_dict('company.sector'), 'company_uk_region': dict_utils.computed_nested_id_name_dict('company.uk_region'), } SEARCH_FIELDS = ( 'id', 'name', 'name.trigram', 'email', 'email_alternative', 'company.name', 'company.name.trigram', ) class Meta: """Default document meta data.""" doc_type = DEFAULT_MAPPING_TYPE class Index: doc_type = DEFAULT_MAPPING_TYPE
class Contact(BaseESModel): """Elasticsearch representation of Contact model.""" id = Keyword() accepts_dit_email_marketing = Boolean() address_1 = Text() address_2 = Text() address_town = fields.SortableCaseInsensitiveKeywordText() address_county = fields.SortableCaseInsensitiveKeywordText() address_postcode = Text() address_country = fields.nested_id_name_field() address_same_as_company = Boolean() adviser = fields.nested_contact_or_adviser_field('adviser') archived = Boolean() archived_by = fields.nested_contact_or_adviser_field('archived_by') archived_on = Date() archived_reason = Text() company = fields.nested_company_field('company') company_sector = fields.nested_sector_field() company_uk_region = fields.nested_id_name_field() created_by = fields.nested_contact_or_adviser_field('created_by', include_dit_team=True) created_on = Date() email = fields.SortableCaseInsensitiveKeywordText() email_alternative = Text() first_name = fields.SortableText( copy_to=[ 'name', 'name_keyword', 'name_trigram', ], ) job_title = fields.SortableCaseInsensitiveKeywordText() last_name = fields.SortableText( copy_to=[ 'name', 'name_keyword', 'name_trigram', ], ) modified_on = Date() name = fields.SortableText() name_keyword = fields.SortableCaseInsensitiveKeywordText() # field is being aggregated name_trigram = fields.TrigramText() notes = fields.EnglishText() primary = Boolean() telephone_alternative = Text() telephone_countrycode = Keyword() telephone_number = Keyword() title = fields.nested_id_name_field() MAPPINGS = { 'id': str, 'adviser': dict_utils.contact_or_adviser_dict, 'archived_by': dict_utils.contact_or_adviser_dict, 'company': dict_utils.company_dict, 'created_by': dict_utils.adviser_dict_with_team, 'title': dict_utils.id_name_dict, } COMPUTED_MAPPINGS = { 'address_1': contact_dict_utils.computed_address_field('address_1'), 'address_2': contact_dict_utils.computed_address_field('address_2'), 'address_town': contact_dict_utils.computed_address_field('address_town'), 'address_county': contact_dict_utils.computed_address_field('address_county'), 'address_postcode': contact_dict_utils.computed_address_field('address_postcode'), 'address_country': contact_dict_utils.computed_address_field('address_country'), 'company_sector': dict_utils.computed_nested_sector_dict('company.sector'), 'company_uk_region': dict_utils.computed_nested_id_name_dict('company.uk_region'), } SEARCH_FIELDS = ( 'name', 'name_trigram', 'email', 'email_alternative', 'company.name', 'company.name_trigram', ) class Meta: """Default document meta data.""" doc_type = 'contact'