def test_files(self): output_path = 'job_dir' j = Job(user=self.user, status=Job.COMPLETED, output_path=output_path) j.save() dir_path = os.path.join(settings.FILES_BASE, output_path) if not os.path.exists(dir_path): os.makedirs(dir_path) output_path2 = 'job_dir/job_subdir' dir_path2 = os.path.join(settings.FILES_BASE, output_path2) if not os.path.exists(dir_path2): os.makedirs(dir_path2) file_names_to_contents = { 'file1': 'ksjhfewiu\n', 'filez2': 'faeowrfjieawmnc\n', 'file3': 'sdlkjfaeowijfiaowjef\n', } file_names_to_contents2 = { 'job_subdir/fileA': 'aaaaahhhhhhh', 'job_subdir/fileB': 'baaaaaaaahhhhhh', } from tao.tests import helper for file_name in file_names_to_contents.keys(): helper.create_file(dir_path, file_name, file_names_to_contents) for file_name in file_names_to_contents2.keys(): helper.create_file(dir_path, file_name, file_names_to_contents2) merged_file_names_to_contents = {} merged_file_names_to_contents.update(file_names_to_contents) merged_file_names_to_contents.update(file_names_to_contents2) self.assertEqual(sorted(merged_file_names_to_contents.keys()), sorted([job_file.file_name for job_file in j.files()]))
def handle(self, *args, **options): if options['debug']: import pdb pdb.set_trace() self.valid_states = [x[0] for x in models.STATUS_CHOICES] status = options['status'].upper() if options['show']: self.show_and_exit(*args, **options) if options['set_status']: self.set_status(*args, **options) sys.exit() # Crash if invalid status status_idx = self.check_state_name(status) description = options['description'] fn = args[0] with open(fn, 'r') as fp: params = fp.read() username = args[1] # Crash if the user doesn't exist user = TaoUser.objects.get(username=username) database = args[2] if DataSet.objects.filter(database=database).count() != 1: raise CommandError("database '{db}' doesn't exist".format(db=database)) repetition = options['repetition'] if repetition not in ['Unique', 'Random']: raise CommandError("invalid repetition: {}".format(repetition)) for j in range(int(options['count'])): i = j + 1 new_job = Job(user=user, description=description.format(i=i, repetition=repetition), status=status, database=database, parameters=params.format(i=i, repetition=repetition) ) new_job.save()
def test_email_sent_only_when_completed(self): mail.outbox = [] job = Job(user=self.user, status=Job.IN_PROGRESS, output_path='job_dir') job.save() self.assertEqual(0, len(mail.outbox)) job.status = Job.COMPLETED job.save() self.assertEqual(1, len(mail.outbox)) self.assertEquals('[ASVO-TAO] Catalogue status update', mail.outbox[0].subject) mail_content = str(mail.outbox[0].body) self.assertTrue((str(job.id) in mail_content) and (self.user.username in mail_content))