Skip to content

Commit

Permalink
chore: linting
Browse files Browse the repository at this point in the history
  • Loading branch information
EwoutV committed Apr 9, 2024
1 parent aef4787 commit 48ed93b
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 24 deletions.
34 changes: 27 additions & 7 deletions backend/api/tests/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@
from authentication.models import Faculty, User


def create_faculty(name: str|int) -> Faculty:
def create_faculty(name: str | int) -> Faculty:
"""Create a Faculty with the given arguments."""
return Faculty.objects.create(id=name, name=name)

def create_user(id: str|int, first_name: str, last_name: str, email: str, faculty: list[Faculty] = None) -> User:

def create_user(id: str | int, first_name: str, last_name: str, email: str, faculty: list[Faculty] = None) -> User:
username = f"{first_name.lower()}{last_name.lower()}"

user = User.objects.create(
Expand All @@ -32,13 +33,24 @@ def create_user(id: str|int, first_name: str, last_name: str, email: str, facult

return user

def create_admin(id: str|int, first_name: str, last_name: str, email: str, faculty: list[Faculty] = None):

def create_admin(id: str | int, first_name: str, last_name: str, email: str, faculty: list[Faculty] = None):
"""Create an Admin with the given arguments."""
admin = create_user(id, first_name, last_name, email, faculty)
admin.make_admin()
return admin

def create_student(id: str|int, first_name: str, last_name: str, email: str, student_id: str = "", is_active: bool = True, faculty: list[Faculty] = None, courses: list[Course] = None) -> Student:

def create_student(
id: str | int,
first_name: str,
last_name: str,
email: str,
student_id: str = "",
is_active: bool = True,
faculty: list[Faculty] = None,
courses: list[Course] = None
) -> Student:
"""Create a student with the given arguments."""
username = f"{first_name.lower()}{last_name.lower()}"

Expand All @@ -63,6 +75,7 @@ def create_student(id: str|int, first_name: str, last_name: str, email: str, stu

return student


def create_assistant(id, first_name, last_name, email, is_active: bool = True, faculty=None, courses=None):
"""Create an assistant with the given arguments."""
username = f"{first_name.lower()}{last_name.lower()}"
Expand All @@ -87,6 +100,7 @@ def create_assistant(id, first_name, last_name, email, is_active: bool = True, f

return assistant


def create_teacher(id, first_name, last_name, email, is_active: bool = True, faculty=None, courses=None):
"""Create an assistant with the given arguments."""
username = f"{first_name.lower()}{last_name.lower()}"
Expand All @@ -111,10 +125,12 @@ def create_teacher(id, first_name, last_name, email, is_active: bool = True, fac

return assistant


def create_file_extension(extension):
"""Create a FileExtension with the given arguments."""
return FileExtension.objects.create(extension=extension)


def create_structure_check(name, project, obligated_extensions, blocked_extensions):
"""Create a StructureCheck with the given arguments."""
check = StructureCheck.objects.create(name=name, project=project)
Expand All @@ -127,7 +143,8 @@ def create_structure_check(name, project, obligated_extensions, blocked_extensio

return check

def create_project(name, description, days, course, max_score=5, group_size=5, visible=True, archived=False):

def create_project(name, description, days, course, max_score=5, group_size=5, visible=True, archived=False):
"""Create a Project with the given arguments."""
deadline = timezone.now() + timezone.timedelta(days=days)

Expand All @@ -142,7 +159,8 @@ def create_project(name, description, days, course, max_score=5, group_size=5,
group_size=group_size,
)

def create_course(name: str|int, academic_startyear: int, description: str = None, parent_course: Course = None) -> Course:

def create_course(name: str | int, academic_startyear: int, description: str = None, parent_course: Course = None) -> Course:
"""Create a Course with the given arguments."""
return Course.objects.create(
name=name,
Expand All @@ -151,10 +169,12 @@ def create_course(name: str|int, academic_startyear: int, description: str = Non
parent_course=parent_course,
)

def create_group(project: Project, score: int =0) -> Group:

def create_group(project: Project, score: int = 0) -> Group:
"""Create a Group with the given arguments."""
return Group.objects.create(project=project, score=score)


def create_submission(submission_number: int, group: Group, structure_checks_passed: bool) -> Submission:
"""Create a Submission with the given arguments."""

Expand Down
1 change: 0 additions & 1 deletion backend/api/tests/test_assistant.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ def test_activate_old(self):
# Assert that an active student exists with the user ID
self.assertTrue(Assistant.objects.filter(id=assistant.id, is_active=True).exists())


def test_deactivate(self):
"""Able to deactivate an existing student role"""
# Create the initial student
Expand Down
9 changes: 4 additions & 5 deletions backend/api/tests/test_checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,12 +147,11 @@ def test_structure_checks_exists(self):
Able to retrieve a single Checks after creating it.
"""
# Create a Checks instance with some file extensions
file_extension1 = create_file_extension( extension="jpg")
file_extension2 = create_file_extension( extension="png")
file_extension3 = create_file_extension( extension="tar")
file_extension4 = create_file_extension( extension="wfp")
file_extension1 = create_file_extension(extension="jpg")
file_extension2 = create_file_extension(extension="png")
file_extension3 = create_file_extension(extension="tar")
file_extension4 = create_file_extension(extension="wfp")
checks = create_structure_check(

name=".",
project=get_project(),
obligated_extensions=[file_extension1, file_extension4],
Expand Down
16 changes: 12 additions & 4 deletions backend/api/tests/test_course.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ def get_student():
"""
Return a random student to use in tests.
"""
return create_student(id=5, first_name="Simon", last_name="Mignolet", email="[email protected]", student_id="02000341")
return create_student(
id=5, first_name="Simon", last_name="Mignolet", email="[email protected]", student_id="02000341"
)


class CourseModelTests(APITestCase):
Expand Down Expand Up @@ -866,9 +868,15 @@ def test_create_individual_project(self):
course.teachers.add(self.user)

# Create some students
student1 = create_student(id=5, first_name="Simon", last_name="Mignolet", email="[email protected]", student_id="0100")
student2 = create_student(id=6, first_name="Ronny", last_name="Deila", email="[email protected]", student_id="0200")
student3 = create_student(id=7, first_name="Karel", last_name="Geraerts", email="[email protected]", student_id="0300")
student1 = create_student(
id=5, first_name="Simon", last_name="Mignolet", email="[email protected]", student_id="0100"
)
student2 = create_student(
id=6, first_name="Ronny", last_name="Deila", email="[email protected]", student_id="0200"
)
student3 = create_student(
id=7, first_name="Karel", last_name="Geraerts", email="[email protected]", student_id="0300"
)

# Add the students to the course
course.students.add(student1)
Expand Down
5 changes: 0 additions & 5 deletions backend/api/tests/test_file_structure.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ def tearDown(self):
def test_parsing(self):
course = create_course(name="test course", academic_startyear=2024)
project = create_project(

group_size=5,
max_score=10,
name="test",
Expand Down Expand Up @@ -173,7 +172,6 @@ def test_checking(self):
def test_checking_obligated_not_found(self):
course = create_course(name="test course", academic_startyear=2024)
project = create_project(

group_size=5,
max_score=10,
name="test",
Expand Down Expand Up @@ -241,7 +239,6 @@ def test_checking_obligated_not_found(self):
def test_checking_obligated_directory_not_found(self):
course = create_course(name="test course", academic_startyear=2024)
project = create_project(

group_size=5,
max_score=10,
name="test",
Expand Down Expand Up @@ -309,7 +306,6 @@ def test_checking_obligated_directory_not_found(self):
def test_checking_blocked_extension_found(self):
course = create_course(name="test course", academic_startyear=2024)
project = create_project(

group_size=5,
max_score=10,
name="test",
Expand Down Expand Up @@ -378,7 +374,6 @@ def test_checking_blocked_extension_found(self):
def test_checking_extra_directory_found(self):
course = create_course(name="test course", academic_startyear=2024)
project = create_project(

group_size=5,
max_score=10,
name="test",
Expand Down
6 changes: 4 additions & 2 deletions backend/api/tests/test_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
from api.models.project import Project
from api.models.student import Student
from api.models.teacher import Teacher
from api.tests.helpers import create_course, create_file_extension, create_project, create_group, create_submission, create_student, create_structure_check
from api.tests.helpers import create_course, create_file_extension, create_project, create_group, create_submission, \
create_student, create_structure_check
from authentication.models import User


Expand Down Expand Up @@ -534,7 +535,8 @@ def test_project_structure_checks_post_blocked_and_obligated(self):
{
"name": ".",
"obligated_extensions": [file_extension1.extension, file_extension4.extension],
"blocked_extensions": [file_extension1.extension, file_extension2.extension, file_extension3.extension]},
"blocked_extensions": [file_extension1.extension, file_extension2.extension,
file_extension3.extension]},
follow=True,
)

Expand Down
3 changes: 3 additions & 0 deletions backend/api/tests/test_submission.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,19 @@ def create_past_project(name, description, days, course, days_start_date):
name=name, description=description, deadline=deadline, course=course, score_visible=True, start_date=start_date
)


def create_submission(group, submission_number):
"""Create a Submission with the given arguments."""
return Submission.objects.create(
group=group, submission_number=submission_number, submission_time=timezone.now(), structure_checks_passed=True
)


def create_submission_file(submission, file):
"""Create an SubmissionFile with the given arguments."""
return SubmissionFile.objects.create(submission=submission, file=file)


class SubmissionModelTests(APITestCase):

def setUp(self) -> None:
Expand Down

0 comments on commit 48ed93b

Please sign in to comment.