Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • j.michal/grady
1 result
Show changes
{
"meta": {
"version": "4.0.0"
},
"module": {
"module_reference": "B.Inf.1801",
"total_score": 50,
"pass_score": 25,
"pass_only": false
},
"submission_types": [
{
"name": "Eine Bibliothek für Permutationen (I1-ID: l120mlc005h0)",
"full_score": 50,
"description": "A <b>description</b>!",
"solution": "Blub",
"programming_language": "java"
}
],
"students": [
{
"fullname": "Test, User",
"identifier": "20000000",
"username": "TU20000000",
"submissions": [
{
"code": "234;",
"type": "Eine Bibliothek für Permutationen (I1-ID: l120mlc005h0)",
"tests": {}
}
]
}
]
}
......@@ -14,13 +14,14 @@ from util import factory_boys as fact
def expect_file_to_be_downloaded(path):
"""
Checks if a file has finished downloading by checking if a file exists at the path and
no accompanying `<path>.part` file.
no `.part` file is present in the directory containing path
:param path: path to check
:return:
"""
def condition(*args):
file_present = Path(path).is_file()
partial_file_present = Path(os.path.join(path, '.part')).is_file()
partial_file_present = any(dir_path.suffix == ".part" for
dir_path in Path(path).parent.iterdir())
return file_present and not partial_file_present
return condition
......
import os
from django.test import LiveServerTestCase
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from core import models
from functional_tests.util import (login, create_browser, query_returns_object,
reset_browser_after_test)
from util import factory_boys as fact
JSON_EXPORT_FILE = os.path.join(os.path.dirname(__file__), 'data/hektor.json')
class TestImport(LiveServerTestCase):
browser: webdriver.Firefox = None
username = None
password = None
role = None
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.browser = create_browser()
@classmethod
def tearDownClass(cls):
super().tearDownClass()
cls.browser.quit()
def setUp(self):
super().setUp()
self.username = 'rev'
self.password = 'p'
fact.UserAccountFactory(
username=self.username,
password=self.password,
role=models.UserAccount.REVIEWER
)
def tearDown(self):
reset_browser_after_test(self.browser, self.live_server_url)
def _login(self):
login(self.browser, self.live_server_url, self.username, self.password)
def test_reviewer_can_import_data(self):
self._login()
self.browser.find_element_by_id("user-options").click()
self.browser.find_element_by_id("import-data-list-tile").click()
self.browser.execute_script(
"document.getElementById('file-input').style.display='block';"
)
file_input = self.browser.find_element_by_id("file-input")
file_input.send_keys(JSON_EXPORT_FILE)
self.browser.find_element_by_id("submit-import").click()
WebDriverWait(self.browser, 20).until(query_returns_object(models.SubmissionType))
......@@ -91,6 +91,7 @@ class TestSolutionComments(LiveServerTestCase):
old_text = 'A comment'
new_text = 'A new text'
self._write_comment(old_text)
WebDriverWait(self.browser, 10).until(query_returns_object(models.SolutionComment))
comment_obj = models.SolutionComment.objects.first()
self.assertEqual(old_text, comment_obj.text)
comment_el = self._edit_comment(old_text, new_text)
......
......@@ -18,6 +18,7 @@ def create_browser() -> webdriver.Firefox:
options = Options()
options.headless = bool(os.environ.get('HEADLESS_TESTS', False))
options.set_capability('unhandledPromptBehavior', 'accept')
options.set_capability('strictFileInteractability', False)
profile = FirefoxProfile()
profile.set_preference("dom.disable_beforeunload", True)
profile.set_preference("browser.download.folderList", 2)
......
......@@ -3,6 +3,7 @@ import os
import readline
import logging
from rest_framework.exceptions import ValidationError
from util.messages import warn
from core.models import ExamType, Feedback, Submission, SubmissionType, Test, FeedbackLabel
from core.models import UserAccount as User
......@@ -28,8 +29,8 @@ PASSWORDS = '.importer_passwords'
YES = 'Y/n'
NO = 'y/N'
RUSTY_HEKTOR_MIN_VER = ">=3.0.0"
RUSTY_HEKTOR_MAX_VER = "<4.0.0"
RUSTY_HEKTOR_MIN_VER = ">=4.0.0"
RUSTY_HEKTOR_MAX_VER = "<5.0.0"
valid = {"yes": True, "y": True, "ye": True, "no": False, "n": False}
......@@ -119,11 +120,17 @@ def load_hektor_json():
with open(file, 'r') as f:
exam_data = json.JSONDecoder().decode(f.read())
parse_and_import_hektor_json(exam_data)
def parse_and_import_hektor_json(exam_data):
hektor_version = exam_data['meta']['version']
if not (semver.match(hektor_version, RUSTY_HEKTOR_MIN_VER) and
semver.match(hektor_version, RUSTY_HEKTOR_MAX_VER)):
warn(f'The data you\'re trying to import has the wrong version {hektor_version}\n'
f'Requirements: {RUSTY_HEKTOR_MIN_VER}, {RUSTY_HEKTOR_MAX_VER}')
raise ValidationError(
f'The data you\'re trying to import has the wrong version {hektor_version}\n'
f'Requirements: {RUSTY_HEKTOR_MIN_VER}, {RUSTY_HEKTOR_MAX_VER}'
)
exam, _ = ExamType.objects.get_or_create(**exam_data['module'])
......@@ -131,7 +138,7 @@ def load_hektor_json():
_, created = SubmissionType.objects.update_or_create(
name=submission_type['name'], defaults=submission_type)
if not created:
log.warning(f"Updated submission type {submission_type}")
raise ValidationError(f"Updated submission type: {submission_type['name']}")
for student in exam_data['students']:
student_obj = user_factory.make_student(exam=exam, is_active=False,
......@@ -151,7 +158,7 @@ def load_reviewers():
store_pw=True)
def add_submission(student_obj, code, tests, type=None):
def add_submission(student_obj, code, tests, type=None, display_code=None):
submission_type_obj = SubmissionType.objects.get(name=type)
submission_obj, _ = Submission.objects.update_or_create(
......