Skip to content

Commit a81f5b9

Browse files
authored
Merge pull request #251 from uktrade/develop
Jankins is fine
2 parents 7206766 + 397056d commit a81f5b9

35 files changed

+833
-427
lines changed

.coveragerc

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ omit =
77
*manage.py
88
*__init__.py
99
*models.py
10+
*apps.py
1011
*core/auth.py
1112
*datahub/core/management/commands/distributed_migrate.py
1213
*loading_scripts/etl/*

config/settings/common.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -29,26 +29,26 @@
2929

3030
# Application definition
3131

32-
DJANGO_APPS = (
32+
DJANGO_APPS = [
3333
'django.contrib.admin',
3434
'django.contrib.auth',
3535
'django.contrib.contenttypes',
3636
'django.contrib.sessions',
3737
'django.contrib.messages',
3838
'django.contrib.staticfiles',
3939
'django.contrib.postgres',
40-
)
40+
]
4141

42-
THIRD_PARTY_APPS = (
42+
THIRD_PARTY_APPS = [
4343
'rest_framework',
4444
'django_extensions',
4545
'reversion',
4646
'oauth2_provider',
4747
'django_filters',
4848
'mptt',
49-
)
49+
]
5050

51-
LOCAL_APPS = (
51+
LOCAL_APPS = [
5252
'datahub.core',
5353
'datahub.company',
5454
'datahub.interaction',
@@ -58,7 +58,7 @@
5858
'datahub.search.apps.SearchConfig',
5959
'datahub.user',
6060
'datahub.korben',
61-
)
61+
]
6262

6363
INSTALLED_APPS = DJANGO_APPS + THIRD_PARTY_APPS + LOCAL_APPS
6464

config/settings/test.py

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import environ
2+
3+
environ.Env.read_env() # reads the .env file
4+
env = environ.Env()
5+
6+
from .common import *
7+
8+
# We need to prevent Django from initialising datahub.search for tests.
9+
INSTALLED_APPS.remove('datahub.search.apps.SearchConfig')
10+
INSTALLED_APPS.append('datahub.search')
11+
12+
ES_INDEX = 'test'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# -*- coding: utf-8 -*-
2+
# Generated by Django 1.11.1 on 2017-06-09 11:03
3+
from __future__ import unicode_literals
4+
5+
from django.db import migrations
6+
7+
8+
class Migration(migrations.Migration):
9+
10+
dependencies = [
11+
('company', '0004_rename_advsor_fkeys_to_adviser'),
12+
]
13+
14+
operations = [
15+
migrations.RemoveField(
16+
model_name='companieshousecompany',
17+
name='registered_address_3',
18+
),
19+
migrations.RemoveField(
20+
model_name='companieshousecompany',
21+
name='registered_address_4',
22+
),
23+
migrations.RemoveField(
24+
model_name='company',
25+
name='lead',
26+
),
27+
migrations.RemoveField(
28+
model_name='company',
29+
name='registered_address_3',
30+
),
31+
migrations.RemoveField(
32+
model_name='company',
33+
name='registered_address_4',
34+
),
35+
migrations.RemoveField(
36+
model_name='company',
37+
name='trading_address_3',
38+
),
39+
migrations.RemoveField(
40+
model_name='company',
41+
name='trading_address_4',
42+
),
43+
migrations.RemoveField(
44+
model_name='contact',
45+
name='address_3',
46+
),
47+
migrations.RemoveField(
48+
model_name='contact',
49+
name='address_4',
50+
),
51+
]

datahub/company/models.py

-12
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
from django.db import models
1010
from django.utils.functional import cached_property
1111
from django.utils.timezone import now
12-
1312
from mptt.models import MPTTModel, TreeForeignKey
1413

1514
from datahub.company.validators import RelaxedURLValidator
@@ -26,8 +25,6 @@ class CompanyAbstract(BaseModel):
2625
name = models.CharField(max_length=MAX_LENGTH)
2726
registered_address_1 = models.CharField(max_length=MAX_LENGTH)
2827
registered_address_2 = models.CharField(max_length=MAX_LENGTH, blank=True, null=True)
29-
registered_address_3 = models.CharField(max_length=MAX_LENGTH, blank=True, null=True)
30-
registered_address_4 = models.CharField(max_length=MAX_LENGTH, blank=True, null=True)
3128
registered_address_town = models.CharField(max_length=MAX_LENGTH)
3229
registered_address_county = models.CharField(max_length=MAX_LENGTH, blank=True, null=True)
3330
registered_address_country = models.ForeignKey(
@@ -93,7 +90,6 @@ class Company(MPTTModel, ArchivableModel, CompanyAbstract):
9390
blank=True,
9491
related_name='company_future_interest_countries'
9592
)
96-
lead = models.BooleanField(default=False)
9793
description = models.TextField(blank=True, null=True)
9894
website = models.CharField(max_length=MAX_LENGTH, validators=[RelaxedURLValidator], blank=True, null=True)
9995
uk_region = models.ForeignKey(
@@ -102,8 +98,6 @@ class Company(MPTTModel, ArchivableModel, CompanyAbstract):
10298
)
10399
trading_address_1 = models.CharField(max_length=MAX_LENGTH, blank=True, null=True)
104100
trading_address_2 = models.CharField(max_length=MAX_LENGTH, blank=True, null=True)
105-
trading_address_3 = models.CharField(max_length=MAX_LENGTH, blank=True, null=True)
106-
trading_address_4 = models.CharField(max_length=MAX_LENGTH, blank=True, null=True)
107101
trading_address_town = models.CharField(max_length=MAX_LENGTH, blank=True, null=True)
108102
trading_address_county = models.CharField(max_length=MAX_LENGTH, blank=True, null=True)
109103
trading_address_country = models.ForeignKey(
@@ -162,8 +156,6 @@ def _validate_trading_address(self):
162156
any_trading_address_fields = any((
163157
self.trading_address_1,
164158
self.trading_address_2,
165-
self.trading_address_3,
166-
self.trading_address_4,
167159
self.trading_address_town,
168160
self.trading_address_county,
169161
self.trading_address_postcode,
@@ -251,8 +243,6 @@ class Contact(ArchivableModel, BaseModel):
251243
address_same_as_company = models.BooleanField(default=False)
252244
address_1 = models.CharField(max_length=MAX_LENGTH, blank=True, null=True)
253245
address_2 = models.CharField(max_length=MAX_LENGTH, blank=True, null=True)
254-
address_3 = models.CharField(max_length=MAX_LENGTH, blank=True, null=True)
255-
address_4 = models.CharField(max_length=MAX_LENGTH, blank=True, null=True)
256246
address_town = models.CharField(max_length=MAX_LENGTH, blank=True, null=True)
257247
address_county = models.CharField(max_length=MAX_LENGTH, blank=True, null=True)
258248
address_country = models.ForeignKey(
@@ -298,8 +288,6 @@ def validate_address(self):
298288
some_address_fields_existence = any((
299289
self.address_1,
300290
self.address_2,
301-
self.address_3,
302-
self.address_4,
303291
self.address_town,
304292
self.address_county,
305293
self.address_postcode,

datahub/company/serializers.py

+30-17
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,6 @@ class CompanySerializerRead(serializers.ModelSerializer):
6161
account_manager = AdviserSerializer()
6262
registered_address_1 = serializers.SerializerMethodField()
6363
registered_address_2 = serializers.SerializerMethodField()
64-
registered_address_3 = serializers.SerializerMethodField()
65-
registered_address_4 = serializers.SerializerMethodField()
6664
registered_address_town = serializers.SerializerMethodField()
6765
registered_address_country = serializers.SerializerMethodField()
6866
registered_address_county = serializers.SerializerMethodField()
@@ -92,14 +90,6 @@ def get_registered_address_2(self, obj):
9290
"""Return CH address if present."""
9391
return self._address_partial(obj, 'registered_address_2')
9492

95-
def get_registered_address_3(self, obj):
96-
"""Return CH address if present."""
97-
return self._address_partial(obj, 'registered_address_3')
98-
99-
def get_registered_address_4(self, obj):
100-
"""Return CH address if present."""
101-
return self._address_partial(obj, 'registered_address_4')
102-
10393
@staticmethod
10494
def get_registered_address_country(obj):
10595
"""Return CH address if present."""
@@ -159,11 +149,34 @@ class ContactSerializer(serializers.ModelSerializer):
159149
class Meta: # noqa: D101
160150
model = Contact
161151
fields = (
162-
'id', 'title', 'first_name', 'last_name', 'job_title', 'company', 'adviser',
163-
'primary', 'telephone_countrycode', 'telephone_number', 'email',
164-
'address_same_as_company', 'address_1', 'address_2', 'address_3', 'address_4',
165-
'address_town', 'address_county', 'address_country', 'address_postcode',
166-
'telephone_alternative', 'email_alternative', 'notes', 'contactable_by_dit',
167-
'contactable_by_dit_partners', 'contactable_by_email', 'contactable_by_phone',
168-
'archived', 'archived_on', 'archived_reason', 'archived_by', 'created_on'
152+
'id',
153+
'title',
154+
'first_name',
155+
'last_name',
156+
'job_title',
157+
'company',
158+
'adviser',
159+
'primary',
160+
'telephone_countrycode',
161+
'telephone_number',
162+
'email',
163+
'address_same_as_company',
164+
'address_1',
165+
'address_2',
166+
'address_town',
167+
'address_county',
168+
'address_country',
169+
'address_postcode',
170+
'telephone_alternative',
171+
'email_alternative',
172+
'notes',
173+
'contactable_by_dit',
174+
'contactable_by_dit_partners',
175+
'contactable_by_email',
176+
'contactable_by_phone',
177+
'archived',
178+
'archived_on',
179+
'archived_reason',
180+
'archived_by',
181+
'created_on'
169182
)

datahub/company/test/test_company_views.py

-4
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,6 @@ def test_detail_company_with_company_number(self):
5050
assert response.data['trading_name'] == company.alias
5151
assert response.data['registered_address_1'] == ch_company.registered_address_1
5252
assert response.data['registered_address_2'] is None
53-
assert response.data['registered_address_3'] is None
54-
assert response.data['registered_address_4'] is None
5553
assert response.data['registered_address_town'] == ch_company.registered_address_town
5654
assert response.data['registered_address_country'] == {
5755
'name': ch_company.registered_address_country.name,
@@ -83,8 +81,6 @@ def test_detail_company_without_company_number(self):
8381
assert response.data['name'] == company.name
8482
assert response.data['registered_address_1'] == company.registered_address_1
8583
assert response.data['registered_address_2'] is None
86-
assert response.data['registered_address_3'] is None
87-
assert response.data['registered_address_4'] is None
8884
assert response.data['registered_address_town'] == company.registered_address_town
8985
assert response.data['registered_address_country'] == {
9086
'name': company.registered_address_country.name,

datahub/company/test/test_contact_views.py

+16-21
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,6 @@ def test_with_manual_address(self):
3939
'address_same_as_company': False,
4040
'address_1': 'Foo st.',
4141
'address_2': 'adr 2',
42-
'address_3': 'adr 3',
43-
'address_4': 'adr 4',
4442
'address_town': 'London',
4543
'address_county': 'London',
4644
'address_country': {
@@ -82,8 +80,6 @@ def test_with_manual_address(self):
8280
'address_same_as_company': False,
8381
'address_1': 'Foo st.',
8482
'address_2': 'adr 2',
85-
'address_3': 'adr 3',
86-
'address_4': 'adr 4',
8783
'address_town': 'London',
8884
'address_county': 'London',
8985
'address_country': {
@@ -125,8 +121,6 @@ def test_with_address_same_as_company(self):
125121
assert response_data['address_same_as_company']
126122
assert not response_data['address_1']
127123
assert not response_data['address_2']
128-
assert not response_data['address_3']
129-
assert not response_data['address_4']
130124
assert not response_data['address_country']
131125
assert not response_data['address_county']
132126
assert not response_data['address_postcode']
@@ -156,8 +150,6 @@ def test_defaults(self):
156150
assert not response_data['email_alternative']
157151
assert not response_data['address_1']
158152
assert not response_data['address_2']
159-
assert not response_data['address_3']
160-
assert not response_data['address_4']
161153
assert not response_data['address_town']
162154
assert not response_data['address_county']
163155
assert not response_data['address_country']
@@ -205,7 +197,7 @@ def test_fails_without_address(self):
205197
}, format='json')
206198

207199
assert response.status_code == status.HTTP_400_BAD_REQUEST
208-
assert response.data['errors'] == {
200+
assert response.data == {
209201
'address_same_as_company': ['Please select either address_same_as_company or enter an address manually.']
210202
}
211203

@@ -226,7 +218,7 @@ def test_fails_with_only_partial_manual_address(self):
226218
}, format='json')
227219

228220
assert response.status_code == status.HTTP_400_BAD_REQUEST
229-
assert response.data['errors'] == {
221+
assert response.data == {
230222
'address_country': ['This field may not be null.'],
231223
'address_town': ['This field may not be null.']
232224
}
@@ -250,7 +242,7 @@ def test_fails_with_contact_preferences_not_set(self):
250242
}, format='json')
251243

252244
assert response.status_code == status.HTTP_400_BAD_REQUEST
253-
assert response.data['errors'] == {
245+
assert response.data == {
254246
'contactable_by_email': [
255247
'A contact should have at least one way of being contacted. '
256248
'Please select either email or phone, or both'
@@ -286,8 +278,6 @@ def test_patch(self):
286278
address_same_as_company=False,
287279
address_1='Foo st.',
288280
address_2='adr 2',
289-
address_3='adr 3',
290-
address_4='adr 4',
291281
address_town='London',
292282
address_county='London',
293283
address_country_id=constants.Country.united_kingdom.value.id,
@@ -332,8 +322,6 @@ def test_patch(self):
332322
'address_same_as_company': False,
333323
'address_1': 'Foo st.',
334324
'address_2': 'adr 2',
335-
'address_3': 'adr 3',
336-
'address_4': 'adr 4',
337325
'address_town': 'London',
338326
'address_county': 'London',
339327
'address_country': {
@@ -387,8 +375,8 @@ def test_archive_with_reason(self):
387375
assert response.data['archived_reason'] == 'foo'
388376
assert response.data['id'] == contact.pk
389377

390-
def test_unarchive(self):
391-
"""Test unarchive contact."""
378+
def test_unarchive_get(self):
379+
"""Test unarchiving a contact using GET."""
392380
contact = ContactFactory(archived=True, archived_reason='foo')
393381
url = reverse('api-v3:contact:unarchive', kwargs={'pk': contact.pk})
394382
response = self.api_client.get(url)
@@ -398,6 +386,17 @@ def test_unarchive(self):
398386
assert response.data['archived_reason'] == ''
399387
assert response.data['id'] == contact.pk
400388

389+
def test_unarchive_post(self):
390+
"""Test unarchiving a contact using POST."""
391+
contact = ContactFactory(archived=True, archived_reason='foo')
392+
url = reverse('api-v3:contact:unarchive', kwargs={'pk': contact.pk})
393+
response = self.api_client.post(url)
394+
395+
assert not response.data['archived']
396+
assert not response.data['archived_by']
397+
assert response.data['archived_reason'] == ''
398+
assert response.data['id'] == contact.pk
399+
401400

402401
class ViewContactTestCase(LeelooTestCase):
403402
"""View contact test case."""
@@ -423,8 +422,6 @@ def test_view(self):
423422
address_same_as_company=False,
424423
address_1='Foo st.',
425424
address_2='adr 2',
426-
address_3='adr 3',
427-
address_4='adr 4',
428425
address_town='London',
429426
address_county='London',
430427
address_country_id=constants.Country.united_kingdom.value.id,
@@ -466,8 +463,6 @@ def test_view(self):
466463
'address_same_as_company': False,
467464
'address_1': 'Foo st.',
468465
'address_2': 'adr 2',
469-
'address_3': 'adr 3',
470-
'address_4': 'adr 4',
471466
'address_town': 'London',
472467
'address_county': 'London',
473468
'address_country': {

0 commit comments

Comments
 (0)