|
1 |
| -from uuid import uuid4 |
2 |
| - |
3 | 1 | import pytest
|
4 | 2 | from django.contrib.admin import site
|
5 |
| -from django.contrib.admin.templatetags.admin_urls import admin_urlname |
6 |
| -from django.urls import reverse |
7 |
| -from rest_framework import status |
8 | 3 |
|
9 |
| -from datahub.company.test.factories import CompanyFactory, ContactFactory |
10 |
| -from datahub.core.admin import get_change_url |
11 |
| -from datahub.core.test_utils import AdminTestMixin, random_obj_for_model |
| 4 | +from datahub.company.test.factories import ContactFactory |
| 5 | +from datahub.core.test_utils import AdminTestMixin |
12 | 6 | from datahub.interaction.admin import InteractionAdmin
|
13 |
| -from datahub.interaction.models import CommunicationChannel, Interaction |
| 7 | +from datahub.interaction.models import Interaction |
14 | 8 | from datahub.interaction.test.factories import CompanyInteractionFactory
|
15 |
| -from datahub.metadata.models import Service, Team |
16 |
| - |
17 |
| - |
18 |
| -class TestInteractionAdminContacts(AdminTestMixin): |
19 |
| - """ |
20 |
| - Tests for the contacts and contact logic in interaction admin. |
21 |
| -
|
22 |
| - TODO: The app and update tests will be removed once the migration from contact to |
23 |
| - contacts is complete. |
24 |
| - """ |
25 |
| - |
26 |
| - def test_add(self): |
27 |
| - """Test that adding an interaction also sets the contact field.""" |
28 |
| - company = CompanyFactory() |
29 |
| - contacts = ContactFactory.create_batch(2, company=company) |
30 |
| - communication_channel = random_obj_for_model(CommunicationChannel) |
31 |
| - |
32 |
| - url = reverse(admin_urlname(Interaction._meta, 'add')) |
33 |
| - data = { |
34 |
| - 'id': uuid4(), |
35 |
| - 'kind': Interaction.KINDS.interaction, |
36 |
| - 'status': Interaction.STATUSES.complete, |
37 |
| - 'communication_channel': communication_channel.pk, |
38 |
| - 'subject': 'whatever', |
39 |
| - 'date_0': '2018-01-01', |
40 |
| - 'date_1': '00:00:00', |
41 |
| - 'dit_adviser': self.user.pk, |
42 |
| - 'company': company.pk, |
43 |
| - 'contacts': [contact.pk for contact in contacts], |
44 |
| - 'service': random_obj_for_model(Service).pk, |
45 |
| - 'dit_team': random_obj_for_model(Team).pk, |
46 |
| - 'was_policy_feedback_provided': False, |
47 |
| - 'dit_participants-TOTAL_FORMS': 0, |
48 |
| - 'dit_participants-INITIAL_FORMS': 0, |
49 |
| - 'dit_participants-MAX_NUM_FORMS': 0, |
50 |
| - 'dit_participants-MIN_NUM_FORMS': 0, |
51 |
| - } |
52 |
| - response = self.client.post(url, data, follow=True) |
53 |
| - |
54 |
| - assert response.status_code == status.HTTP_200_OK |
55 |
| - |
56 |
| - assert Interaction.objects.count() == 1 |
57 |
| - interaction = Interaction.objects.first() |
58 |
| - |
59 |
| - assert interaction.contact == contacts[0] |
60 |
| - assert set(interaction.contacts.all()) == set(contacts) |
61 |
| - |
62 |
| - def test_update_contact_to_non_null(self): |
63 |
| - """ |
64 |
| - Test that updating an interaction with a value in contacts also sets the contact field. |
65 |
| - """ |
66 |
| - interaction = CompanyInteractionFactory() |
67 |
| - new_contacts = ContactFactory.create_batch(2, company=interaction.company) |
68 |
| - |
69 |
| - url = get_change_url(interaction) |
70 |
| - data = { |
71 |
| - # Unchanged values |
72 |
| - 'id': interaction.pk, |
73 |
| - 'kind': Interaction.KINDS.interaction, |
74 |
| - 'status': Interaction.STATUSES.complete, |
75 |
| - 'communication_channel': interaction.communication_channel.pk, |
76 |
| - 'subject': interaction.subject, |
77 |
| - 'date_0': interaction.date.date().isoformat(), |
78 |
| - 'date_1': interaction.date.time().isoformat(), |
79 |
| - 'dit_adviser': interaction.dit_adviser.pk, |
80 |
| - 'company': interaction.company.pk, |
81 |
| - 'service': interaction.service.pk, |
82 |
| - 'dit_team': interaction.dit_team.pk, |
83 |
| - 'was_policy_feedback_provided': interaction.was_policy_feedback_provided, |
84 |
| - 'policy_feedback_notes': interaction.policy_feedback_notes, |
85 |
| - 'policy_areas': [], |
86 |
| - 'policy_issue_types': [], |
87 |
| - 'event': '', |
88 |
| - 'dit_participants-TOTAL_FORMS': 0, |
89 |
| - 'dit_participants-INITIAL_FORMS': 0, |
90 |
| - 'dit_participants-MAX_NUM_FORMS': 0, |
91 |
| - 'dit_participants-MIN_NUM_FORMS': 0, |
92 |
| - 'dit_participants-0-id': interaction.dit_participants.first().pk, |
93 |
| - 'dit_participants-0-interaction': interaction.pk, |
94 |
| - |
95 |
| - # Changed values |
96 |
| - 'contacts': [contact.pk for contact in new_contacts], |
97 |
| - } |
98 |
| - response = self.client.post(url, data, follow=True) |
99 |
| - |
100 |
| - assert response.status_code == status.HTTP_200_OK |
101 |
| - |
102 |
| - interaction.refresh_from_db() |
103 |
| - assert interaction.contact == new_contacts[0] |
104 |
| - assert set(interaction.contacts.all()) == set(new_contacts) |
105 |
| - |
106 |
| - def test_update_contact_to_null(self): |
107 |
| - """Test that removing all contacts from an interaction clears the contact field.""" |
108 |
| - interaction = CompanyInteractionFactory() |
109 |
| - |
110 |
| - url = get_change_url(interaction) |
111 |
| - data = { |
112 |
| - # Unchanged values |
113 |
| - 'id': interaction.pk, |
114 |
| - 'kind': Interaction.KINDS.interaction, |
115 |
| - 'status': Interaction.STATUSES.complete, |
116 |
| - 'communication_channel': interaction.communication_channel.pk, |
117 |
| - 'subject': interaction.subject, |
118 |
| - 'date_0': interaction.date.date().isoformat(), |
119 |
| - 'date_1': interaction.date.time().isoformat(), |
120 |
| - 'dit_adviser': interaction.dit_adviser.pk, |
121 |
| - 'company': interaction.company.pk, |
122 |
| - 'service': interaction.service.pk, |
123 |
| - 'dit_team': interaction.dit_team.pk, |
124 |
| - 'was_policy_feedback_provided': interaction.was_policy_feedback_provided, |
125 |
| - 'policy_feedback_notes': interaction.policy_feedback_notes, |
126 |
| - 'policy_areas': [], |
127 |
| - 'policy_issue_types': [], |
128 |
| - 'event': '', |
129 |
| - 'dit_participants-TOTAL_FORMS': 0, |
130 |
| - 'dit_participants-INITIAL_FORMS': 0, |
131 |
| - 'dit_participants-MAX_NUM_FORMS': 0, |
132 |
| - 'dit_participants-MIN_NUM_FORMS': 0, |
133 |
| - 'dit_participants-0-id': interaction.dit_participants.first().pk, |
134 |
| - 'dit_participants-0-interaction': interaction.pk, |
135 |
| - |
136 |
| - # Changed values |
137 |
| - 'contacts': [], |
138 |
| - } |
139 |
| - response = self.client.post(url, data=data, follow=True) |
140 | 9 |
|
141 |
| - assert response.status_code == status.HTTP_200_OK |
142 | 10 |
|
143 |
| - interaction.refresh_from_db() |
144 |
| - assert interaction.contact is None |
145 |
| - assert interaction.contacts.count() == 0 |
| 11 | +class TestInteractionAdmin(AdminTestMixin): |
| 12 | + """Tests for interaction admin.""" |
146 | 13 |
|
147 | 14 | @pytest.mark.parametrize(
|
148 | 15 | 'num_contacts,expected_display_value',
|
|
0 commit comments