Skip to content

Commit cab09ef

Browse files
committed
Use same schema when creating cases, as the schema used to dump them
1 parent 108166a commit cab09ef

File tree

4 files changed

+18
-19
lines changed

4 files changed

+18
-19
lines changed

source/app/blueprints/rest/v2/cases.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,7 @@ def search(self):
107107
def create(self):
108108
try:
109109
request_data = call_deprecated_on_preload_modules_hook('case_create', request.get_json(), None)
110-
add_case_schema = CaseSchema()
111-
# TODO should use self._schema!
112-
case = add_case_schema.load(request_data)
110+
case = self._schema.load(request_data)
113111
case_template_id = request_data.pop('case_template_id', None)
114112
case = cases_create(case, case_template_id)
115113
result = self._schema.dump(case)

source/app/schema/marshables.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2477,16 +2477,17 @@ def verify_customer(self, data: Dict[str, Any], **kwargs: Any) -> Dict[str, Any]
24772477
ValidationError: If the customer ID is not valid.
24782478
24792479
"""
2480-
assert_type_mml(input_var=data.get('case_customer'),
2481-
field_name='case_customer',
2480+
customer_identifier = data.get('case_customer_id')
2481+
assert_type_mml(input_var=customer_identifier,
2482+
field_name='case_customer_id',
24822483
type=int,
24832484
allow_none=True)
24842485

2485-
client = Client.query.filter(Client.client_id == data.get('case_customer')).first()
2486+
client = Client.query.filter(Client.client_id == customer_identifier).first()
24862487
if client:
24872488
return data
24882489

2489-
raise ValidationError("Invalid client id", field_name="case_customer")
2490+
raise ValidationError('Invalid client id', field_name='case_customer_id')
24902491

24912492

24922493
class CaseDetailsSchema(ma.SQLAlchemyAutoSchema):

tests/iris.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ def create_dummy_case(self):
9999
body = {
100100
'case_name': 'case name',
101101
'case_description': 'description',
102-
'case_customer': 1,
102+
'case_customer_id': 1,
103103
'case_soc_id': ''
104104
}
105105
response = self._api.post('/api/v2/cases', body).json()

tests/tests_rest_cases.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def test_create_case_should_return_201(self):
4444
response = self._subject.create('/api/v2/cases', {
4545
'case_name': 'name',
4646
'case_description': 'description',
47-
'case_customer': 1,
47+
'case_customer_id': 1,
4848
'case_soc_id': ''
4949
})
5050
self.assertEqual(201, response.status_code)
@@ -53,15 +53,15 @@ def test_create_case_with_spurious_slash_should_return_404(self):
5353
response = self._subject.create('/api/v2/cases/', {
5454
'case_name': 'name',
5555
'case_description': 'description',
56-
'case_customer': 1,
56+
'case_customer_id': 1,
5757
'case_soc_id': ''
5858
})
5959
self.assertEqual(404, response.status_code)
6060

6161
def test_create_case_with_missing_name_should_return_400(self):
6262
response = self._subject.create('/api/v2/cases', {
6363
'case_description': 'description',
64-
'case_customer': 1,
64+
'case_customer_id': 1,
6565
'case_soc_id': ''
6666
})
6767
self.assertEqual(400, response.status_code)
@@ -70,7 +70,7 @@ def test_create_case_with_classification_id_should_set_classification_id(self):
7070
response = self._subject.create('/api/v2/cases', {
7171
'case_name': 'name',
7272
'case_description': 'description',
73-
'case_customer': 1,
73+
'case_customer_id': 1,
7474
'case_soc_id': '',
7575
'classification_id': 2
7676
}).json()
@@ -88,7 +88,7 @@ def test_get_case_should_return_case_data(self):
8888
response = self._subject.create('/api/v2/cases', {
8989
'case_name': 'name',
9090
'case_description': 'description',
91-
'case_customer': 1,
91+
'case_customer_id': 1,
9292
'case_soc_id': ''
9393
}).json()
9494
identifier = response['case_id']
@@ -99,7 +99,7 @@ def test_delete_case_should_return_204(self):
9999
response = self._subject.create('/api/v2/cases', {
100100
'case_name': 'name',
101101
'case_description': 'description',
102-
'case_customer': 1,
102+
'case_customer_id': 1,
103103
'case_soc_id': ''
104104
}).json()
105105
identifier = response['case_id']
@@ -110,7 +110,7 @@ def test_get_case_should_return_404_after_it_is_deleted(self):
110110
response = self._subject.create('/api/v2/cases', {
111111
'case_name': 'name',
112112
'case_description': 'description',
113-
'case_customer': 1,
113+
'case_customer_id': 1,
114114
'case_soc_id': ''
115115
}).json()
116116
identifier = response['case_id']
@@ -131,7 +131,7 @@ def test_get_cases_should_filter_on_case_name(self):
131131
response = self._subject.create('/api/v2/cases', {
132132
'case_name': 'test_get_cases_should_filter_on_case_name',
133133
'case_description': 'description',
134-
'case_customer': 1,
134+
'case_customer_id': 1,
135135
'case_soc_id': ''
136136
}).json()
137137
case_identifier = response['case_id']
@@ -178,17 +178,17 @@ def test_create_case_should_return_data_with_case_customer_when_case_customer_is
178178
body = {
179179
'case_name': 'case name',
180180
'case_description': 'description',
181-
'case_customer': '',
181+
'case_customer_id': '',
182182
'case_soc_id': ''
183183
}
184184
response = self._subject.create('/api/v2/cases', body).json()
185-
self.assertIn('case_customer', response['data'])
185+
self.assertIn('case_customer_id', response['data'])
186186

187187
def test_create_case_should_return_field_case_customer(self):
188188
body = {
189189
'case_name': 'case name',
190190
'case_description': 'description',
191-
'case_customer': 1,
191+
'case_customer_id': 1,
192192
'case_soc_id': ''
193193
}
194194
response = self._subject.create('/api/v2/cases', body).json()

0 commit comments

Comments
 (0)