From 7dec8520732712ff8b383537d9a7d41f9cf0cf30 Mon Sep 17 00:00:00 2001 From: Aron Buzogany Date: Fri, 23 Feb 2024 17:55:41 +0100 Subject: [PATCH 1/7] Fix #22 --- backend/project/__init__.py | 4 +- backend/project/endpoints/index.py | 10 ----- .../endpoints/index/OpenAPI_Object.json | 45 +++++++++++++++++++ backend/project/endpoints/index/index.py | 13 ++++++ 4 files changed, 60 insertions(+), 12 deletions(-) delete mode 100644 backend/project/endpoints/index.py create mode 100644 backend/project/endpoints/index/OpenAPI_Object.json create mode 100644 backend/project/endpoints/index/index.py diff --git a/backend/project/__init__.py b/backend/project/__init__.py index 98017b80..23a7ee90 100644 --- a/backend/project/__init__.py +++ b/backend/project/__init__.py @@ -2,8 +2,8 @@ This file is the base of the Flask API. It contains the basic structure of the API. """ -from flask import Flask, jsonify -from .endpoints.index import index_bp +from flask import Flask +from .endpoints.index.index import index_bp def create_app(): """ diff --git a/backend/project/endpoints/index.py b/backend/project/endpoints/index.py deleted file mode 100644 index b5536eaf..00000000 --- a/backend/project/endpoints/index.py +++ /dev/null @@ -1,10 +0,0 @@ -from flask import Blueprint -from flask_restful import Resource - -index_bp = Blueprint("index", __name__) - -class Index(Resource): - def get(self): - return {"Message": "Hello World!"} - -index_bp.add_url_rule("/", view_func=Index.as_view("index")) \ No newline at end of file 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..5d7a3bb1 --- /dev/null +++ b/backend/project/endpoints/index/index.py @@ -0,0 +1,13 @@ +from flask import Blueprint, send_from_directory +from flask_restful import Resource, Api +import os + +index_bp = Blueprint("index", __name__) +index_endpoint = Api(index_bp) + +class Index(Resource): + def get(self): + 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")) \ No newline at end of file From b7a9d444605b28dd82a4e24c5160099313ee99ef Mon Sep 17 00:00:00 2001 From: Aron Buzogany Date: Fri, 23 Feb 2024 20:07:19 +0100 Subject: [PATCH 2/7] moved endpoint tests to seperate folder --- backend/tests/{ => endpoints}/__init__.py | 0 backend/tests/{ => endpoints}/conftest.py | 0 backend/tests/{test_base.py => endpoints/index_test.py} | 0 3 files changed, 0 insertions(+), 0 deletions(-) rename backend/tests/{ => endpoints}/__init__.py (100%) rename backend/tests/{ => endpoints}/conftest.py (100%) rename backend/tests/{test_base.py => endpoints/index_test.py} (100%) diff --git a/backend/tests/__init__.py b/backend/tests/endpoints/__init__.py similarity index 100% rename from backend/tests/__init__.py rename to backend/tests/endpoints/__init__.py 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/test_base.py b/backend/tests/endpoints/index_test.py similarity index 100% rename from backend/tests/test_base.py rename to backend/tests/endpoints/index_test.py From cb62692d62508db055b4ba46fe46c88b19ed3a37 Mon Sep 17 00:00:00 2001 From: Aron Buzogany Date: Fri, 23 Feb 2024 20:08:05 +0100 Subject: [PATCH 3/7] added test to test if required field of openapi root object are present --- backend/tests/endpoints/index_test.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/backend/tests/endpoints/index_test.py b/backend/tests/endpoints/index_test.py index 803b8456..e432de9f 100644 --- a/backend/tests/endpoints/index_test.py +++ b/backend/tests/endpoints/index_test.py @@ -4,3 +4,10 @@ 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 \ No newline at end of file From 922fa0f62d487e3dcaf0b2d8ccf9a1ede7655c36 Mon Sep 17 00:00:00 2001 From: Aron Buzogany Date: Fri, 23 Feb 2024 20:18:24 +0100 Subject: [PATCH 4/7] added init file to support multi level module referencing --- backend/tests/__init__.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 backend/tests/__init__.py diff --git a/backend/tests/__init__.py b/backend/tests/__init__.py new file mode 100644 index 00000000..e69de29b From 7f099c0de0c5a03f236bc138205eebdd9cbf76ac Mon Sep 17 00:00:00 2001 From: Aron Buzogany Date: Sat, 24 Feb 2024 11:33:04 +0100 Subject: [PATCH 5/7] linting: fixed --- backend/project/endpoints/index/index.py | 2 +- backend/tests/endpoints/index_test.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/backend/project/endpoints/index/index.py b/backend/project/endpoints/index/index.py index a9829f38..ac76f624 100644 --- a/backend/project/endpoints/index/index.py +++ b/backend/project/endpoints/index/index.py @@ -1,7 +1,7 @@ """Index api point""" +import os from flask import Blueprint, send_from_directory from flask_restful import Resource, Api -import os index_bp = Blueprint("index", __name__) index_endpoint = Api(index_bp) diff --git a/backend/tests/endpoints/index_test.py b/backend/tests/endpoints/index_test.py index e432de9f..200fbaeb 100644 --- a/backend/tests/endpoints/index_test.py +++ b/backend/tests/endpoints/index_test.py @@ -10,4 +10,4 @@ def test_openapi_spec(client): response = client.get("/") response_json = response.json assert response_json["openapi"] is not None - assert response_json["info"] is not None \ No newline at end of file + assert response_json["info"] is not None From d18d982c4d1b7a6115030eceeb2349173edb77fe Mon Sep 17 00:00:00 2001 From: Aron Buzogany Date: Sat, 24 Feb 2024 11:39:22 +0100 Subject: [PATCH 6/7] linting: multi-line function docs ender on his own --- backend/project/endpoints/index/index.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/backend/project/endpoints/index/index.py b/backend/project/endpoints/index/index.py index ac76f624..1bfe67cb 100644 --- a/backend/project/endpoints/index/index.py +++ b/backend/project/endpoints/index/index.py @@ -10,8 +10,10 @@ 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!""" + """ + 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") From c3dd7b4b1d69eb835a7c2d3eb67e7890225e36db Mon Sep 17 00:00:00 2001 From: Aron Buzogany Date: Sat, 24 Feb 2024 11:41:38 +0100 Subject: [PATCH 7/7] linting: function docs should use 3 quatation marks --- backend/tests/endpoints/index_test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/tests/endpoints/index_test.py b/backend/tests/endpoints/index_test.py index 200fbaeb..5624bba7 100644 --- a/backend/tests/endpoints/index_test.py +++ b/backend/tests/endpoints/index_test.py @@ -6,7 +6,7 @@ def test_home(client): assert response.status_code == 200 def test_openapi_spec(client): - "Test whether the required fields of the openapi spec are present" + """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