diff --git a/.gitignore b/.gitignore index b6e4761..b140ee4 100644 --- a/.gitignore +++ b/.gitignore @@ -127,3 +127,10 @@ dmypy.json # Pyre type checker .pyre/ + +# Node +node_modules/ + +# VSCode +.vscode + diff --git a/pkg_api/server/__init__.py b/pkg_api/server/__init__.py new file mode 100644 index 0000000..ea1e08c --- /dev/null +++ b/pkg_api/server/__init__.py @@ -0,0 +1,29 @@ +"""The server module contains the Flask app and the API resources. + +Resources give access to HTTP methods related to a PKG API feature. +""" + +from flask import Flask +from flask_restful import Api + +from pkg_api.server.auth import AuthResource +from pkg_api.server.facts_management import PersonalFactsResource +from pkg_api.server.pkg_exploration import PKGExplorationResource +from pkg_api.server.service_management import ServiceManagementResource + + +def create_app() -> Flask: + """Create the Flask app and add the API resources. + + Returns: + The Flask app. + """ + app = Flask(__name__) + api = Api(app) + + api.add_resource(AuthResource, "/auth") + api.add_resource(ServiceManagementResource, "/service") + api.add_resource(PersonalFactsResource, "/facts") + api.add_resource(PKGExplorationResource, "/explore") + + return app diff --git a/pkg_api/server/auth.py b/pkg_api/server/auth.py new file mode 100644 index 0000000..e44d352 --- /dev/null +++ b/pkg_api/server/auth.py @@ -0,0 +1,11 @@ +"""Authentication resource.""" + +from typing import Dict + +from flask_restful import Resource + + +class AuthResource(Resource): + def get(self) -> Dict[str, str]: + """Returns the authentication data.""" + return {"message": "Prompt for login/signup"} diff --git a/pkg_api/server/facts_management.py b/pkg_api/server/facts_management.py new file mode 100644 index 0000000..e002d5d --- /dev/null +++ b/pkg_api/server/facts_management.py @@ -0,0 +1,10 @@ +"""Facts Management API Resource.""" +from typing import Dict + +from flask_restful import Resource + + +class PersonalFactsResource(Resource): + def get(self) -> Dict[str, str]: + """Returns the personal facts/preferences management data.""" + return {"message": "Personal Facts/Preferences Management"} diff --git a/pkg_api/server/pkg_exploration.py b/pkg_api/server/pkg_exploration.py new file mode 100644 index 0000000..3e011da --- /dev/null +++ b/pkg_api/server/pkg_exploration.py @@ -0,0 +1,10 @@ +"""PKG Exploration Resource.""" +from typing import Dict + +from flask_restful import Resource + + +class PKGExplorationResource(Resource): + def get(self) -> Dict[str, str]: + """Returns the data for PKG exploration.""" + return {"message": "PKG Exploration"} diff --git a/pkg_api/server/service_management.py b/pkg_api/server/service_management.py new file mode 100644 index 0000000..87769c0 --- /dev/null +++ b/pkg_api/server/service_management.py @@ -0,0 +1,10 @@ +"""Service Management API.""" +from typing import Dict + +from flask_restful import Resource + + +class ServiceManagementResource(Resource): + def get(self) -> Dict[str, str]: + """Returns the service management data.""" + return {"message": "Service Management"} diff --git a/requirements.txt b/requirements.txt index 032a9b4..8dfbe98 100644 --- a/requirements.txt +++ b/requirements.txt @@ -8,4 +8,6 @@ pre-commit pydocstyle==6.1.1 toml rdflib==6.3.2 -pytest-cov \ No newline at end of file +pytest-cov +Flask>=2.3.3 +Flask-RESTful>=0.3.10 \ No newline at end of file diff --git a/tests/pkg_api/server/__init__.py b/tests/pkg_api/server/__init__.py new file mode 100644 index 0000000..1f309b5 --- /dev/null +++ b/tests/pkg_api/server/__init__.py @@ -0,0 +1 @@ +"""Server tests.""" diff --git a/tests/pkg_api/server/conftest.py b/tests/pkg_api/server/conftest.py new file mode 100644 index 0000000..645dcec --- /dev/null +++ b/tests/pkg_api/server/conftest.py @@ -0,0 +1,17 @@ +"""Fixtures for the pkg_api.server package.""" +import pytest +from flask import Flask + +from pkg_api.server import create_app + + +@pytest.fixture +def client() -> Flask: + """Create the Flask test client and add the API resources. + + Yields: + The Flask client. + """ + app = create_app() + client = app.test_client() + yield client diff --git a/tests/pkg_api/server/test_auth.py b/tests/pkg_api/server/test_auth.py new file mode 100644 index 0000000..1b08cde --- /dev/null +++ b/tests/pkg_api/server/test_auth.py @@ -0,0 +1,8 @@ +"""Tests for the auth endpoints.""" + + +def test_auth_endpoint(client) -> None: + """Test the auth endpoint.""" + response = client.get("/auth") + assert response.status_code == 200 + assert response.get_json() == {"message": "Prompt for login/signup"} diff --git a/tests/pkg_api/server/test_facts_management.py b/tests/pkg_api/server/test_facts_management.py new file mode 100644 index 0000000..ddf73dc --- /dev/null +++ b/tests/pkg_api/server/test_facts_management.py @@ -0,0 +1,10 @@ +"""Tests for the facts management endpoints.""" + + +def test_facts_management_endpoint(client) -> None: + """Test the facts endpoint.""" + response = client.get("/facts") + assert response.status_code == 200 + assert response.get_json() == { + "message": "Personal Facts/Preferences Management" + } diff --git a/tests/pkg_api/server/test_pkg_exploration.py b/tests/pkg_api/server/test_pkg_exploration.py new file mode 100644 index 0000000..37800b9 --- /dev/null +++ b/tests/pkg_api/server/test_pkg_exploration.py @@ -0,0 +1,8 @@ +"""Tests for the pkg exploration endpoints.""" + + +def test_pkg_exploration_endpoint(client) -> None: + """Test the pkg exploration endpoint.""" + response = client.get("/explore") + assert response.status_code == 200 + assert response.get_json() == {"message": "PKG Exploration"} diff --git a/tests/pkg_api/server/test_service_management.py b/tests/pkg_api/server/test_service_management.py new file mode 100644 index 0000000..6fbc6be --- /dev/null +++ b/tests/pkg_api/server/test_service_management.py @@ -0,0 +1,8 @@ +"""Tests for the service management endpoints.""" + + +def test_service_management_endpoint(client) -> None: + """Test the service management endpoint.""" + response = client.get("/service") + assert response.status_code == 200 + assert response.get_json() == {"message": "Service Management"}