Skip to content

Commit

Permalink
Workflows/backend/linting isnt applied recursively (#25)
Browse files Browse the repository at this point in the history
* Fixes #24

* linting: added docs and removed trailing whitespaces

* fixed: linting

* added lint configuration file

* added special linting rules where necessary
  • Loading branch information
AronBuzogany authored Feb 24, 2024
1 parent bebf79a commit 4991b3f
Show file tree
Hide file tree
Showing 14 changed files with 71 additions and 37 deletions.
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"))
3 changes: 0 additions & 3 deletions backend/project/models/course_relations.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
"""Models for relation between users and courses"""
# pylint: disable=too-few-public-methods

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
3 changes: 1 addition & 2 deletions backend/project/models/courses.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
"""The Courses model"""
# 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
3 changes: 1 addition & 2 deletions backend/project/models/projects.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
"""Model for projects"""
# 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
3 changes: 1 addition & 2 deletions backend/project/models/submissions.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
"""Model for submissions"""
# 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: 1 addition & 1 deletion backend/project/models/users.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""Model for users"""
# pylint: disable=too-few-public-methods

from sqlalchemy import Boolean, Column, String
from project import db

Expand Down
10 changes: 10 additions & 0 deletions backend/pylintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[MASTER]
init-hook='import sys; sys.path.append(".")'

[test-files:*_test.py]
disable=
W0621, # Redefining name %r from outer scope (line %s)

[modules:project/modules/*]
disable=
R0903 # Too few public methods (modules don't require us to have public methods)
4 changes: 2 additions & 2 deletions backend/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ def app():
Returns:
Flask -- A Flask application instance
"""
app = create_app() # pylint: disable=redefined-outer-name ; fixture testing requires the same name to be used
app = create_app()
yield app

@pytest.fixture
def client(app): # pylint: disable=redefined-outer-name ; fixture testing requires the same name to be used
def client(app):
"""A fixture that creates a test client for the app.
Arguments:
app {Flask} -- A Flask application instance
Expand Down
Empty file.
29 changes: 20 additions & 9 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,26 +49,31 @@ 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):
"""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)
Expand All @@ -75,6 +82,7 @@ def course_students():

@pytest.fixture
def course_students_relation(course,course_students):
"""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):
"""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

0 comments on commit 4991b3f

Please sign in to comment.