def test_real_file_storage(self): dir = tempfile.mkdtemp() try: client = filetracker.Client(cache_dir=dir, remote_store=None) storage = FiletrackerStorage(client=client) self._test_file_storage(storage) finally: shutil.rmtree(dir)
def test_django_to_filetracker_path(self): storage = FiletrackerStorage(prefix='/foo', client=DummyClient()) field = FileField(storage=storage) value = FieldFile(None, field, 'bar') self.assertEqual(django_to_filetracker_path(value), '/foo/bar') with self.assertRaises(ValueError): django_to_filetracker_path(ContentFile('whatever', name='gizmo')) self.assertEqual('/foo/bar', django_to_filetracker_path( filetracker_to_django_file('/foo/bar', storage=storage)))
def test_handlers(self): submission = TestRunProgramSubmission.objects.get(pk=1) environ = create_environ() environ['job_id'] = 'job_id' environ['submission_id'] = submission.id environ['submission_kind'] = submission.kind environ['problem_instance_id'] = submission.problem_instance.id environ['problem_id'] = submission.problem.id environ['round_id'] = submission.problem_instance.round.id environ['contest_id'] = submission.problem_instance.id # Simulate successful compilation environ['compilation_result'] = 'OK' environ['compilation_message'] = '' environ = handlers.make_test(environ) self.assertIn('tests', environ) self.assertIn('test', environ['tests']) self.assertIn('in_file', environ['tests']['test']) # Simulate running tests FiletrackerStorage().save('output', ContentFile('o')) try: environ['test_results'] = {} environ['test_results']['test'] = { 'result_cpode': 'OK', 'result_string': 'OK', 'time_used': 111, 'out_file': '/output' } environ = handlers.grade_submission(environ) self.assertEqual(None, environ['score']) self.assertEqual('OK', environ['status']) environ = handlers.make_report(environ) self.assertIn('report_id', environ) report = TestRunReport.objects.get( submission_report=environ['report_id']) self.assertEqual(111, report.time_used) self.assertEqual('', report.comment) self.assertEqual('o', report.output_file.read()) handlers.delete_output(environ) except Exception: get_client().delete_file('/output')
def test_dummy_file_storage(self): storage = FiletrackerStorage() self._test_file_storage(storage)