def test_submission(client): filepath = settings.BASE_DIR / 'testsuite' / 'test.zip' with open(filepath, 'rb') as file: upload = SimpleUploadedFile(filepath.name, file.read(), content_type='application/zip') client.post('/upload/?assignment_id=pc-00', data={ 'name': filepath.name, 'file': upload }, format='multipart') assert len(Submission.objects.all()) == 1 assert storage.exists('1.zip') submission = Submission.objects.all()[0] assert submission.state == submission.STATE_NEW assert submission.assignment.code == 'pc-00' assert submission.archive_size > 0 assert submission.vmck_job_id > 0 while submission.state != submission.STATE_DONE: time.sleep(2) assert submission.score > 0
def test_submission(client, live_server, base_db_setup): FILEPATH = settings.BASE_DIR / 'testsuite' / 'test.zip' (_, _, user, course, assignment) = base_db_setup client.login(username=user.username, password='******') with open(FILEPATH, 'rb') as file: upload = SimpleUploadedFile(FILEPATH.name, file.read(), content_type='application/zip') client.post( f'/assignment/{course.pk}/{assignment.pk}/upload/', data={'name': FILEPATH.name, 'file': upload}, format='multipart', ) assert len(Submission.objects.all()) == 1 assert storage.exists('1.zip') submission = Submission.objects.all()[0] # There is a delay before the general queue's threads starts so, depending # on the system, the submission might be in the queue or already sent assert submission.state == submission.STATE_NEW \ or submission.state == submission.STATE_QUEUED assert submission.archive_size > 0 # As the reason mentioned above, the submission might have been already # submitted start = time.time() while submission.vmck_job_id is None: time.sleep(0.5) submission.refresh_from_db() assert time.time() - start < 2 assert submission.vmck_job_id > 0 start = time.time() while submission.state != submission.STATE_DONE: submission.refresh_from_db() time.sleep(1) if time.time() - start >= 180: assert False assert submission.score == 100 assert submission.total_score == 100 response = client.get(f'/submission/{submission.pk}/download') with NamedTemporaryFile(delete=False) as f: for data in response.streaming_content: f.write(data) assert filecmp.cmp(f.name, FILEPATH, shallow=False)
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 test_submission(client, live_server, base_db_setup, mock_config): (_, _, user, course, assignment) = base_db_setup client.login(username=user.username, password="******") mock_config.start_server() with open(FILEPATH, "rb") as file: upload = SimpleUploadedFile(FILEPATH.name, file.read(), content_type="application/zip") client.post( f"/assignment/{course.pk}/{assignment.pk}/upload/", data={ "name": FILEPATH.name, "file": upload }, format="multipart", ) assert Submission.objects.all().count() == 1 assert storage.exists("1.zip") submission = Submission.objects.all()[0] # There is a delay before the general queue's threads starts so, depending # on the system, the submission might be in the queue or already sent assert (submission.state == submission.STATE_NEW or submission.state == submission.STATE_QUEUED) assert submission.archive_size > 0 # As the reason mentioned above, the submission might have been already # submitted start = time.time() while submission.evaluator_job_id is None: time.sleep(0.5) submission.refresh_from_db() assert time.time() - start < 2 assert submission.evaluator_job_id > 0 start = time.time() while submission.state != submission.STATE_DONE: submission.refresh_from_db() time.sleep(1) if time.time() - start >= 180: assert False mock_config.stop_server() assert submission.score == 100 assert submission.total_score == 100 response = client.get(f"/submission/{submission.pk}/download") with NamedTemporaryFile(delete=False) as f: for data in response.streaming_content: f.write(data) assert filecmp.cmp(f.name, FILEPATH, shallow=False)