Skip to content

Commit

Permalink
Merge pull request #677 from uktrade/release/v0.3.1
Browse files Browse the repository at this point in the history
Release v0.3.1
  • Loading branch information
marcofucci authored Nov 27, 2017
2 parents 054ce3f + 13118e6 commit df7b63b
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 4 deletions.
3 changes: 2 additions & 1 deletion datahub/search/contact/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,15 @@ class Contact(DocType, MapDBModelToDict):
company = dsl_utils.id_name_partial_mapping('company')
company_sector = dsl_utils.id_name_mapping()
company_uk_region = dsl_utils.id_name_mapping()
created_by = dsl_utils.contact_or_adviser_mapping('created_by')

MAPPINGS = {
'id': str,
'title': dict_utils.id_name_dict,
'adviser': dict_utils.contact_or_adviser_dict,
'company': dict_utils.id_name_dict,
'archived_by': dict_utils.contact_or_adviser_dict,
'created_by': dict_utils.contact_or_adviser_dict,
}

COMPUTED_MAPPINGS = {
Expand All @@ -80,7 +82,6 @@ class Contact(DocType, MapDBModelToDict):
}

IGNORED_FIELDS = (
'created_by',
'interactions',
'investment_projects',
'modified_by',
Expand Down
1 change: 1 addition & 0 deletions datahub/search/contact/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class SearchContactSerializer(SearchSerializer):
company_sector = SingleOrListField(child=StringUUIDField(), required=False)
company_uk_region = SingleOrListField(child=StringUUIDField(), required=False)
address_country = SingleOrListField(child=StringUUIDField(), required=False)
created_by = SingleOrListField(child=StringUUIDField(), required=False)

SORT_BY_FIELDS = (
'address_country.name',
Expand Down
1 change: 1 addition & 0 deletions datahub/search/contact/test/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ def test_contact_dbmodel_to_dict(setup_es):
'title',
'company',
'created_on',
'created_by',
'modified_on',
'archived',
'archived_on',
Expand Down
20 changes: 19 additions & 1 deletion datahub/search/contact/test/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from rest_framework import status
from rest_framework.reverse import reverse

from datahub.company.test.factories import CompanyFactory, ContactFactory
from datahub.company.test.factories import AdviserFactory, CompanyFactory, ContactFactory
from datahub.core.constants import Country, Sector, UKRegion
from datahub.core.test_utils import APITestMixin, get_test_user
from datahub.metadata.test.factories import TeamFactory
Expand Down Expand Up @@ -198,6 +198,24 @@ def test_search_contact_by_company_id(self, setup_es, setup_data):
assert len(response.data['results']) == 1
assert response.data['results'][0]['company']['id'] == str(company.id)

def test_search_contact_by_created_by(self, setup_es, setup_data):
"""Tests filtering by created_by."""
adviser = AdviserFactory()
ContactFactory(created_by=adviser)

setup_es.indices.refresh()

url = reverse('api-v3:search:contact')

response = self.api_client.post(url, {
'created_by': adviser.id,
})

assert response.status_code == status.HTTP_200_OK
assert response.data['count'] == 1
assert len(response.data['results']) == 1
assert response.data['results'][0]['created_by']['id'] == str(adviser.id)

def test_company_name_trigram_filter(self, setup_es):
"""Tests edge case of partially matching company name."""
company = CompanyFactory(name='United States')
Expand Down
2 changes: 2 additions & 0 deletions datahub/search/contact/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class SearchContactParams:
'company_name',
'company_sector',
'company_uk_region',
'created_by',
'address_country',
'archived',
)
Expand All @@ -28,6 +29,7 @@ class SearchContactParams:
'company_sector': 'company_sector.id',
'company_uk_region': 'company_uk_region.id',
'address_country': 'address_country.id',
'created_by': 'created_by.id',
}


Expand Down
8 changes: 6 additions & 2 deletions fixtures/test_data.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@
contactable_by_phone: true
notes: This is a dummy contact for testing
modified_on: '2017-06-05T00:00:00Z'
archived_documents_url_path: '/documents/123'

- model: company.contact
pk: 952232d2-1d25-4c3a-bcac-2f3a30a94da9
Expand Down Expand Up @@ -225,7 +226,7 @@
contactable_by_phone: true
notes: This is a dummy contact for testing
modified_on: '2017-04-05T00:00:00Z'

- model: company.contact
pk: 6791d583-7a52-418f-a0d3-d8d527f20d43
fields:
Expand All @@ -248,7 +249,7 @@
contactable_by_phone: true
notes: This is a dummy contact for testing
modified_on: '2016-04-05T00:00:00Z'

- model: company.contact
pk: 7d43f9a2-868f-4d85-8e5f-631e5a8c9a3b
fields:
Expand Down Expand Up @@ -335,6 +336,7 @@
investment_project: ~
created_by: e83a608e-84a4-11e6-ae22-56b6b6499611
modified_by: e83a608e-84a4-11e6-ae22-56b6b6499611
archived_documents_url_path: '/documents/123'

- model: investment.investmentproject
pk: 721e2a04-21c3-4172-a321-4368463a4b2d
Expand Down Expand Up @@ -407,6 +409,7 @@
sector: 034be3be-5329-e511-b6bc-e4115bead28a
business_activities:
- a2dbd807-ae52-421c-8d1d-88adfc7a506b
archived_documents_url_path: '/documents/123'

- model: investment.investmentproject
pk: 18750b26-a8c3-41b2-8d3a-fb0b930c2270
Expand Down Expand Up @@ -739,3 +742,4 @@
related_programmes:
- d352a68f-aaf4-4c43-b39d-9bca67a8322e
service: ccf9b82b-3499-e211-a939-e4115bead28a
archived_documents_url_path: '/documents/123'

0 comments on commit df7b63b

Please sign in to comment.