diff --git a/backend/project/__init__.py b/backend/project/__init__.py index 66435003..8b9f5f94 100644 --- a/backend/project/__init__.py +++ b/backend/project/__init__.py @@ -4,7 +4,7 @@ from flask import Flask from flask_sqlalchemy import SQLAlchemy -from .endpoints.index import index_bp +from .endpoints.index.index import index_bp db = SQLAlchemy() diff --git a/backend/project/endpoints/index.py b/backend/project/endpoints/index.py deleted file mode 100644 index 384cefd9..00000000 --- a/backend/project/endpoints/index.py +++ /dev/null @@ -1,23 +0,0 @@ -""" -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): - """ - Subclass of restfull Resource, used to define the index endpoint of the API. - """ - - def get(self): - """ - 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")) diff --git a/backend/project/endpoints/index/OpenAPI_Object.json b/backend/project/endpoints/index/OpenAPI_Object.json new file mode 100644 index 00000000..7243ff59 --- /dev/null +++ b/backend/project/endpoints/index/OpenAPI_Object.json @@ -0,0 +1,45 @@ +{ + "openapi": "3.1.0", + "info": { + "title": "Pigeonhole API", + "summary": "A project submission and grading API for University Ghent students and professors.", + "description": "The API built for the Pigeonhole application. It serves as an interface for student of University Ghent. They can submit solutions to projects created by their professors. Professors and their assistents can then review these submitions, grade them and define custom tests that automatically run on every submition. The API is built using the OpenAPI 3.1.0 specification.", + "version": "1.0.0", + "contact": { + "name": "Project discussion forum", + "url": "https://github.com/SELab-2/UGent-opgave/discussions", + "email": "Bart.Coppens@UGent.be" + }, + "x-authors": [ + { + "name": "Aron Buzogany", + "github": "https://github.com/AronBuzogany" + }, + { + "name": "Gerwoud Van den Eynden", + "github": "https://github.com/Gerwoud" + }, + { + "name": "Jarne Clauw", + "github": "https://github.com/JarneClauw" + }, + { + "name": "Siebe Vlietinck", + "github": "https://github.com/Vucis" + }, + { + "name": "Warre Provoost", + "github": "https://github.com/warreprovoost" + }, + { + "name": "Cedric Mekeirle", + "github": "https://github.com/JibrilExe" + }, + { + "name": "Matisse Sulzer", + "github": "https://github.com/Matisse-Sulzer" + } + ] + }, + "paths": [] +} diff --git a/backend/project/endpoints/index/index.py b/backend/project/endpoints/index/index.py new file mode 100644 index 00000000..1bfe67cb --- /dev/null +++ b/backend/project/endpoints/index/index.py @@ -0,0 +1,21 @@ +"""Index api point""" +import os +from flask import Blueprint, send_from_directory +from flask_restful import Resource, Api + +index_bp = Blueprint("index", __name__) +index_endpoint = Api(index_bp) + +class Index(Resource): + """Api endpoint for the / route""" + + 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! + """ + dir_path = os.path.dirname(os.path.realpath(__file__)) + return send_from_directory(dir_path, "OpenAPI_Object.json") + + +index_bp.add_url_rule("/", view_func=Index.as_view("index")) diff --git a/backend/tests/endpoints/__init__.py b/backend/tests/endpoints/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/backend/tests/conftest.py b/backend/tests/endpoints/conftest.py similarity index 100% rename from backend/tests/conftest.py rename to backend/tests/endpoints/conftest.py diff --git a/backend/tests/endpoints/index_test.py b/backend/tests/endpoints/index_test.py new file mode 100644 index 00000000..5624bba7 --- /dev/null +++ b/backend/tests/endpoints/index_test.py @@ -0,0 +1,13 @@ +"""Test the base routes of the application""" + +def test_home(client): + """Test whether the index page is accesible""" + response = client.get("/") + assert response.status_code == 200 + +def test_openapi_spec(client): + """Test whether the required fields of the openapi spec are present""" + response = client.get("/") + response_json = response.json + assert response_json["openapi"] is not None + assert response_json["info"] is not None diff --git a/backend/tests/test_base.py b/backend/tests/test_base.py deleted file mode 100644 index 803b8456..00000000 --- a/backend/tests/test_base.py +++ /dev/null @@ -1,6 +0,0 @@ -"""Test the base routes of the application""" - -def test_home(client): - """Test whether the index page is accesible""" - response = client.get("/") - assert response.status_code == 200