Skip to content

Commit

Permalink
Feature/32-Add-basic-Flask-endpoints (#34)
Browse files Browse the repository at this point in the history
  • Loading branch information
IKostric authored Oct 27, 2023
1 parent bd2f6ab commit bda371a
Show file tree
Hide file tree
Showing 13 changed files with 132 additions and 1 deletion.
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,10 @@ dmypy.json

# Pyre type checker
.pyre/

# Node
node_modules/

# VSCode
.vscode

29 changes: 29 additions & 0 deletions pkg_api/server/__init__.py
Original file line number Diff line number Diff line change
@@ -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
11 changes: 11 additions & 0 deletions pkg_api/server/auth.py
Original file line number Diff line number Diff line change
@@ -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"}
10 changes: 10 additions & 0 deletions pkg_api/server/facts_management.py
Original file line number Diff line number Diff line change
@@ -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"}
10 changes: 10 additions & 0 deletions pkg_api/server/pkg_exploration.py
Original file line number Diff line number Diff line change
@@ -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"}
10 changes: 10 additions & 0 deletions pkg_api/server/service_management.py
Original file line number Diff line number Diff line change
@@ -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"}
4 changes: 3 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,6 @@ pre-commit
pydocstyle==6.1.1
toml
rdflib==6.3.2
pytest-cov
pytest-cov
Flask>=2.3.3
Flask-RESTful>=0.3.10
1 change: 1 addition & 0 deletions tests/pkg_api/server/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Server tests."""
17 changes: 17 additions & 0 deletions tests/pkg_api/server/conftest.py
Original file line number Diff line number Diff line change
@@ -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
8 changes: 8 additions & 0 deletions tests/pkg_api/server/test_auth.py
Original file line number Diff line number Diff line change
@@ -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"}
10 changes: 10 additions & 0 deletions tests/pkg_api/server/test_facts_management.py
Original file line number Diff line number Diff line change
@@ -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"
}
8 changes: 8 additions & 0 deletions tests/pkg_api/server/test_pkg_exploration.py
Original file line number Diff line number Diff line change
@@ -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"}
8 changes: 8 additions & 0 deletions tests/pkg_api/server/test_service_management.py
Original file line number Diff line number Diff line change
@@ -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"}

0 comments on commit bda371a

Please sign in to comment.