def test_archive_creation(self): """Test archive creation for solutions.""" for solution in [self.passed_solution, self.failed_solution]: self.assertFalse(solution.archive) create_archive_async(solution) self.assertTrue(solution.archive) self.assertTrue(zipfile.is_zipfile(solution.archive.path)) with zipfile.ZipFile(solution.archive.path) as zip_file: self.assertIn("Example1.java", zip_file.namelist()) self.assertIn("Example2.java", zip_file.namelist()) with zip_file.open("Example1.java") as f: self.assertEqual(f.read(), JAVA_EXAMPLE_1) with zip_file.open("Example2.java") as f: self.assertEqual(f.read(), JAVA_EXAMPLE_2) with TemporaryDirectory() as tmp_dir: # Test extraction to expose erroneous packaging zip_file.extractall(tmp_dir) for _, dirs, files in os.walk(tmp_dir): self.assertIn("Example1.java", files) self.assertIn("Example2.java", files) self.assertEqual(2, len(files)) # The inherited folder structure should be flat self.assertFalse(dirs) self.assertIsNone(zip_file.testzip())
def get(self, request, solution_id): if not solution_id: raise Http404('No solution id was supplied.') solution = access_solution_or_404(request.user, solution_id) if solution.archive: return JsonResponse({'status': 'available'}) try: create_archive_async(solution) except TaskLockedException: return JsonResponse({'status': 'already running'}) return JsonResponse({'status': 'initiated'})
def get(self, request, solution_id): if not solution_id: raise Http404("No solution id was supplied.") solution = get_object_or_404(Solution, pk=solution_id, author=request.user) if solution.archive: return JsonResponse({"status": "available"}) try: create_archive_async(solution) except TaskLockedException: return JsonResponse({"status": "already running"}) return JsonResponse({"status": "initiated"})