Skip to content

Commit

Permalink
Merge pull request #5 from Nneji123/testing-client
Browse files Browse the repository at this point in the history
Added automated tests
  • Loading branch information
Nneji123 committed Mar 23, 2023
2 parents ed104c1 + 9d67084 commit fa7d728
Show file tree
Hide file tree
Showing 33 changed files with 1,509 additions and 103 deletions.
2 changes: 1 addition & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

# DATABASE AND SERVER CONFIG
POSTGRES = "postgresql://postgres:password@url:port/database" # POST SERVER
SQLITE = "sqlite:///../database.db" # LOCATION OF SQLITE DATABASE
SQLITE = "sqlite:///./database.db" # LOCATION OF SQLITE DATABASE
SERVER_NAME="http://127.0.0.1:3000" # CHANGE THIS TO YOUR PRODUCTION SERVER LINK
SERVER_MODE="DEV" # CHANGE TO `PROD` TO ENABLE PRODUCTION READY SETTINGS
SERIAL="secret" # FOR GENERATING EMAIL HASHCODE
Expand Down
37 changes: 37 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Python Tests

on: [push]

jobs:
build:

runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, windows-latest]
python-version: ["3.8", "3.9", "3.10"]

steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Run build script
run: |
apt-get update && apt-get ffmpeg libsm6 build-essential cmake libxext6
pip install --upgrade setuptools
pip install dlib --verbose
cd src
pip install -r requirements.txt
shell: bash
- name: Install dependencies
run: |
cd tests
python -m pip install --upgrade pip
pip install pytest
- name: Test with pytest
uses: dariocurr/pytest-summary@main
with:
output: test-summary.md
paths: tests/**.py
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
.env
database.db
src/database.db
__pycache__/
.pytest_cache/
env/
instance/
*.pdf
Expand Down
52 changes: 52 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# Create virtual environment
.PHONY: venv

venv:
sh -c 'python -m venv env'


# Activate virtual environment
.PHONY: activate

activate:
sh -c 'source env/Scripts/activate'

# Lint files
.PHONY: lint

lint:
sh -c 'black src && isort src'

# Install requirements
.PHONY: install

install:
sh -c 'cd src && pip install -r requirements.txt'

# Run init script
.PHONY: init

init:
sh -c 'cd src && ./init.sh'

# Start application
.PHONY: start

start:
sh -c 'cd src && python app.py'

# Run tests
.PHONY: test

test:
pip install pytest pytest-html
sh -c 'cd src/tests && pytest . -W ignore::DeprecationWarning --verbose --html=report.html'

# Cleanup
.PHONY: clean

clean:
sh -c 'rm -rf env && cd src && rm -rf database.db'

# Default target
all: venv activate install init start
16 changes: 3 additions & 13 deletions src/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,10 @@ FROM nneji123/abuad-lms

WORKDIR /app

# RUN apt-get -y update && apt-get install -y \
# wget \
# ffmpeg \
# libsm6 \
# build-essential \
# cmake \
# libxext6

# RUN pip install --upgrade setuptools

# ADD ./requirements.txt /app/requirements.txt

ADD . /app

RUN python init.py
COPY /templates/admin/templates /usr/local/lib/python3.8/site-packages/flask_admin/templates/bootstrap4/admin/

RUN ./init.sh

CMD gunicorn -b 0.0.0.0:5000 --worker-class eventlet -w 1 app:app
16 changes: 8 additions & 8 deletions src/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,14 @@

from configurations.config import configs
from configurations.extensions import db, email, login_manager, socketio
from configurations.models import (Admins, AdminsView, Lecturers,
LecturersView, Students, StudentsView)
from configurations.models import (
Admins,
AdminsView,
Lecturers,
LecturersView,
Students,
StudentsView,
)
from views.custom_errors import custom_error
from views.index import CustomIndexView, index
from views.lecturer import lecturer
Expand Down Expand Up @@ -96,9 +102,3 @@ def load_user(user_id):
debug=configs[SERVER_MODE]["DEBUG"],
host="0.0.0.0",
)
# app.run(
# host="0.0.0.0",
# port=configs[SERVER_MODE]["PORT"],
# debug=configs[SERVER_MODE]["DEBUG"],
# threaded=True,
# )
2 changes: 1 addition & 1 deletion src/configurations/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

configs = {
"PROD": {
"SQLALCHEMY_DATABASE_URI": POSTGRES,
"SQLALCHEMY_DATABASE_URI": SQLITE,
"LOGIN_DISABLED": False,
"PORT": 5000,
"DEBUG": False,
Expand Down
51 changes: 34 additions & 17 deletions src/configurations/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@


import uuid
from datetime import datetime

from flask_admin import AdminIndexView
from flask_admin.contrib.sqla import ModelView
Expand All @@ -23,42 +24,58 @@

class Students(UserMixin, db.Model):
id = db.Column(db.String(36), primary_key=True, default=str(uuid.uuid4()))
username = db.Column(db.String(30), unique=True)
email = db.Column(db.String(50), unique=True)
password = db.Column(db.String)
matric_number = db.Column(db.String(120), unique=True)
role = db.Column(db.String(10))
hashCode = db.Column(db.String(120))
username = db.Column(db.String(50), unique=True, nullable=False)
email = db.Column(db.String(50), unique=True, nullable=False)
password = db.Column(db.String, nullable=False)
matric_number = db.Column(db.String(120), unique=True, nullable=False)
department = db.Column(db.String(120), nullable=False)
role = db.Column(db.String(10), nullable=False)
created_at = db.Column(db.DateTime, nullable=False, default=datetime.utcnow)
last_logged_in_at = db.Column(db.DateTime, nullable=True)
is_active = db.Column(db.Boolean, default=True)
hashCode = db.Column(db.String(120), nullable=True)

def check_password(self, password):
return check_password_hash(self.password, password)


class Lecturers(UserMixin, db.Model):
id = db.Column(db.String(36), primary_key=True, default=str(uuid.uuid4()))
username = db.Column(db.String(30), unique=True)
email = db.Column(db.String(50), unique=True)
password = db.Column(db.String)
role = db.Column(db.String(10))
hashCode = db.Column(db.String(120))
username = db.Column(db.String(30), unique=True, nullable=False)
email = db.Column(db.String(50), unique=True, nullable=False)
password = db.Column(db.String, nullable=False)
role = db.Column(db.String(10), nullable=False)
created_at = db.Column(db.DateTime, nullable=False, default=datetime.utcnow)
last_logged_in_at = db.Column(db.DateTime, nullable=True)
is_active = db.Column(db.Boolean, default=True)
hashCode = db.Column(db.String(120), nullable=True)

def check_password(self, password):
return check_password_hash(self.password, password)


class Admins(UserMixin, db.Model):
id = db.Column(db.String(36), primary_key=True, default=str(uuid.uuid4()))
username = db.Column(db.String(15), unique=True)
password = db.Column(db.String)
role = db.Column(db.String(10))
username = db.Column(db.String(15), unique=True, nullable=False)
password = db.Column(db.String, nullable=False)
role = db.Column(db.String(10), nullable=False)
is_admin = db.Column(db.Boolean, default=True)
created_at = db.Column(db.DateTime, nullable=False, default=datetime.utcnow)
last_logged_in_at = db.Column(db.DateTime, nullable=True)

def check_password(self, password):
return check_password_hash(self.password, password)


class StudentsView(ModelView):
column_searchable_list = ["username", "email", "matric_number"]
column_searchable_list = [
"username",
"email",
"matric_number",
"department",
"created_at",
"last_logged_in_at",
]
column_filters = ["username", "email", "matric_number"]
column_exclude_list = ["password", "hashCode"]

Expand All @@ -68,7 +85,7 @@ def on_model_change(self, form, model, is_created):


class LecturersView(ModelView):
column_searchable_list = ["username", "email"]
column_searchable_list = ["username", "email", "created_at", "last_logged_in_at"]
column_filters = ["username", "email"]
column_exclude_list = ["password", "hashCode"]

Expand All @@ -78,7 +95,7 @@ def on_model_change(self, form, model, is_created):


class AdminsView(ModelView):
column_searchable_list = ["username"]
column_searchable_list = ["username", "created_at", "last_logged_in_at"]
column_filters = ["username"]
column_exclude_list = ["password"]
form_excluded_columns = ["id"]
Expand Down

0 comments on commit fa7d728

Please sign in to comment.