Skip to content

Commit

Permalink
Release: v0.0.9 (#42)
Browse files Browse the repository at this point in the history
* fix: Enable CORS (#40)

* feat: Register endpoint (#39)

* feat: enpoint registration coverage 57%

Implementation of the registration endpoint, 57% coverage is achieved

* style: Fix formatter and linter warnings

* test: Use random data in register tests

* refactor: Update register endpoint according to the `.net` spec

* test: Fix broken test

---------

Co-authored-by: Antonio Donis <[email protected]>
Co-authored-by: Pedro Andrés Chaparro Quintero <[email protected]>
Co-authored-by: Pedro Andrés Chaparro Quintero <[email protected]>
Co-authored-by: Andrea Velasquez <[email protected]>
Co-authored-by: Andvelavi <[email protected]>
  • Loading branch information
6 people authored Oct 10, 2023
1 parent 0532440 commit 8417cac
Show file tree
Hide file tree
Showing 13 changed files with 121 additions and 5 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.

### 0.0.9 (2023-10-09)


### Features

* Register endpoint ([#39](https://github.com/hawks-atlanta/proxy-python/issues/39)) ([38392d4](https://github.com/hawks-atlanta/proxy-python/commit/38392d476c718eacc7e70e0bed98de08f2f1d186))

### 0.0.8 (2023-10-09)

### 0.0.7 (2023-10-09)
Expand Down
10 changes: 10 additions & 0 deletions CLI.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# CLI

This document describes how to use the service as a CLI tool.

## Environment variables

| Variable | Description | Example |
| ----------------- | ------------------------------------------------------ | ------------------------------------------ |
| `GATEWAY_BASEURL` | Base URL of the gateway | `https://gateway:8080` |
| `ALLOWED_ORIGINS` | An string with the allowed origins separated by commas | `https://example.com,https://example2.com` |
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ COPY . .
USER application
RUN pip install -r requirements.txt
ENV GATEWAY_BASEURL "http://gateway:8080"
ENV ALLOWED_ORIGINS "http://localhost:5173"
ENTRYPOINT ["python", "-m", "flask", "-A", "./main.py", "run", "--host", "0.0.0.0", "--port", "8080"]
4 changes: 2 additions & 2 deletions docs/spec.openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ paths:
application/json:
schema:
$ref: "#/components/schemas/statusResponse"
/register:
/account/register:
post:
tags:
- Authentication
Expand Down Expand Up @@ -577,7 +577,7 @@ components:
authorization:
type: object
properties:
jwt:
token:
type: string
fileDetails:
type: object
Expand Down
6 changes: 6 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
import flask
from flask_cors import CORS
from src.views import views
from src.config.environment import variables

app = flask.Flask(__name__)
app.register_blueprint(views)

allowed_origins_list = variables["ALLOWED_ORIGINS"].split(",")

CORS(app, resources={r"/*": {"origins": allowed_origins_list}})

if __name__ == "__main__":
app.run(debug=True)
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
"git-semver-tags": "^4.1.1",
"standard-version": "^9.5.0"
},
"version": "0.0.8"
"version": "0.0.9"
}
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,4 @@ urllib3==2.0.4
Werkzeug==2.3.7
wrapt==1.15.0
zeep==4.2.1
flask-cors==4.0.0
1 change: 1 addition & 0 deletions src/config/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@

variables = {
"GATEWAY_BASEURL": os.getenv("GATEWAY_BASEURL", "http://localhost:8080"),
"ALLOWED_ORIGINS": os.getenv("ALLOWED_ORIGINS", "http://localhost:5173"),
}
31 changes: 31 additions & 0 deletions src/controllers/_account_controllers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
from flask import request
from src.config.soap_client import soap_client


def register_handler():
try:
# Get JSON data from the request
data = request.json

if not data:
return {"msg": "No JSON data provided in the request"}, 400

username = data.get("username")
password = data.get("password")

if not username or not password:
return {"msg": "Required fields are missing in JSON data"}, 400

result = soap_client.service.account_register(
{"username": username, "password": password}
)

if result.auth is not None:
jwt = result.auth.token
return {"msg": "Register succeeded", "token": jwt}, 200

return {"msg": "Username already registered"}, 409

except Exception as e:
print("[Exception] register_handler ->", str(e))
return {"msg": "Internal error", "error": str(e)}, 500
2 changes: 2 additions & 0 deletions src/views/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import flask
from ._authentication_views import views as authentication_views
from ._account_views import views as account_views


# NOTE: Register all views / routes using the following blueprint
views = flask.Blueprint("views", __name__)


views.register_blueprint(authentication_views)
views.register_blueprint(account_views)
9 changes: 9 additions & 0 deletions src/views/_account_views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import flask
from src.controllers import _account_controllers

views = flask.Blueprint("account", __name__)


@views.route("/account/register", methods=["POST"])
def account_register():
return _account_controllers.register_handler()
48 changes: 48 additions & 0 deletions src/views/_account_views_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import json
from main import app
from src.lib.faker import fake_username, fake_password

register_test_data = {"username": fake_username(), "password": fake_password()}


def test_account_register_successful() -> None:
register_data = {
"username": register_test_data["username"],
"password": register_test_data["password"],
}
response = app.test_client().post("/account/register", json=register_data)
json_response = json.loads(response.data)

assert response.status_code == 200
assert json.loads(response.data)["msg"] == "Register succeeded"
assert json_response["token"] != ""


def test_account_register_missing_fields() -> None:
# Empty json
data = {}
response = app.test_client().post("/account/register", json=data)

assert response.status_code == 400
assert json.loads(response.data)["msg"] == "No JSON data provided in the request"

# Missing password
data = {"username": register_test_data["username"]}
response = app.test_client().post("/account/register", json=data)

assert response.status_code == 400
assert (
json.loads(response.data)["msg"] == "Required fields are missing in JSON data"
)


def test_account_register_Username_already_registered() -> None:
data = {
"username": register_test_data["username"],
"password": register_test_data["password"],
}
response = app.test_client().post("/account/register", json=data)
json_response = json.loads(response.data)

assert response.status_code == 409
assert json_response["msg"] == "Username already registered"

0 comments on commit 8417cac

Please sign in to comment.