def test_minio(client): with open(filepath, "rb") as f: storage.upload("myFile.zip", bytes(f.read())) assert storage.exists("myFile.zip") with TemporaryDirectory() as _tmp: tmp = Path(_tmp) storage.download("myFile.zip", tmp / "downloaded.zip") assert filecmp.cmp(filepath, tmp / "downloaded.zip")
def test_minio(client): filepath = settings.BASE_DIR / 'testsuite' / 'test.zip' with open(filepath, 'rb') as f: storage.upload('myFile.zip', bytes(f.read())) assert storage.exists('myFile.zip') with TemporaryDirectory() as _tmp: tmp = Path(_tmp) storage.download('myFile.zip', tmp / 'downloaded.zip') assert filecmp.cmp(filepath, tmp / 'downloaded.zip')
def test_minio_buff(client): with open(filepath, "rb") as f: storage.upload("myFile.zip", bytes(f.read())) assert storage.exists("myFile.zip") buff = io.BytesIO() storage.download_buffer("myFile.zip", buff) buff.seek(0) with TemporaryDirectory() as _tmp: tmp = Path(_tmp) with open(tmp / "test1.zip", "wb") as f: f.write(buff.getbuffer()) assert filecmp.cmp(filepath, tmp / "test1.zip")
def handle_submission(file, assignment, user): log.debug(f'Submission {file.name} received') test_file = deepcopy(file) with ZipFile(test_file) as archive: if archive.testzip(): raise CorruptZipFile() with transaction.atomic(): """ Computing time from the last upload by this user. We lock the assignment row to prevent simultaneous uploads (race condition). """ assignment = ( Assignment.objects.select_for_update() .get(pk=assignment.pk) ) entries = ( assignment.submission_set .filter(user=user) .order_by('-timestamp') ) entry = entries.first() if entry: delta_t = timezone.now() - entry.timestamp if delta_t.seconds < assignment.min_time_between_uploads: log.debug(f'Submission can be made after #{delta_t} seconds') raise TooManySubmissionsError( assignment.min_time_between_uploads ) submission = assignment.submission_set.create( user=user, archive_size=file.size, ) log.debug(f'Submission #{submission.pk} created') storage.upload(f'{submission.pk}.zip', file.read()) log.debug(f"Submission's #{submission.pk} zipfile was uploaded") submission.evaluate() log.debug(f'Submission #{submission.pk} was sent to VMCK ' f'as #{submission.vmck_job_id}')
def test_ta_download_submission(client, STC, base_db_setup): """ Test if the teaching assistant can download submission """ (_, ta, user, _, assignment) = base_db_setup submission = assignment.submission_set.create( score=100.00, state=Submission.STATE_DONE, user=user, ) with open(FILEPATH, "rb") as f_in: storage.upload(f"{submission.pk}.zip", f_in.read()) client.login(username=ta.username, password="******") response = client.get(f"/submission/{submission.pk}/download") assert response.status_code == 200
def handle_submission(file, assignment, user): log.debug("Submission %s received", file.name) test_file = deepcopy(file) with ZipFile(test_file) as archive: if archive.testzip(): raise CorruptZipFile() with transaction.atomic(): """ Computing time from the last upload by this user. We lock the assignment row to prevent simultaneous uploads (race condition). """ entries = assignment.submission_set.filter( user=user).order_by("-timestamp") entry = entries.first() if entry: delta_t = timezone.now() - entry.timestamp if delta_t.seconds < assignment.min_time_between_uploads: log.debug("Submission can be made after #%s seconds", delta_t) raise TooManySubmissionsError( assignment.min_time_between_uploads) submission = assignment.submission_set.create( user=user, archive_size=file.size, ) log.debug("Submission #%s created", submission.pk) storage.upload(f"{submission.pk}.zip", file.read()) log.debug("Submission's #%s zipfile was uploaded", submission.pk) submission.evaluate() log.debug(f"Submission #{submission.pk} was sent to VMCK " f"as #{submission.evaluator_job_id}")
def handle_submission(request): file = request.FILES['file'] log.debug(f'Submission {file.name} received') assignment = get_object_or_404(Assignment.objects, code=request.GET['assignment_id']) # if not assignment.is_open_for(request.uesr): # return render('ești bou.html') if not assignment: return Http404() submission = Submission.objects.create( archive_size=file.size, user=request.user, assignment=assignment, ) storage.upload(f'{submission.id}.zip', file.read()) submission.evaluate() log.debug(f'Submission #{submission.id} sent to VMCK ' f'as #{submission.vmck_job_id}')