Esempio n. 1
0
 def test_valid_submission_post_creates_entry(self, m):
     request = self.factory.post(reverse('submission'),
                                 self.data,
                                 format='multipart')
     view = SubmissionDetails.as_view()
     response = view(request)
     self.assertEqual(response.status_code, status.HTTP_201_CREATED)
 def test_submission_makes_single_batch_entry(self, m):
     request = self.factory.post(reverse('submission'), self.data,
                                 format='multipart')
     view = SubmissionDetails.as_view()
     response = view(request)
     self.assertEqual(response.status_code, status.HTTP_201_CREATED)
     self.assertEqual(len(Batch.objects.all()), 1)
 def test_rejection_with_blank_submission_name(self):
     self.data['submission_name'] = ""
     request = self.factory.post(reverse('submission'), self.data,
                                 format='multipart')
     view = SubmissionDetails.as_view()
     response = view(request)
     self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
 def test_rejection_without_input_data(self):
     del(self.data['input_data'])
     request = self.factory.post(reverse('submission'), self.data,
                                 format='multipart')
     view = SubmissionDetails.as_view()
     response = view(request)
     self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
 def test_valid_submission_gets_medium_priority(self, m):
     request = self.factory.post(reverse('submission'), self.data,
                                 format='multipart')
     view = SubmissionDetails.as_view()
     response = view(request)
     subs = Submission.objects.get()
     self.assertEqual(subs.priority, Submission.MEDIUM)
Esempio n. 6
0
 def test_valid_submission_gets_medium_priority(self, m):
     request = self.factory.post(reverse('submission'),
                                 self.data,
                                 format='multipart')
     view = SubmissionDetails.as_view()
     response = view(request)
     subs = Submission.objects.get()
     self.assertEqual(subs.priority, Submission.MEDIUM)
Esempio n. 7
0
 def test_rejection_with_blank_submission_name(self):
     self.data['submission_name'] = ""
     request = self.factory.post(reverse('submission'),
                                 self.data,
                                 format='multipart')
     view = SubmissionDetails.as_view()
     response = view(request)
     self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
Esempio n. 8
0
 def test_rejection_without_input_data(self):
     del (self.data['input_data'])
     request = self.factory.post(reverse('submission'),
                                 self.data,
                                 format='multipart')
     view = SubmissionDetails.as_view()
     response = view(request)
     self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
Esempio n. 9
0
 def test_submission_makes_single_batch_entry(self, m):
     request = self.factory.post(reverse('submission'),
                                 self.data,
                                 format='multipart')
     view = SubmissionDetails.as_view()
     response = view(request)
     self.assertEqual(response.status_code, status.HTTP_201_CREATED)
     self.assertEqual(len(Batch.objects.all()), 1)
 def test_submissions_after_hard_limit_get_rejection(self, m):
     for i in range(0, settings.QUEUE_HARD_LIMIT):
         s = SubmissionFactory.create(ip="127.0.0.1", status=0)
     request = self.factory.post(reverse('submission'), self.data,
                                 format='multipart')
     view = SubmissionDetails.as_view()
     response = view(request)
     self.assertEqual(response.status_code,
                      status.HTTP_429_TOO_MANY_REQUESTS)
 def test_submission_ignores_undefined_params(self, m):
     p1 = ParameterFactory.create(task=self.t, rest_alias="this")
     self.data['task1_strange'] = "Value2"
     self.data['task1_this'] = "Value1"
     request = self.factory.post(reverse('submission'), self.data,
                                 format='multipart')
     view = SubmissionDetails.as_view()
     response = view(request)
     self.assertEqual(response.status_code, status.HTTP_201_CREATED)
 def test_multiple_submission_makes_seperate_batch_entries(self, m):
     self.data['job'] = 'job1'
     request = self.factory.post(reverse('submission'), self.data,
                                 format='multipart')
     view = SubmissionDetails.as_view()
     response = view(request)
     self.data['job'] = 'job2'
     self.data['input_data'] = SimpleUploadedFile('file1.txt',
                                                  bytes('these are the '
                                                        'file contents!',
                                                        'utf-8'))
     request = self.factory.post(reverse('submission'), self.data,
                                 format='multipart')
     view = SubmissionDetails.as_view()
     response = view(request)
     batch_entries = Batch.objects.all()
     self.assertEqual(len(batch_entries), 2)
     self.assertNotEqual(batch_entries[0].UUID, batch_entries[1].UUID)
 def test_submission_rejects_when_a_param_is_missed(self, m):
     p1 = ParameterFactory.create(task=self.t, rest_alias="this")
     p2 = ParameterFactory.create(task=self.t, rest_alias="that")
     self.data['task1_this'] = "Value1"
     request = self.factory.post(reverse('submission'), self.data,
                                 format='multipart')
     view = SubmissionDetails.as_view()
     response = view(request)
     self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
     self.assertEqual(len(Submission.objects.all()), 0)
 def test_reject_where_one_job_does_not_exist(self, m):
     self.data['job'] = 'job1,job34'
     request = self.factory.post(reverse('submission'), self.data,
                                 format='multipart')
     view = SubmissionDetails.as_view()
     response = view(request)
     self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
     batch_entries = Batch.objects.all()
     self.assertEqual(len(batch_entries), 0)
     self.assertEqual(len(Submission.objects.all()), 0)
Esempio n. 15
0
 def test_submissions_after_hard_limit_get_rejection(self, m):
     for i in range(0, settings.QUEUE_HARD_LIMIT):
         s = SubmissionFactory.create(ip="127.0.0.1", status=0)
     request = self.factory.post(reverse('submission'),
                                 self.data,
                                 format='multipart')
     view = SubmissionDetails.as_view()
     response = view(request)
     self.assertEqual(response.status_code,
                      status.HTTP_429_TOO_MANY_REQUESTS)
 def test_submission_accepts_when_all_params_given(self, m):
     p1 = ParameterFactory.create(task=self.t, rest_alias="this")
     p2 = ParameterFactory.create(task=self.t, rest_alias="that")
     self.data['task1_this'] = "Value1"
     self.data['task1_that'] = "Value2"
     request = self.factory.post(reverse('submission'), self.data,
                                 format='multipart')
     view = SubmissionDetails.as_view()
     response = view(request)
     self.assertEqual(response.status_code, status.HTTP_201_CREATED)
Esempio n. 17
0
 def test_multiple_submission_makes_seperate_batch_entries(self, m):
     self.data['job'] = 'job1'
     request = self.factory.post(reverse('submission'),
                                 self.data,
                                 format='multipart')
     view = SubmissionDetails.as_view()
     response = view(request)
     self.data['job'] = 'job2'
     self.data['input_data'] = SimpleUploadedFile(
         'file1.txt', bytes('these are the '
                            'file contents!', 'utf-8'))
     request = self.factory.post(reverse('submission'),
                                 self.data,
                                 format='multipart')
     view = SubmissionDetails.as_view()
     response = view(request)
     batch_entries = Batch.objects.all()
     self.assertEqual(len(batch_entries), 2)
     self.assertNotEqual(batch_entries[0].UUID, batch_entries[1].UUID)
Esempio n. 18
0
 def test_submission_ignores_undefined_params(self, m):
     p1 = ParameterFactory.create(task=self.t, rest_alias="this")
     self.data['task1_strange'] = "Value2"
     self.data['task1_this'] = "Value1"
     request = self.factory.post(reverse('submission'),
                                 self.data,
                                 format='multipart')
     view = SubmissionDetails.as_view()
     response = view(request)
     self.assertEqual(response.status_code, status.HTTP_201_CREATED)
 def test_reject_batch_with_missin_params(self, m):
     self.data['job'] = 'job1,job2'
     p1 = ParameterFactory.create(task=self.t, rest_alias="this")
     p2 = ParameterFactory.create(task=self.t2, rest_alias="that")
     self.data['task1_this'] = "Value1"
     request = self.factory.post(reverse('submission'), self.data,
                                 format='multipart')
     view = SubmissionDetails.as_view()
     response = view(request)
     self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
Esempio n. 20
0
 def test_reject_batch_with_missin_params(self, m):
     self.data['job'] = 'job1,job2'
     p1 = ParameterFactory.create(task=self.t, rest_alias="this")
     p2 = ParameterFactory.create(task=self.t2, rest_alias="that")
     self.data['task1_this'] = "Value1"
     request = self.factory.post(reverse('submission'),
                                 self.data,
                                 format='multipart')
     view = SubmissionDetails.as_view()
     response = view(request)
     self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
 def test_submission_checks_params_across_more_than_one_task(self, m):
     p1 = ParameterFactory.create(task=self.t, rest_alias="this")
     t2 = TaskFactory.create(backend=self.b, name="task2", executable="ls")
     p2 = ParameterFactory.create(task=t2, rest_alias="this2")
     self.data['task2_this2'] = "Value2"
     self.data['task1_this'] = "Value1"
     request = self.factory.post(reverse('submission'), self.data,
                                 format='multipart')
     view = SubmissionDetails.as_view()
     response = view(request)
     self.assertEqual(response.status_code, status.HTTP_201_CREATED)
Esempio n. 22
0
 def test_reject_where_one_job_does_not_exist(self, m):
     self.data['job'] = 'job1,job34'
     request = self.factory.post(reverse('submission'),
                                 self.data,
                                 format='multipart')
     view = SubmissionDetails.as_view()
     response = view(request)
     self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
     batch_entries = Batch.objects.all()
     self.assertEqual(len(batch_entries), 0)
     self.assertEqual(len(Submission.objects.all()), 0)
Esempio n. 23
0
 def test_submission_rejects_when_a_param_is_missed(self, m):
     p1 = ParameterFactory.create(task=self.t, rest_alias="this")
     p2 = ParameterFactory.create(task=self.t, rest_alias="that")
     self.data['task1_this'] = "Value1"
     request = self.factory.post(reverse('submission'),
                                 self.data,
                                 format='multipart')
     view = SubmissionDetails.as_view()
     response = view(request)
     self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
     self.assertEqual(len(Submission.objects.all()), 0)
Esempio n. 24
0
 def test_submission_accepts_when_all_params_given(self, m):
     p1 = ParameterFactory.create(task=self.t, rest_alias="this")
     p2 = ParameterFactory.create(task=self.t, rest_alias="that")
     self.data['task1_this'] = "Value1"
     self.data['task1_that'] = "Value2"
     request = self.factory.post(reverse('submission'),
                                 self.data,
                                 format='multipart')
     view = SubmissionDetails.as_view()
     response = view(request)
     self.assertEqual(response.status_code, status.HTTP_201_CREATED)
Esempio n. 25
0
 def test_rejection_with_disabled_job(self):
     j3 = JobFactory.create(name="job303", runnable=False)
     b3 = BackendFactory.create(root_path="/tmp/")
     t3 = TaskFactory.create(backend=b3, name="task1", executable="ls")
     s3 = StepFactory(job=j3, task=t3, ordering=0)
     self.data['job'] = 'job303'
     request = self.factory.post(reverse('submission'),
                                 self.data,
                                 format='multipart')
     view = SubmissionDetails.as_view()
     response = view(request)
     self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)
 def test_rejection_with_disabled_job(self):
     j3 = JobFactory.create(name="job303", runnable=False)
     b3 = BackendFactory.create(root_path="/tmp/")
     t3 = TaskFactory.create(backend=b3, name="task1",
                             executable="ls")
     s3 = StepFactory(job=j3, task=t3, ordering=0)
     self.data['job'] = 'job303'
     request = self.factory.post(reverse('submission'), self.data,
                                 format='multipart')
     view = SubmissionDetails.as_view()
     response = view(request)
     self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)
Esempio n. 27
0
 def test_submission_checks_params_across_more_than_one_task(self, m):
     p1 = ParameterFactory.create(task=self.t, rest_alias="this")
     t2 = TaskFactory.create(backend=self.b, name="task2", executable="ls")
     p2 = ParameterFactory.create(task=t2, rest_alias="this2")
     self.data['task2_this2'] = "Value2"
     self.data['task1_this'] = "Value1"
     request = self.factory.post(reverse('submission'),
                                 self.data,
                                 format='multipart')
     view = SubmissionDetails.as_view()
     response = view(request)
     self.assertEqual(response.status_code, status.HTTP_201_CREATED)
 def test_submissions_after_threshold_get_low_priority(self, m):
     for i in range(0, settings.QUEUE_HOG_SIZE):
         s = SubmissionFactory.create(ip="127.0.0.1", status=0)
     # for 'reasons' reverse does not work in this class/test?????
     # request = self.factory.post(reverse('submission'), self.data,
     #                             format='multipart')
     request = self.factory.post('/analytics_automated/submission/',
                                 self.data,
                                 format='multipart')
     view = SubmissionDetails.as_view()
     response = view(request)
     subs = Submission.objects.all()
     self.assertEqual(subs[10].priority, Submission.LOW)
 def test_dual_submission_makes_common_batch_entries(self, m):
     self.data['job'] = 'job1,job2'
     request = self.factory.post(reverse('submission'), self.data,
                                 format='multipart')
     view = SubmissionDetails.as_view()
     response = view(request)
     self.assertEqual(response.status_code, status.HTTP_201_CREATED)
     batch_entries = Batch.objects.all()
     submission_entries = Submission.objects.all()
     self.assertEqual(len(batch_entries), 1)
     self.assertEqual(len(submission_entries), 2)
     self.assertEqual(submission_entries[0].batch, batch_entries[0])
     self.assertEqual(submission_entries[1].batch, batch_entries[0])
Esempio n. 30
0
 def test_dual_submission_makes_common_batch_entries(self, m):
     self.data['job'] = 'job1,job2'
     request = self.factory.post(reverse('submission'),
                                 self.data,
                                 format='multipart')
     view = SubmissionDetails.as_view()
     response = view(request)
     self.assertEqual(response.status_code, status.HTTP_201_CREATED)
     batch_entries = Batch.objects.all()
     submission_entries = Submission.objects.all()
     self.assertEqual(len(batch_entries), 1)
     self.assertEqual(len(submission_entries), 2)
     self.assertEqual(submission_entries[0].batch, batch_entries[0])
     self.assertEqual(submission_entries[1].batch, batch_entries[0])
 def test_submission_rejects_when_file_does_not_validate(self, m):
     vt = ValidatorTypesFactory.create(name='png')
     v = ValidatorFactory.create(job=self.j1, validation_type=vt)
     f = open("submissions/files/test.gif", "rb").read()
     pngFile = SimpleUploadedFile('test.gif', f)
     this_data = {'input_data': pngFile,
                  'job': 'job1',
                  'submission_name': 'test',
                  'email': '*****@*****.**'}
     request = self.factory.post(reverse('submission'), this_data,
                                 format='multipart')
     view = SubmissionDetails.as_view()
     response = view(request)
     self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
Esempio n. 32
0
 def test_submissions_after_threshold_get_low_priority(self, m):
     # THIS FUNCTION AND OTHERS THAT DEPEND ON SETTINGS
     # ARE NOT IDEMPOTENT.
     for i in range(0, settings.QUEUE_HOG_SIZE):
         s = SubmissionFactory.create(ip="127.0.0.1", status=0)
     # for 'reasons' reverse does not work in this class/test?????
     # request = self.factory.post(reverse('submission'), self.data,
     #                             format='multipart')
     request = self.factory.post('/analytics_automated/submission/',
                                 self.data,
                                 format='multipart')
     view = SubmissionDetails.as_view()
     response = view(request)
     subs = Submission.objects.all()
     self.assertEqual(subs[10].priority, Submission.LOW)
Esempio n. 33
0
 def test_submission_rejects_when_file_does_not_validate(self, m):
     vt = ValidatorTypesFactory.create(name='png')
     v = ValidatorFactory.create(job=self.j1, validation_type=vt)
     f = open("submissions/files/test.gif", "rb").read()
     pngFile = SimpleUploadedFile('test.gif', f)
     this_data = {
         'input_data': pngFile,
         'job': 'job1',
         'submission_name': 'test',
         'email': '*****@*****.**'
     }
     request = self.factory.post(reverse('submission'),
                                 this_data,
                                 format='multipart')
     view = SubmissionDetails.as_view()
     response = view(request)
     self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
 def test_valid_submission_post_creates_entry(self, m):
     request = self.factory.post(reverse('submission'), self.data,
                                 format='multipart')
     view = SubmissionDetails.as_view()
     response = view(request)
     self.assertEqual(response.status_code, status.HTTP_201_CREATED)