Skip to content
2 changes: 1 addition & 1 deletion App/controllers/coursesOfferedPerSem.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def addSemesterCourses(courseCode):
semCourses = CoursesOfferedPerSem(courseCode)
db.session.add(semCourses)
db.session.commit()
return course
return semCourses
else:
print("Course not found")

Expand Down
4 changes: 2 additions & 2 deletions App/models/prerequisites.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ def __init__(self, prereqCode, nameofCourse):
def get_json(self):
return{
'prereq_id': self.id,
'course_id': self.course_id,
'prerequisite_course': self.prereq_code,
'prerequisite_courseCode': self.prereq_courseCode,
'prerequisite_course':self.courseName
}
28 changes: 26 additions & 2 deletions App/tests/courses.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pytest, unittest
from App.models import Course
from App.controllers import create_course, courses_Sorted_byRating_Objects, get_course_by_courseCode
from App.models import Course, Prerequisites
from App.controllers import create_course, courses_Sorted_byRating_Objects, get_course_by_courseCode, create_prereq, getPrereqCodes
from App.main import create_app
from App.database import db, create_db

Expand Down Expand Up @@ -34,7 +34,22 @@ def test_course_json(self):
'Course Rating: ': rating,
'No. of Credits: ': credits
})


def test_new_prerequisite(self):
prereq=Prerequisites("INFO2605","Introduction to Information Technology Concepts")
assert prereq.prereq_courseCode=="INFO2605"

def test_prerequisite_toJSON(self):
prereq=Prerequisites("INFO2605","Introduction to Information Technology Concepts")
prereq_json=prereq.get_json()
self.assertDictEqual(prereq_json,{
'prereq_id': None,
'prerequisite_courseCode': 'INFO2605',
'prerequisite_course': 'Introduction to Information Technology Concepts'
})


@pytest.fixture(autouse=True, scope="module")
def empty_db():
app = create_app({'TESTING': True, 'SQLALCHEMY_DATABASE_URI': 'sqlite:///test.db'})
Expand Down Expand Up @@ -66,3 +81,12 @@ def test_courses_sorted_by_rating(self):

for i in range(len(sortedCourses) - 1):
self.assertLessEqual(sortedCourses[i].rating, sortedCourses[i + 1].rating)


def test_create_prerequisite(self):
create_course("MATH1115", "Fundamental Mathematics for the General Sciences 1",1,6,[])
create_course("MATH2250", "Industrial Statistics",4,3,[])

create_prereq("MATH1115","Industrial Statistics")
prereqs=getPrereqCodes("Industrial Statistics")
self.assertEqual(['MATH1115'],prereqs)
39 changes: 36 additions & 3 deletions App/tests/program.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import unittest, pytest
from App.models import Program
from App.models import Program, ProgramCourses
from App.main import create_app
from App.database import db, create_db
from App.controllers import create_program, get_program_by_name
from App.controllers import create_program, get_program_by_name,create_course, create_programCourse, get_all_programCourses, programCourses_SortedbyRating,programCourses_SortedbyHighestCredits

class ProgramUnitTests(unittest.TestCase):

Expand Down Expand Up @@ -34,6 +34,18 @@ def test_program_toJSON(self):
'Foundation Credits: ': foun_credits,
})

def test_new_program_course(self):
programcourse=ProgramCourses("1","INFO2605","2")
assert programcourse.code=="INFO2605"

def test_program_course_toJSON(self):
programcourse=ProgramCourses("1","INFO2605","2")
programcourse_json=programcourse.get_json()
self.assertDictEqual(programcourse_json,{'Program Course ID:':None, 'Program ID:':'1','Course Code: ':'INFO2605','Course Type: ':'2'})




@pytest.fixture(autouse=True, scope="module")
def empty_db():
app = create_app({'TESTING': True, 'SQLALCHEMY_DATABASE_URI': 'sqlite:///test.db'})
Expand All @@ -44,4 +56,25 @@ def empty_db():
class ProgramIntegrationTests(unittest.TestCase):
def test_create_program(self):
program = create_program("IT", 69, 15, 9)
assert get_program_by_name("IT") != None
assert get_program_by_name("IT") != None

def test_create_program_requirement(self):
create_course("MATH1115", "Fundamental Mathematics for the General Sciences 1",1,6,[])
create_course("MATH2250", "Industrial Statistics",4,3,[])
create_course("INFO2606", "Internship",1,6,[])

create_programCourse("IT","MATH1115",1)
program_courses=get_all_programCourses("IT")
assert any(course.code == "MATH1115" for course in program_courses)

def test_programCourses_sorted_by_credits(self):
create_programCourse("IT","INFO2606",2)
program=get_program_by_name("IT")
credits_sorted=programCourses_SortedbyHighestCredits(program.id)
self.assertListEqual(credits_sorted,['INFO2606', 'MATH1115'])

def test_programCourses_sorted_by_rating(self):
create_programCourse("IT","MATH2250",1)
program=get_program_by_name("IT")
rating_list=programCourses_SortedbyRating(program.id)
self.assertListEqual(rating_list,['MATH1115', 'INFO2606', 'MATH2250'])
4 changes: 2 additions & 2 deletions App/views/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ def login_action():
user = login(data['username'], data['password'])
if user:
login_user(user)
return 'user logged in!'
return 'bad username or password given', 401
return jsonify({"token":jwt_authenticate(data['username'],data['password'])})
return jsonify({"error":"invalid credentials"}), 401

@auth_views.route('/logout', methods=['GET'])
def logout_action():
Expand Down
4 changes: 2 additions & 2 deletions App/views/index.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from flask import Blueprint, redirect, render_template, request, send_from_directory, jsonify
from App.models import db
from App.controllers import (create_course, create_staff)
from App.controllers import (create_course, create_staff,createCoursesfromFile)

index_views = Blueprint('index_views', __name__, template_folder='../templates')

Expand All @@ -13,7 +13,7 @@ def init():
db.drop_all()
db.create_all()
create_staff("adminpass","999", "admin")
create_course('testData/courseData.csv')
createCoursesfromFile('testData/courseData.csv')
return jsonify(message='staff created, courses created, db initialized!')

@index_views.route('/health', methods=['GET'])
Expand Down
8 changes: 4 additions & 4 deletions App/views/staff.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from flask import Blueprint, render_template, jsonify, request, send_from_directory, flash, redirect, url_for
from flask_jwt_extended import jwt_required, current_user as jwt_current_user
from flask_login import current_user, login_required
from App.models import Program
from App.models import Program, ProgramCourses

from.index import index_views

Expand Down Expand Up @@ -29,7 +29,7 @@ def getOfferedCourses():
return jsonify({'message': 'You are unauthorized to perform this action. Please login with Staff credentials.'}), 401

listing=get_all_OfferedCodes()
return jsonify(listing), 200
return jsonify({'message':'Success', 'offered_courses':listing}), 200

@staff_views.route('/staff/program', methods=['POST'])
@login_required
Expand Down Expand Up @@ -103,7 +103,7 @@ def addProgramRequirements():
return jsonify({'message': 'Invalid course type. Core (1) Elective (2) Foundation (3)'}), 400

response=create_programCourse(name, code, num)
return jsonify({'message': response}), 200
return jsonify({'message': response.get_json()}), 200


@staff_views.route('/staff/addOfferedCourse', methods=['POST'])
Expand All @@ -125,6 +125,6 @@ def addCourse():

course = addSemesterCourses(courseCode)
if course:
return jsonify({'message': f"Course {courseCode} added"}), 200
return jsonify(course.get_json()), 200
else:
return jsonify({'message': "Course addition unsucessful"}), 400
2 changes: 1 addition & 1 deletion App/views/student.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def create_student_route():

student = get_student_by_id(student_id)
if student:
return jsonify({'Error': 'Student ID taken'}), 400
return jsonify({'Error': 'Student id found'}), 400

program = get_program_by_name(programname)
if not program:
Expand Down
3 changes: 2 additions & 1 deletion wsgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ def add_offered_course(code):
@click.argument("type", default="all")
def user_tests_command(type):
if type == "unit":
sys.exit(pytest.main(["-k", "UnitTests"]))
sys.exit(pytest.main(["-k", "UserUnitTests"]))
elif type == "int":
sys.exit(pytest.main(["-k", "UserIntegrationTests"]))
else:
Expand Down Expand Up @@ -265,6 +265,7 @@ def courses_tests_command(type):
sys.exit(pytest.main(["App/tests/studentCourseHistory.py"]))



app.cli.add_command(test)
#################################################################

Expand Down