generated from iai-group/template-project
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature/32-Add-basic-Flask-endpoints (#34)
- Loading branch information
Showing
13 changed files
with
132 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -127,3 +127,10 @@ dmypy.json | |
|
||
# Pyre type checker | ||
.pyre/ | ||
|
||
# Node | ||
node_modules/ | ||
|
||
# VSCode | ||
.vscode | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
"""Server tests.""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"} |