| @@ 23-93 (lines=71) @@ | ||
| 20 | from ..tasks import ImportTemplateTask |
|
| 21 | ||
| 22 | ||
| 23 | class ImportTemplateTaskTest(WebSocketMixin, BaseExcelMixin, TestCase): |
|
| 24 | def setUp(self): |
|
| 25 | # calling my base class setup |
|
| 26 | super().setUp() |
|
| 27 | ||
| 28 | # setting task |
|
| 29 | self.my_task = ImportTemplateTask() |
|
| 30 | ||
| 31 | def test_on_failure(self): |
|
| 32 | """Testing on failure methods""" |
|
| 33 | ||
| 34 | exc = Exception("Test") |
|
| 35 | task_id = "test_task_id" |
|
| 36 | args = [self.submission_id] |
|
| 37 | kwargs = {} |
|
| 38 | einfo = ExceptionInfo |
|
| 39 | ||
| 40 | # call on_failure method |
|
| 41 | self.my_task.on_failure(exc, task_id, args, kwargs, einfo) |
|
| 42 | ||
| 43 | # check submission status and message |
|
| 44 | submission = Submission.objects.get(pk=self.submission_id) |
|
| 45 | ||
| 46 | # check submission.state changed |
|
| 47 | self.assertEqual(submission.status, ERROR) |
|
| 48 | self.assertEqual( |
|
| 49 | submission.message, |
|
| 50 | "Error in Template loading: Test") |
|
| 51 | ||
| 52 | # test email sent |
|
| 53 | self.assertEqual(len(mail.outbox), 1) |
|
| 54 | ||
| 55 | # read email |
|
| 56 | email = mail.outbox[0] |
|
| 57 | ||
| 58 | self.assertEqual( |
|
| 59 | "Error in Template loading: %s" % self.submission_id, |
|
| 60 | email.subject) |
|
| 61 | ||
| 62 | message = 'Error' |
|
| 63 | notification_message = 'Error in Template loading: Test' |
|
| 64 | ||
| 65 | self.check_message(message, notification_message) |
|
| 66 | ||
| 67 | @patch("excel.tasks.upload_template", return_value=True) |
|
| 68 | def test_import_from_template(self, my_upload): |
|
| 69 | """Testing template import""" |
|
| 70 | ||
| 71 | # NOTE that I'm calling the function directly, without delay |
|
| 72 | # (AsyncResult). I've patched the time consuming task |
|
| 73 | res = self.my_task.run(submission_id=1) |
|
| 74 | ||
| 75 | # assert a success with data uploading |
|
| 76 | self.assertEqual(res, "success") |
|
| 77 | ||
| 78 | # assert that method were called |
|
| 79 | self.assertTrue(my_upload.called) |
|
| 80 | ||
| 81 | @patch("excel.tasks.upload_template", return_value=False) |
|
| 82 | def test_import_from_template_errors(self, my_upload): |
|
| 83 | """Testing template import with errors""" |
|
| 84 | ||
| 85 | # NOTE that I'm calling the function directly, without delay |
|
| 86 | # (AsyncResult). I've patched the time consuming task |
|
| 87 | res = self.my_task.run(submission_id=1) |
|
| 88 | ||
| 89 | # assert a success with data uploading |
|
| 90 | self.assertEqual(res, "Error in uploading Template data") |
|
| 91 | ||
| 92 | # assert that method were called |
|
| 93 | self.assertTrue(my_upload.called) |
|
| 94 | ||
| @@ 23-93 (lines=71) @@ | ||
| 20 | from ..tasks import ImportCRBAnimTask |
|
| 21 | ||
| 22 | ||
| 23 | class ImportCRBAnimTaskTest(WebSocketMixin, BaseTestCase, TestCase): |
|
| 24 | def setUp(self): |
|
| 25 | # calling my base class setup |
|
| 26 | super().setUp() |
|
| 27 | ||
| 28 | # setting task |
|
| 29 | self.my_task = ImportCRBAnimTask() |
|
| 30 | ||
| 31 | def test_on_failure(self): |
|
| 32 | """Testing on failure methods""" |
|
| 33 | ||
| 34 | exc = Exception("Test") |
|
| 35 | task_id = "test_task_id" |
|
| 36 | args = [self.submission_id] |
|
| 37 | kwargs = {} |
|
| 38 | einfo = ExceptionInfo |
|
| 39 | ||
| 40 | # call on_failure method |
|
| 41 | self.my_task.on_failure(exc, task_id, args, kwargs, einfo) |
|
| 42 | ||
| 43 | # check submission status and message |
|
| 44 | submission = Submission.objects.get(pk=self.submission_id) |
|
| 45 | ||
| 46 | # check submission.state changed |
|
| 47 | self.assertEqual(submission.status, ERROR) |
|
| 48 | self.assertEqual( |
|
| 49 | submission.message, |
|
| 50 | "Error in CRBAnim loading: Test") |
|
| 51 | ||
| 52 | # test email sent |
|
| 53 | self.assertEqual(len(mail.outbox), 1) |
|
| 54 | ||
| 55 | # read email |
|
| 56 | email = mail.outbox[0] |
|
| 57 | ||
| 58 | self.assertEqual( |
|
| 59 | "Error in CRBAnim loading: %s" % self.submission_id, |
|
| 60 | email.subject) |
|
| 61 | ||
| 62 | message = 'Error' |
|
| 63 | notification_message = 'Error in CRBAnim loading: Test' |
|
| 64 | ||
| 65 | self.check_message(message, notification_message) |
|
| 66 | ||
| 67 | @patch("crbanim.tasks.upload_crbanim", return_value=True) |
|
| 68 | def test_import_from_crbanim(self, my_upload): |
|
| 69 | """Testing crbanim import""" |
|
| 70 | ||
| 71 | # NOTE that I'm calling the function directly, without delay |
|
| 72 | # (AsyncResult). I've patched the time consuming task |
|
| 73 | res = self.my_task.run(submission_id=1) |
|
| 74 | ||
| 75 | # assert a success with data uploading |
|
| 76 | self.assertEqual(res, "success") |
|
| 77 | ||
| 78 | # assert that method were called |
|
| 79 | self.assertTrue(my_upload.called) |
|
| 80 | ||
| 81 | @patch("crbanim.tasks.upload_crbanim", return_value=False) |
|
| 82 | def test_import_from_crbanim_errors(self, my_upload): |
|
| 83 | """Testing crbianim import with errors""" |
|
| 84 | ||
| 85 | # NOTE that I'm calling the function directly, without delay |
|
| 86 | # (AsyncResult). I've patched the time consuming task |
|
| 87 | res = self.my_task.run(submission_id=1) |
|
| 88 | ||
| 89 | # assert a success with data uploading |
|
| 90 | self.assertEqual(res, "Error in uploading CRBAnim data") |
|
| 91 | ||
| 92 | # assert that method were called |
|
| 93 | self.assertTrue(my_upload.called) |
|
| 94 | ||