|
@@ 329-390 (lines=62) @@
|
| 326 |
|
self.assertTrue(my_validate.called) |
| 327 |
|
self.assertTrue(my_read.called) |
| 328 |
|
|
| 329 |
|
@patch('validation.tasks.send_message_to_websocket') |
| 330 |
|
@patch('asyncio.get_event_loop') |
| 331 |
|
@patch("validation.tasks.MetaDataValidation.read_in_ruleset") |
| 332 |
|
@patch("validation.tasks.MetaDataValidation.check_usi_structure") |
| 333 |
|
@patch("validation.tasks.MetaDataValidation.validate") |
| 334 |
|
def test_validate_submission_wrong_json( |
| 335 |
|
self, my_validate, my_check, my_read, asyncio_mock, |
| 336 |
|
send_message_to_websocket_mock): |
| 337 |
|
tmp = asyncio_mock.return_value |
| 338 |
|
tmp.run_until_complete = Mock() |
| 339 |
|
|
| 340 |
|
# assign a fake response for check_usi_structure |
| 341 |
|
usi_result = [ |
| 342 |
|
('Wrong JSON structure: no title field for record with ' |
| 343 |
|
'alias as animal_1'), |
| 344 |
|
('Wrong JSON structure: the values for attribute Person ' |
| 345 |
|
'role needs to be in an array for record animal_1') |
| 346 |
|
] |
| 347 |
|
my_check.return_value = usi_result |
| 348 |
|
|
| 349 |
|
# setting a return value for check_with_ruleset |
| 350 |
|
rule_result = Mock() |
| 351 |
|
rule_result.get_overall_status.return_value = "Pass" |
| 352 |
|
my_validate.return_value = rule_result |
| 353 |
|
|
| 354 |
|
# call task |
| 355 |
|
res = self.my_task.run(submission_id=self.submission_id) |
| 356 |
|
|
| 357 |
|
# assert a success with validation taks |
| 358 |
|
self.assertEqual(res, "success") |
| 359 |
|
|
| 360 |
|
# check submission status and message |
| 361 |
|
self.submission.refresh_from_db() |
| 362 |
|
|
| 363 |
|
# check submission.state changed |
| 364 |
|
self.assertEqual(self.submission.status, NEED_REVISION) |
| 365 |
|
self.assertIn( |
| 366 |
|
"Wrong JSON structure", |
| 367 |
|
self.submission.message) |
| 368 |
|
|
| 369 |
|
self.assertEqual(asyncio_mock.call_count, 1) |
| 370 |
|
self.assertEqual(tmp.run_until_complete.call_count, 1) |
| 371 |
|
self.assertEqual(send_message_to_websocket_mock.call_count, 1) |
| 372 |
|
send_message_to_websocket_mock.assert_called_with( |
| 373 |
|
{'message': 'Need Revision', |
| 374 |
|
'notification_message': 'Validation got errors: Wrong JSON ' |
| 375 |
|
'structure'}, 1) |
| 376 |
|
|
| 377 |
|
# check Names (they require revisions) |
| 378 |
|
for name in self.name_qs: |
| 379 |
|
self.assertEqual(name.status, NEED_REVISION) |
| 380 |
|
|
| 381 |
|
# test for model message (usi_results) |
| 382 |
|
self.assertEqual( |
| 383 |
|
name.validationresult.messages, usi_result) |
| 384 |
|
self.assertEqual( |
| 385 |
|
name.validationresult.status, "Wrong JSON structure") |
| 386 |
|
|
| 387 |
|
# if JSON is not valid, I don't check for ruleset |
| 388 |
|
self.assertTrue(my_check.called) |
| 389 |
|
self.assertFalse(my_validate.called) |
| 390 |
|
self.assertTrue(my_read.called) |
| 391 |
|
|
| 392 |
|
@patch('validation.tasks.send_message_to_websocket') |
| 393 |
|
@patch('asyncio.get_event_loop') |
|
@@ 274-327 (lines=54) @@
|
| 271 |
|
1 |
| 272 |
|
) |
| 273 |
|
|
| 274 |
|
@patch('validation.tasks.send_message_to_websocket') |
| 275 |
|
@patch('asyncio.get_event_loop') |
| 276 |
|
@patch("validation.tasks.MetaDataValidation.read_in_ruleset") |
| 277 |
|
@patch("validation.tasks.MetaDataValidation.check_usi_structure") |
| 278 |
|
@patch("validation.tasks.MetaDataValidation.validate") |
| 279 |
|
def test_validate_submission(self, my_validate, my_check, my_read, |
| 280 |
|
asyncio_mock, send_message_to_websocket_mock): |
| 281 |
|
tmp = asyncio_mock.return_value |
| 282 |
|
tmp.run_until_complete = Mock() |
| 283 |
|
# setting check_usi_structure result |
| 284 |
|
my_check.return_value = [] |
| 285 |
|
|
| 286 |
|
# setting a return value for check_with_ruleset |
| 287 |
|
validation_result = Mock() |
| 288 |
|
validation_result.get_overall_status.return_value = "Pass" |
| 289 |
|
validation_result.get_messages.return_value = ["A message"] |
| 290 |
|
my_validate.return_value = validation_result |
| 291 |
|
|
| 292 |
|
# NOTE that I'm calling the function directly, without delay |
| 293 |
|
# (AsyncResult). I've patched the time consuming task |
| 294 |
|
res = self.my_task.run(submission_id=self.submission_id) |
| 295 |
|
|
| 296 |
|
# assert a success with validation taks |
| 297 |
|
self.assertEqual(res, "success") |
| 298 |
|
|
| 299 |
|
# check submission status and message |
| 300 |
|
self.submission.refresh_from_db() |
| 301 |
|
|
| 302 |
|
# check submission.state changed |
| 303 |
|
self.assertEqual(self.submission.status, READY) |
| 304 |
|
self.assertEqual( |
| 305 |
|
self.submission.message, |
| 306 |
|
"Submission validated with success") |
| 307 |
|
|
| 308 |
|
self.assertEqual(asyncio_mock.call_count, 1) |
| 309 |
|
self.assertEqual(tmp.run_until_complete.call_count, 1) |
| 310 |
|
self.assertEqual(send_message_to_websocket_mock.call_count, 1) |
| 311 |
|
send_message_to_websocket_mock.assert_called_with( |
| 312 |
|
{'message': 'Ready', |
| 313 |
|
'notification_message': 'Submission validated with success'}, 1) |
| 314 |
|
|
| 315 |
|
# check Names (they are all ok) |
| 316 |
|
for name in self.name_qs: |
| 317 |
|
self.assertEqual(name.status, READY) |
| 318 |
|
|
| 319 |
|
# test for model message (usi_results) |
| 320 |
|
self.assertEqual( |
| 321 |
|
name.validationresult.messages, ["A message"]) |
| 322 |
|
self.assertEqual(name.validationresult.status, "Pass") |
| 323 |
|
|
| 324 |
|
# assert validation functions called |
| 325 |
|
self.assertTrue(my_check.called) |
| 326 |
|
self.assertTrue(my_validate.called) |
| 327 |
|
self.assertTrue(my_read.called) |
| 328 |
|
|
| 329 |
|
@patch('validation.tasks.send_message_to_websocket') |
| 330 |
|
@patch('asyncio.get_event_loop') |