-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'development' into backend/feature/root-endpoint
- Loading branch information
Showing
19 changed files
with
500 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,4 +7,5 @@ __pycache__/ | |
htmlcov/ | ||
docs/_build/ | ||
dist/ | ||
venv/ | ||
venv/ | ||
.env |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
FROM python:3.9-slim | ||
|
||
# Set the working directory | ||
WORKDIR /app | ||
|
||
# Copy the application code into the container | ||
COPY . /app | ||
|
||
# Install dependencies | ||
RUN apt-get update | ||
RUN apt-get install -y --no-install-recommends python3-pip | ||
RUN pip3 install --no-cache-dir -r requirements.txt -r dev-requirements.txt | ||
|
||
# Command to run the tests | ||
CMD ["pytest"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,12 @@ | ||
"""Main entry point for the application.""" | ||
from sys import path | ||
from os import getenv | ||
from dotenv import load_dotenv | ||
from project import create_app_with_db | ||
|
||
path.append(".") | ||
|
||
if __name__ == "__main__": | ||
from project import create_app | ||
app = create_app() | ||
load_dotenv() | ||
app = create_app_with_db(getenv("DB_HOST")) | ||
app.run(debug=True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
"""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, | ||
both course relation tables have a | ||
course_id of the course to wich someone is related and | ||
an uid of the related person""" | ||
|
||
__abstract__ = True | ||
|
||
course_id = Column(Integer, ForeignKey('courses.course_id'), nullable=False) | ||
uid = Column(String(255), ForeignKey("users.uid"), nullable=False) | ||
__table_args__ = ( | ||
PrimaryKeyConstraint("course_id", "uid"), | ||
) | ||
|
||
class CourseAdmins(BaseCourseRelation): | ||
"""Admin to course relation model""" | ||
|
||
__tablename__ = "course_admins" | ||
|
||
class CourseStudents(BaseCourseRelation): | ||
"""Student to course relation model""" | ||
|
||
__tablename__ = "course_students" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
"""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, | ||
a course has an id, name, optional ufora id and the teacher that created it""" | ||
|
||
__tablename__ = "courses" | ||
course_id = Column(Integer, primary_key=True) | ||
name = Column(String(50), nullable=False) | ||
ufora_id = Column(String(50), nullable=True) | ||
teacher = Column(String(255), ForeignKey("users.uid"), nullable=False) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
"""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, | ||
a projects has an id, a title, a description, | ||
an optional assignment file that can contain more explanation of the projects, | ||
an optional deadline, | ||
the course id of the course to which the project belongs, | ||
visible for students variable so a teacher can decide if the students can see it yet, | ||
archieved var so we can implement the archiving functionality, | ||
a test path,script name and regex experssions for automated testing""" | ||
|
||
__tablename__ = "projects" | ||
project_id = Column(Integer, primary_key=True) | ||
title = Column(String(50), nullable=False, unique=False) | ||
descriptions = Column(Text, nullable=False) | ||
assignment_file = Column(String(50)) | ||
deadline = Column(DateTime(timezone=True)) | ||
course_id = Column(Integer, ForeignKey("courses.course_id"), nullable=False) | ||
visible_for_students = Column(Boolean, nullable=False) | ||
archieved = Column(Boolean, nullable=False) | ||
test_path = Column(String(50)) | ||
script_name = Column(String(50)) | ||
regex_expressions = Column(ARRAY(String(50))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
"""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, | ||
submissions can be made to a project, a submission has | ||
and id, a uid from the user that uploaded it, | ||
the project id of the related project, | ||
an optional grading, | ||
the submission time, | ||
submission path, | ||
and finally the submission status | ||
so we can easily present in a list which submission succeeded the automated checks""" | ||
|
||
__tablename__ = "submissions" | ||
submission_id = Column(Integer, nullable=False, primary_key=True) | ||
uid = Column(String(255), ForeignKey("users.uid"), nullable=False) | ||
project_id = Column(Integer, ForeignKey("projects.project_id"), nullable=False) | ||
grading = Column(Integer, CheckConstraint("grading >= 0 AND grading <= 20")) | ||
submission_time = Column(DateTime(timezone=True), nullable=False) | ||
submission_path = Column(String(50), nullable=False) | ||
submission_status = Column(Boolean, nullable=False) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
"""Model for users""" | ||
# pylint: disable=too-few-public-methods | ||
from sqlalchemy import Boolean, Column, String | ||
from project import db | ||
|
||
|
||
class Users(db.Model): | ||
"""This class defines the users table, | ||
a user has an uid, | ||
is_teacher and is_admin booleans because a user | ||
can be either a student,admin or teacher""" | ||
|
||
__tablename__ = "users" | ||
uid = Column(String(255), primary_key=True) | ||
is_teacher = Column(Boolean) | ||
is_admin = Column(Boolean) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,5 @@ | ||
flask | ||
flask-restful | ||
flask-sqlalchemy | ||
python-dotenv | ||
psycopg2-binary |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#!/bin/bash | ||
|
||
# Run Docker Compose to build and start the services, and capture the exit code from the test runner service | ||
docker-compose -f tests.yaml up --build --exit-code-from test-runner | ||
|
||
# Store the exit code in a variable | ||
exit_code=$? | ||
|
||
# After the tests are finished, stop and remove the containers | ||
docker-compose -f tests.yaml down | ||
|
||
# Check the exit code to determine whether the tests passed or failed | ||
if [ $exit_code -eq 0 ]; then | ||
echo "Tests passed!" | ||
else | ||
echo "Tests failed!" | ||
fi | ||
|
||
# Exit with the same exit code as the test runner service | ||
exit $exit_code |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
version: '3.8' | ||
|
||
services: | ||
postgres: | ||
image: postgres:latest | ||
environment: | ||
POSTGRES_USER: test_user | ||
POSTGRES_PASSWORD: test_password | ||
POSTGRES_DB: test_database | ||
healthcheck: | ||
test: ["CMD-SHELL", "pg_isready -U test_user -d test_database"] | ||
interval: 5s | ||
timeout: 3s | ||
retries: 3 | ||
start_period: 5s | ||
|
||
test-runner: | ||
build: | ||
context: . | ||
dockerfile: Dockerfile.test | ||
depends_on: | ||
postgres: | ||
condition: service_healthy | ||
environment: | ||
POSTGRES_HOST: postgres # Use the service name defined in Docker Compose | ||
POSTGRES_USER: test_user | ||
POSTGRES_PASSWORD: test_password | ||
POSTGRES_DB: test_database | ||
volumes: | ||
- .:/app | ||
command: ["pytest"] |
Oops, something went wrong.