Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Workflows/backend/linting isnt applied recursively #25

Merged
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,6 @@ jobs:

- name: Run linting
working-directory: ./backend
run: pylint ./*/*.py
run: find . -type f -name "*.py" | xargs pylint


16 changes: 11 additions & 5 deletions backend/project/endpoints/index.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
"""Index api point"""
"""
This is the index endpoint file. It contains the index endpoint of the API as specified by OpenAPI.
"""

from flask import Blueprint
from flask_restful import Resource

index_bp = Blueprint("index", __name__)


class Index(Resource):
"""Api endpoint for the / route"""
"""
Subclass of restfull Resource, used to define the index endpoint of the API.
"""

def get(self):
"""Example of an api endpoint function that will respond to get requests made to /
return a json data structure with key Message and value Hello World!"""
return {"Message": "Hello World!"}
"""
Implementation of the GET method for the index endpoint. Returns the OpenAPI object.
"""

return {"Message": "Hello World!"}

index_bp.add_url_rule("/", view_func=Index.as_view("index"))
2 changes: 0 additions & 2 deletions backend/project/models/course_relations.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@

from sqlalchemy import Integer, Column, ForeignKey, PrimaryKeyConstraint, String
from project import db
from project.models.users import Users
from project.models.courses import Courses

class BaseCourseRelation(db.Model):
"""Base class for course relation models,
Expand Down
1 change: 0 additions & 1 deletion backend/project/models/courses.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
# pylint: disable=too-few-public-methods
from sqlalchemy import Integer, Column, ForeignKey, String
from project import db
from project.models.users import Users

class Courses(db.Model):
"""This class described the courses table,
Expand Down
1 change: 0 additions & 1 deletion backend/project/models/projects.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
# pylint: disable=too-few-public-methods
from sqlalchemy import ARRAY, Boolean, Column, DateTime, ForeignKey, Integer, String, Text
from project import db
from project.models.courses import Courses

class Projects(db.Model):
"""This class describes the projects table,
Expand Down
1 change: 0 additions & 1 deletion backend/project/models/submissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
# pylint: disable=too-few-public-methods
from sqlalchemy import Column,String,ForeignKey,Integer,CheckConstraint,DateTime,Boolean
from project import db
from project.models.users import Users

class Submissions(db.Model):
"""This class describes the submissions table,
Expand Down
2 changes: 2 additions & 0 deletions backend/pylintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[MASTER]
init-hook='import sys; sys.path.append(".")'
Empty file.
35 changes: 23 additions & 12 deletions backend/tests/models/conftest.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
"""

Configuration for the models tests. Contains all the fixtures needed for multiple models tests.
"""

import os
from datetime import datetime
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from datetime import datetime
from sqlalchemy.engine.url import URL
from dotenv import load_dotenv
import pytest
from project import db
from project.models.courses import Courses
from project.models.course_relations import CourseAdmins, CourseStudents
from project.models.projects import Projects
from project.models.submissions import Submissions
from project.models.users import Users
from sqlalchemy.engine.url import URL
from dotenv import load_dotenv
import pytest

load_dotenv()

Expand All @@ -35,6 +35,8 @@

@pytest.fixture
def db_session():
"""Create a new database session for a test.
After the test, all changes are rolled back and the session is closed."""
db.metadata.create_all(engine)
session = Session()
yield session
Expand All @@ -47,34 +49,40 @@ def db_session():

@pytest.fixture
def valid_user():
"""A valid user for testing"""
user = Users(uid="student", is_teacher=False, is_admin=False)
return user
return user

@pytest.fixture
def teachers():
"""A list of 10 teachers for testing"""
users = [Users(uid=str(i), is_teacher=True, is_admin=False) for i in range(10)]
return users

@pytest.fixture
def course_teacher():
"""A user that's a teacher for for testing"""
sel2_teacher = Users(uid="Bart", is_teacher=True, is_admin=False)
return sel2_teacher

@pytest.fixture
def course(course_teacher):
def course(course_teacher): # pylint: disable=redefined-outer-name ; fixture testing requires the same name to be used
"""A course for testing, with the course teacher as the teacher."""
sel2 = Courses(name="Sel2", teacher=course_teacher.uid)
return sel2

@pytest.fixture
def course_students():
"""A list of 5 students for testing."""
students = [
Users(uid="student_sel2_" + str(i), is_teacher=False, is_admin=False)
for i in range(5)
]
return students

@pytest.fixture
def course_students_relation(course,course_students):
def course_students_relation(course,course_students): # pylint: disable=redefined-outer-name
"""A list of 5 course relations for testing."""
course_relations = [
CourseStudents(course_id=course.course_id, uid=course_students[i].uid)
for i in range(5)
Expand All @@ -83,16 +91,19 @@ def course_students_relation(course,course_students):

@pytest.fixture
def assistent():
"""An assistent for testing."""
assist = Users(uid="assistent_sel2")
return assist

@pytest.fixture()
def course_admin(course,assistent):
def course_admin(course,assistent): # pylint: disable=redefined-outer-name ; fixture testing requires the same name to be used
"""A course admin for testing."""
admin_relation = CourseAdmins(uid=assistent.uid, course_id=course.course_id)
return admin_relation

@pytest.fixture()
def valid_project(course):
def valid_project():
"""A valid project for testing."""
deadline = datetime(2024, 2, 25, 12, 0, 0) # February 25, 2024, 12:00 PM
project = Projects(
title="Project",
Expand Down
8 changes: 5 additions & 3 deletions backend/tests/models/course_test.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Test module for the Courses model"""
import pytest
from sqlalchemy.exc import IntegrityError
from psycopg2.errors import ForeignKeyViolation
from project.models.courses import Courses
from project.models.users import Users
from project.models.course_relations import CourseAdmins, CourseStudents
Expand Down Expand Up @@ -47,7 +47,7 @@ def test_foreignkey_coursestudents_uid(
db_session.add_all(course_students_relation)
db_session.commit()

def test_correct_courserelations(
def test_correct_courserelations( # pylint: disable=too-many-arguments ; all arguments are needed for the test
self,
db_session,
course,
Expand All @@ -57,7 +57,9 @@ def test_correct_courserelations(
assistent,
course_admin,
):
"""Tests if we get the expected results for correct usage of CourseStudents and CourseAdmins"""
"""Tests if we get the expected results for
correct usage of CourseStudents and CourseAdmins"""

db_session.add(course_teacher)
db_session.commit()

Expand Down
17 changes: 11 additions & 6 deletions backend/tests/models/projects_and_submissions_test.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
"""This module tests the Projects and Submissions model"""
from datetime import datetime
import pytest
from sqlalchemy.exc import IntegrityError
from project.models.courses import Courses
from project.models.course_relations import CourseAdmins, CourseStudents
from project.models.projects import Projects
from project.models.submissions import Submissions
from project.models.users import Users

class TestProjectsAndSubmissionsModel:
def test_deadline(self,db_session,course,course_teacher,valid_project,valid_user):
class TestProjectsAndSubmissionsModel: # pylint: disable=too-few-public-methods
"""Test class for the database models of projects and submissions"""
def test_deadline(self,db_session, # pylint: disable=too-many-arguments ; all arguments are needed for the test
course,
course_teacher,
valid_project,
valid_user):
"""Tests if the deadline is correctly set
and if the submission is correctly connected to the project"""
db_session.add(course_teacher)
db_session.commit()
db_session.add(course)
Expand Down Expand Up @@ -55,4 +60,4 @@ def test_deadline(self,db_session,course,course_teacher,valid_project,valid_user
)
assert submission_check.grading == 15
assert submission.grading == 15
# Interesting! all the model objects are connected
# Interesting! all the model objects are connected
8 changes: 7 additions & 1 deletion backend/tests/models/users_test.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,25 @@
"""
This file contains the tests for the Users model.
"""
from project.models.users import Users


class TestUserModel:
"""Test class for the database models"""

def test_valid_user(self, db_session, valid_user):
"""Tests if a valid user can be added to the database."""
db_session.add(valid_user)
db_session.commit()
assert valid_user in db_session.query(Users).all()

def test_is_teacher(self, db_session, teachers):
"""Tests if the is_teacher field is correctly set to True
for the teachers when added to the database."""
db_session.add_all(teachers)
db_session.commit()
teacher_count = 0
for usr in db_session.query(Users).filter_by(is_teacher=True):
teacher_count += 1
assert usr.is_teacher
assert teacher_count == 10
assert teacher_count == 10