def test__ensure_we_pass_more_than_one_option(self): p1 = ParameterFactory.create(task=self.t, flag="-th", bool_valued=False, rest_alias="that", default=123, spacing=True) p1 = ParameterFactory.create(task=self.t, flag="-ch", bool_valued=False, rest_alias="chain", default="CU", spacing=True) request_contents = {'task1_chain': 'AS', 'task1_that': 123, } steps = self.j1.steps.all().select_related('task') \ .extra(order_by=['ordering']) sd = SubmissionDetails() local_id = str(uuid.uuid1()) chain_str = sd._SubmissionDetails__construct_chain_string( steps, request_contents, local_id, 1) # print(chain_str) self.assertEqual(chain_str, "chain(task_runner.subtask(('" + local_id + "', 0, 1, 1, 1, 'task1', ['-th', '-ch'], " "{'-ch': {'spacing': True, " "'switchless': False, 'value': 'AS'}, " "'-th': {'spacing': True, " "'switchless': False, 'value': 123}}, " "'', 1, {}), immutable=True, " "queue='localhost'),).apply_async()")
def test_get_job_priority_returns_logged_priority(self): self.client.login(username='******', password='******') sd = SubmissionDetails() priority, value = sd._SubmissionDetails__get_job_priority(True, "127.0.0.1") self.assertEquals(priority, settings.LOGGED_IN_JOB_PRIORITY) self.assertEquals(value, 0)
def test__construct_chain_string_with_ending_group(self): self.t2 = TaskFactory.create(backend=self.b, name="task2", executable="rm") s = StepFactory(job=self.j1, task=self.t2, ordering=1) self.t3 = TaskFactory.create(backend=self.b, name="task3", executable="diff") s = StepFactory(job=self.j1, task=self.t3, ordering=1) steps = self.j1.steps.all().select_related('task') \ .extra(order_by=['ordering']) sd = SubmissionDetails() local_id = str(uuid.uuid1()) request_contents = {} chain_str = sd._SubmissionDetails__construct_chain_string( steps, request_contents, local_id, 1) # print(chain_str) self.assertEqual(chain_str, "chain(task_runner.subtask(('" + local_id + "', 0, 1, 1, 4, 'task1', [], {}, '', 1, {}), " "immutable=True, queue='localhost'), " "group(task_runner.subtask(('" + local_id + "', 1, 2, 2, 4, 'task2', [], {}, '', 1, {}), " "immutable=True, queue='localhost'), " "task_runner.subtask(('" + local_id + "', 1, 2, 3, 4, 'task3', [], {}, '', 1, {}), " "immutable=True, queue='localhost')), " "chord_end.subtask(('" + local_id + "', 2, 4), immutable=True, " "queue='localhost'),).apply_async()")
def test__construct_chain_string_high_priority(self): p1 = ParameterFactory.create(task=self.t, flag="-t", bool_valued=True, rest_alias="this") p1 = ParameterFactory.create(task=self.t, flag="-th", bool_valued=False, rest_alias="that", default=123, spacing=True) p1 = ParameterFactory.create(task=self.t, flag="VALUE", bool_valued=False, rest_alias="other", default="huh") request_contents = {'task1_this': 'True', 'task1_that': 123, 'task1_other': 'things'} steps = self.j1.steps.all().select_related('task') \ .extra(order_by=['ordering']) sd = SubmissionDetails() local_id = str(uuid.uuid1()) chain_str = sd._SubmissionDetails__construct_chain_string( steps, request_contents, local_id, 2) self.assertEqual(chain_str, "chain(task_runner.subtask(('" + local_id + "', 0, 1, 1, 1, 'task1', ['-t', '-th'], " "{'-th': {'spacing': True, " "'switchless': False, 'value': 123}}, " "'things', 1, {}), immutable=True, " "queue='high_localhost'),).apply_async()")
def test_params_rejected_with_r_reserved_words(self): p1 = ParameterFactory.create(task=self.t, flag="-t", bool_valued=False, rest_alias="this") steps = self.j1.steps.all() sd = SubmissionDetails() bool = sd._SubmissionDetails__test_params(steps, {'task1_this': 'format.packageInfo'}) self.assertEqual(bool, False)
def test_params_reject_with_unix_commands(self): p1 = ParameterFactory.create(task=self.t, flag="-t", bool_valued=False, rest_alias="this") steps = self.j1.steps.all() sd = SubmissionDetails() bool = sd._SubmissionDetails__test_params(steps, {'task1_this': 'rm'}) self.assertEqual(bool, False)
def test__test_params_returns_true_when_too_many_items_passed(self): p1 = ParameterFactory.create(task=self.t, flag="-t", bool_valued=False, rest_alias="this") steps = self.j1.steps.all() sd = SubmissionDetails() bool = sd._SubmissionDetails__test_params(steps, {'task1_that': 123, 'task1_this': 69}) self.assertEqual(bool, True)
def test__return_value_empty_string_with_no_value_set(self): p1 = ParameterFactory.create(task=self.t, flag="thingy", bool_valued=False, rest_alias="this") sd = SubmissionDetails() value = sd._SubmissionDetails__return_value(self.t, {'task1_this': 456}) self.assertEqual(value, '')
def test__return_value_returns_value_flag(self): p1 = ParameterFactory.create(task=self.t, flag="VALUE", bool_valued=False, rest_alias="this") sd = SubmissionDetails() value = sd._SubmissionDetails__return_value(self.t, {'task1_this': 456}) self.assertEqual(value, 456)
def test_get_job_priority_returns_none_priority(self): for i in range(0, settings.QUEUE_HARD_LIMIT): s = SubmissionFactory.create(ip="127.0.0.1") sd = SubmissionDetails() priority, value = sd._SubmissionDetails__get_job_priority(False, "127.0.0.1") self.assertEquals(priority, None) self.assertEquals(value, 15)
def test_get_job_priority_returns_low_priority(self): for i in range(0, settings.QUEUE_HOG_SIZE): s = SubmissionFactory.create(ip="127.0.0.1") sd = SubmissionDetails() priority, value = sd._SubmissionDetails__get_job_priority(False, "127.0.0.1") self.assertEquals(priority, Submission.LOW) self.assertEquals(value, 10)
def test_get_job_priority_returns_logged_lower_priority(self): for i in range(0, settings.QUEUE_HOG_SIZE): s = SubmissionFactory.create(ip="127.0.0.1") self.client.login(username='******', password='******') sd = SubmissionDetails() priority, value = sd._SubmissionDetails__get_job_priority(True, "127.0.0.1") self.assertEquals(priority, settings.LOGGED_IN_JOB_PRIORITY-1) self.assertEquals(value, 10)
def test_get_job_priority_returns_def_priority_with_unset_hog_size(self): for i in range(0, settings.QUEUE_HOG_SIZE): s = SubmissionFactory.create(ip="127.0.0.1") with self.settings(QUEUE_HOG_SIZE=None): sd = SubmissionDetails() priority, value = sd._SubmissionDetails__get_job_priority( False, "127.0.0.1") self.assertEquals(priority, settings.DEFAULT_JOB_PRIORITY) self.assertEquals(value, 10)
def test_get_job_priority_returns_low_priority_with_unset_hard_limit(self): for i in range(0, settings.QUEUE_HARD_LIMIT): s = SubmissionFactory.create(ip="127.0.0.1") with self.settings(QUEUE_HARD_LIMIT=None): sd = SubmissionDetails() priority, value = sd._SubmissionDetails__get_job_priority( False, "127.0.0.1") self.assertEquals(priority, settings.DEFAULT_JOB_PRIORITY-1) self.assertEquals(value, 15)
def test__test_params_returns_false_when_set_is_not_complete(self): p1 = ParameterFactory.create(task=self.t, flag="-t", bool_valued=False, rest_alias="this") p1 = ParameterFactory.create(task=self.t, flag="-th", bool_valued=False, rest_alias="that") steps = self.j1.steps.all() sd = SubmissionDetails() bool = sd._SubmissionDetails__test_params(steps, {'task1_that': 123, }) self.assertEqual(bool, False)
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_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_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_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)
def test_rejection_with_bad_job_id(self): self.data['job'] = '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)
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_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_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_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)
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_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)
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_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_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_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_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])
def test__construct_chain_string_multitask(self): self.t2 = TaskFactory.create(backend=self.b, name="task2", executable="rm") s = StepFactory(job=self.j1, task=self.t2, ordering=1) steps = self.j1.steps.all().select_related('task') \ .extra(order_by=['ordering']) sd = SubmissionDetails() local_id = str(uuid.uuid1()) request_contents = {} chain_str = sd._SubmissionDetails__construct_chain_string( steps, request_contents, local_id, 1) self.assertEqual( chain_str, "chain(task_runner.subtask(('" + local_id + "', 0, 1, 1, 2, 'task1', [], " "{}, '', 1, {}), immutable=True, " "queue='localhost'), " "task_runner.subtask(('" + local_id + "', 1, 2, 2, 2, 'task2', [], " "{}, '', 1, {}), immutable=True, " "queue='localhost'),).apply_async()")
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)
def test__request_sets_option_value(self): p1 = ParameterFactory.create(task=self.t, flag="-th", bool_valued=False, rest_alias="that", default=123, spacing=True) request_contents = { 'task1_that': 456, } steps = self.j1.steps.all().select_related('task') \ .extra(order_by=['ordering']) sd = SubmissionDetails() local_id = str(uuid.uuid1()) chain_str = sd._SubmissionDetails__construct_chain_string( steps, request_contents, local_id, 1) self.assertEqual( chain_str, "chain(task_runner.subtask(('" + local_id + "', 0, 1, 1, 1, 'task1', ['-th'], " "{'-th': {'spacing': True, " "'switchless': False, 'value': 456}}, " "'', 1, {}), immutable=True, " "queue='localhost'),).apply_async()")
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_get_job_returns_job_id(self): sd = SubmissionDetails() value = sd._SubmissionDetails__get_job("job1") self.assertEqual(value, [self.j1.pk])
def test__build_environment_returns_valid_dict(self): p1 = EnvironmentFactory.create(task=self.t, env="Test", value="McPath") sd = SubmissionDetails() dict = sd._SubmissionDetails__build_environment(self.t) self.assertEqual(dict, {"Test": "McPath"})
def test__build_environment_returns_empty_dict_without_settings(self): sd = SubmissionDetails() dict = sd._SubmissionDetails__build_environment(self.t) self.assertEqual(dict, {})
def test__test_params_returns_true_with_nothing(self): steps = self.j1.steps.all() sd = SubmissionDetails() bool = sd._SubmissionDetails__test_params(steps, {}) self.assertEqual(bool, True)
def test_get_job_priority_returns_default_priority(self): sd = SubmissionDetails() priority, value = sd._SubmissionDetails__get_job_priority( False, "127.0.0.1") self.assertEquals(priority, settings.DEFAULT_JOB_PRIORITY) self.assertEquals(value, 0)
def test_get_job_raises_if_not_entry(self): sd = SubmissionDetails() self.assertRaises(Exception, sd._SubmissionDetails__get_job, "argl")