@@ -46,9 +46,9 @@ def test_invalid_kind_is_rejected(self, kind):
46
46
'company' : {
47
47
'id' : company .pk ,
48
48
},
49
- 'contact ' : {
49
+ 'contacts ' : [ {
50
50
'id' : contact .pk ,
51
- },
51
+ }] ,
52
52
'date' : '2017-04-18' ,
53
53
'dit_adviser' : {
54
54
'id' : adviser .pk ,
@@ -70,48 +70,6 @@ def test_invalid_kind_is_rejected(self, kind):
70
70
'kind' : [f'"{ kind } " is not a valid choice.' ],
71
71
}
72
72
73
- def test_contact_copied_to_contacts (self ):
74
- """
75
- Test that the value provided in the contact field is copied to contacts when an
76
- interaction is created.
77
-
78
- TODO: remove once the contacts field has fully replaced the contact field.
79
- """
80
- company = CompanyFactory ()
81
- contact = ContactFactory (company = company )
82
- communication_channel = random_obj_for_model (CommunicationChannel )
83
-
84
- url = reverse ('api-v3:interaction:collection' )
85
- request_data = {
86
- 'kind' : Interaction .KINDS .interaction ,
87
- 'communication_channel' : communication_channel .pk ,
88
- 'subject' : 'whatever' ,
89
- 'date' : date .today ().isoformat (),
90
- 'dit_adviser' : {
91
- 'id' : self .user .pk ,
92
- },
93
- 'company' : {
94
- 'id' : company .pk ,
95
- },
96
- 'contact' : {
97
- 'id' : contact .pk ,
98
- },
99
- 'service' : {
100
- 'id' : random_obj_for_model (ServiceModel ).pk ,
101
- },
102
- 'dit_team' : {
103
- 'id' : self .user .dit_team .pk ,
104
- },
105
- 'was_policy_feedback_provided' : False ,
106
- }
107
-
108
- api_client = self .create_api_client ()
109
- response = api_client .post (url , request_data )
110
- assert response .status_code == status .HTTP_201_CREATED
111
- interaction = Interaction .objects .get (pk = response .json ()['id' ])
112
- assert interaction .contact == contact
113
- assert list (interaction .contacts .all ()) == [contact ]
114
-
115
73
def test_contacts_copied_to_contact (self ):
116
74
"""
117
75
Test that the value provided in the contacts field is copied to contact when an
@@ -154,50 +112,6 @@ def test_contacts_copied_to_contact(self):
154
112
assert interaction .contact == contacts [0 ]
155
113
assert set (interaction .contacts .all ()) == set (contacts )
156
114
157
- def test_providing_contact_and_contacts_returns_an_error (self ):
158
- """
159
- Test that if both contact and contacts are provided, an error is returned.
160
-
161
- TODO: remove once the contacts field has fully replaced the contact field.
162
- """
163
- company = CompanyFactory ()
164
- contact = ContactFactory ()
165
- communication_channel = random_obj_for_model (CommunicationChannel )
166
-
167
- url = reverse ('api-v3:interaction:collection' )
168
- request_data = {
169
- 'kind' : Interaction .KINDS .interaction ,
170
- 'communication_channel' : communication_channel .pk ,
171
- 'subject' : 'whatever' ,
172
- 'date' : date .today ().isoformat (),
173
- 'dit_adviser' : {
174
- 'id' : self .user .pk ,
175
- },
176
- 'company' : {
177
- 'id' : company .pk ,
178
- },
179
- 'contact' : {
180
- 'id' : contact .pk ,
181
- },
182
- 'contacts' : [{
183
- 'id' : contact .pk ,
184
- }],
185
- 'service' : {
186
- 'id' : random_obj_for_model (ServiceModel ).pk ,
187
- },
188
- 'dit_team' : {
189
- 'id' : self .user .dit_team .pk ,
190
- },
191
- 'was_policy_feedback_provided' : False ,
192
- }
193
-
194
- api_client = self .create_api_client ()
195
- response = api_client .post (url , request_data )
196
- assert response .status_code == status .HTTP_400_BAD_REQUEST
197
- assert response .json () == {
198
- 'non_field_errors' : ['Only one of contact and contacts should be provided.' ],
199
- }
200
-
201
115
def test_error_returned_if_contacts_dont_belong_to_company (self ):
202
116
"""
203
117
Test that an error is returned if the contacts don't belong to the specified company.
@@ -289,29 +203,6 @@ def test_date_validation(self):
289
203
'Datetime has wrong format. Use one of these formats instead: YYYY-MM-DD.' ,
290
204
]
291
205
292
- def test_contact_copied_to_contacts (self ):
293
- """
294
- Test that the value provided in the contact field is copied to contacts when an
295
- interaction is updated.
296
-
297
- TODO: remove once the contacts field has fully replaced the contact field.
298
- """
299
- interaction = CompanyInteractionFactory (contacts = [])
300
- new_contact = ContactFactory (company = interaction .company )
301
-
302
- url = reverse ('api-v3:interaction:item' , kwargs = {'pk' : interaction .pk })
303
- data = {
304
- 'contact' : {
305
- 'id' : new_contact .pk ,
306
- },
307
- }
308
- response = self .api_client .patch (url , data = data )
309
-
310
- assert response .status_code == status .HTTP_200_OK
311
- interaction .refresh_from_db ()
312
- assert interaction .contact == new_contact
313
- assert list (interaction .contacts .all ()) == [new_contact ]
314
-
315
206
def test_contacts_copied_to_contact (self ):
316
207
"""
317
208
Test that the value provided in the contact field is copied to contacts when an
@@ -335,31 +226,6 @@ def test_contacts_copied_to_contact(self):
335
226
assert interaction .contact == new_contacts [0 ]
336
227
assert set (interaction .contacts .all ()) == set (new_contacts )
337
228
338
- def test_providing_contact_and_contacts_returns_an_error (self ):
339
- """
340
- Test that if both contact and contacts are provided, an error is returned.
341
-
342
- TODO: remove once the contacts field has fully replaced the contact field.
343
- """
344
- interaction = CompanyInteractionFactory (contacts = [])
345
- new_contact = ContactFactory (company = interaction .company )
346
-
347
- url = reverse ('api-v3:interaction:item' , kwargs = {'pk' : interaction .pk })
348
- data = {
349
- 'contact' : {
350
- 'id' : new_contact .pk ,
351
- },
352
- 'contacts' : [{
353
- 'id' : new_contact .pk ,
354
- }],
355
- }
356
- response = self .api_client .patch (url , data = data )
357
-
358
- assert response .status_code == status .HTTP_400_BAD_REQUEST
359
- assert response .json () == {
360
- 'non_field_errors' : ['Only one of contact and contacts should be provided.' ],
361
- }
362
-
363
229
@pytest .mark .parametrize (
364
230
'request_data' ,
365
231
(
0 commit comments