def test_json(self): """Tests coverting a PurgeJobs message to and from JSON""" input_file = storage_test_utils.create_file(file_type='SOURCE') trigger = trigger_test_utils.create_trigger_event() PurgeResults.objects.create(source_file_id=input_file.id, trigger_event=trigger) job_exe = job_test_utils.create_job_exe(status='COMPLETED') job = job_exe.job # Add job to message message = PurgeJobs() message._purge_job_ids = [job.id] message.trigger_id = trigger.id message.source_file_id = input_file.id message.status_change = timezone.now() # Convert message to JSON and back, and then execute message_json_dict = message.to_json() new_message = PurgeJobs.from_json(message_json_dict) result = new_message.execute() self.assertTrue(result) # Check that job is deleted self.assertEqual(Job.objects.filter(id=job.id).count(), 0) self.assertEqual(JobExecution.objects.filter(id=job_exe.id).count(), 0)
def test_json(self): """Tests coverting a PurgeJobs message to and from JSON""" job_exe = job_test_utils.create_job_exe(status='COMPLETED') job = job_exe.job # Add job to message message = PurgeJobs() message._purge_job_ids = [job.id] message.status_change = timezone.now() # Convert message to JSON and back, and then execute message_json_dict = message.to_json() new_message = PurgeJobs.from_json(message_json_dict) result = new_message.execute() self.assertTrue(result) # Check that job is deleted self.assertEqual(Job.objects.filter(id=job.id).count(), 0) self.assertEqual(JobExecution.objects.filter(id=job_exe.id).count(), 0)