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
import factory
from factory.django import DjangoModelFactory
from faker import Faker
from core import models
fake = Faker()
fake.seed(42)
class ExamTypeFactory(DjangoModelFactory):
class Meta:
model = models.ExamType
django_get_or_create = ('module_reference',)
module_reference = 'B.Inf.4242 Test Module'
total_score = 90
pass_score = 45
pass_only = False
class SubmissionTypeFactory(DjangoModelFactory):
class Meta:
model = models.SubmissionType
name = factory.Sequence(lambda n: f"[{n}] Example submission type")
full_score = 15
description = factory.Sequence(
lambda n: f'Type {n} \n<h1>This</h1> is a description containing html')
solution = factory.Sequence(lambda n: f'//This is a solution\n#include<stdio.h>\n\nint main() {{\n\tprintf("Hello World\\n");\n\treturn {n};\n}}') # noqa
programming_language = models.SubmissionType.C
class UserAccountFactory(DjangoModelFactory):
class Meta:
model = models.UserAccount
django_get_or_create = ('username',)
role = models.UserAccount.TUTOR
fullname = fake.name
username = fake.user_name
password = factory.PostGenerationMethodCall('set_password', 'redrum-is-murder-reversed')
class StudentInfoFactory(DjangoModelFactory):
class Meta:
model = models.StudentInfo
exam = factory.SubFactory(ExamTypeFactory)
user = factory.SubFactory(UserAccountFactory)
class TestFactory(DjangoModelFactory):
class Meta:
model = models.Test
name = 'EmptyTest'
label = 'Empty'
annotation = factory.Sequence(lambda n: f'Test: {n} This is an annotation')
class SubmissionFactory(DjangoModelFactory):
class Meta:
model = models.Submission
text = factory.Sequence(lambda n: f'#include<stdio.h>\n\nint main() {{\n\tprintf("Hello World\\n");\n\treturn {n};\n}}') # noqa
type = factory.SubFactory(SubmissionTypeFactory)
student = factory.SubFactory(StudentInfoFactory)
class FeedbackFactory(DjangoModelFactory):
class Meta:
model = models.Feedback
of_submission = factory.SubFactory(SubmissionTypeFactory)
class FeedbackCommentFactory(DjangoModelFactory):
class Meta:
model = models.FeedbackComment
text = 'Well, this is bad...'
of_tutor = factory.SubFactory(UserAccountFactory)
of_feedback = factory.SubFactory(FeedbackFactory)
class SubmissionSubscriptionFactory(DjangoModelFactory):
class Meta:
model = models.SubmissionSubscription
owner = factory.SubFactory(UserAccountFactory)
class TutorSubmissionAssignmentFactory(DjangoModelFactory):
class Meta:
model = models.TutorSubmissionAssignment
submission = factory.SubFactory(SubmissionFactory)
subscription = factory.SubFactory(SubmissionSubscriptionFactory)
...@@ -6,7 +6,7 @@ file = 'core/templates/index.html' ...@@ -6,7 +6,7 @@ file = 'core/templates/index.html'
with open(file, "r+") as f: with open(file, "r+") as f:
s = f.read() s = f.read()
f.seek(0) f.seek(0)
f.write("{% load staticfiles %}\n" + s) f.write("{% load static %}\n" + s)
for i, line in enumerate(fileinput.input(file, inplace=1)): for i, line in enumerate(fileinput.input(file, inplace=1)):
sys.stdout.write(line.replace('/static/', "{% static '")) sys.stdout.write(line.replace('/static/', "{% static '"))
......
...@@ -12,7 +12,7 @@ from core.models import UserAccount as User ...@@ -12,7 +12,7 @@ from core.models import UserAccount as User
from util.factories import GradyUserFactory from util.factories import GradyUserFactory
from util.messages import info, warn from util.messages import info, warn
WELCOME = ''' WELCOME = r'''
______ __ ____ __ ______ __ ____ __
/ ____/________ _____/ /_ __ / _/___ ___ ____ ____ _____/ /____ _____ / ____/________ _____/ /_ __ / _/___ ___ ____ ____ _____/ /____ _____
/ / __/ ___/ __ `/ __ / / / / / // __ `__ \/ __ \/ __ \/ ___/ __/ _ \/ ___/ / / __/ ___/ __ `/ __ / / / / / // __ `__ \/ __ \/ __ \/ ___/ __/ _ \/ ___/
...@@ -67,7 +67,7 @@ class chdir_context(object): ...@@ -67,7 +67,7 @@ class chdir_context(object):
info(f'Returned to {self.old_dir}') info(f'Returned to {self.old_dir}')
def i(prompt: str, default: str='', is_path: bool=False, is_file: bool=False): def i(prompt: str, default: str = '', is_path: bool = False, is_file: bool = False):
if default is YES or default is NO: if default is YES or default is NO:
answer = valid[input(f'[Q] {prompt} ({default}): ').lower() or ( answer = valid[input(f'[Q] {prompt} ({default}): ').lower() or (
'y' if YES == default else 'n')] 'y' if YES == default else 'n')]
...@@ -196,9 +196,9 @@ def do_load_submission_types(): ...@@ -196,9 +196,9 @@ def do_load_submission_types():
$ tree -L 2 $ tree -L 2
. .
├── code-lsg ├── code-lsg
│ ├── a01-lsg.c │ ├── a01.c
│ ├── a02-lsg.c │ ├── a02.java
│ └── a03-lsg.c │ └── a03.hs
└── html └── html
├── a01.html ├── a01.html
├── a02.html ├── a02.html
...@@ -460,12 +460,12 @@ def start(): ...@@ -460,12 +460,12 @@ def start():
else: else:
call_loader(call_order[int(fid)]) call_loader(call_order[int(fid)])
except (EOFError, KeyboardInterrupt) as err: except (EOFError, KeyboardInterrupt):
print() print()
return return
except FileNotFoundError as err: except FileNotFoundError:
raise raise
except Exception as err: except Exception:
import traceback import traceback
traceback.print_exc() traceback.print_exc()
finally: finally:
......