From 994bad056b57262294cf7a5036b6161d98b8576a Mon Sep 17 00:00:00 2001 From: awkawb Date: Mon, 22 Apr 2024 21:14:54 -0400 Subject: [PATCH] Initial commit --- .gitignore | 9 ++++++ Makefile | 11 ++++++++ README.md | 41 ++++++++++++++++++++++++++++ accounts/__init__.py | 9 ++++++ accounts/templates/login.html | 10 +++++++ accounts/templates/registration.html | 10 +++++++ accounts/views/__init__.py | 3 ++ accounts/views/login.py | 13 +++++++++ accounts/views/register.py | 14 ++++++++++ dev-server.py | 16 +++++++++++ shell.nix | 30 ++++++++++++++++++++ tests/README.md | 13 +++++++++ tests/__init__.py | 0 tests/config.py | 3 ++ tests/conftest.py | 19 +++++++++++++ tests/templates/README.md | 4 +++ tests/templates/base.html | 24 ++++++++++++++++ tests/templates/footer.html | 12 ++++++++ tests/templates/header.html | 17 ++++++++++++ tests/test_login.py | 12 ++++++++ tests/test_registration.py | 12 ++++++++ 21 files changed, 282 insertions(+) create mode 100644 .gitignore create mode 100644 Makefile create mode 100644 README.md create mode 100644 accounts/__init__.py create mode 100644 accounts/templates/login.html create mode 100644 accounts/templates/registration.html create mode 100644 accounts/views/__init__.py create mode 100644 accounts/views/login.py create mode 100644 accounts/views/register.py create mode 100755 dev-server.py create mode 100644 shell.nix create mode 100644 tests/README.md create mode 100644 tests/__init__.py create mode 100644 tests/config.py create mode 100644 tests/conftest.py create mode 100644 tests/templates/README.md create mode 100644 tests/templates/base.html create mode 100644 tests/templates/footer.html create mode 100644 tests/templates/header.html create mode 100644 tests/test_login.py create mode 100644 tests/test_registration.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d0cb38f --- /dev/null +++ b/.gitignore @@ -0,0 +1,9 @@ +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# Environment variables +.env +.flaskenv + diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..9e8a1bb --- /dev/null +++ b/Makefile @@ -0,0 +1,11 @@ +#### +# Target definitions +#### + + +# Development targets + +.PHONY: development-server +development-server: # Start a development server + python3 dev-server.py + diff --git a/README.md b/README.md new file mode 100644 index 0000000..2676479 --- /dev/null +++ b/README.md @@ -0,0 +1,41 @@ +# allpawcare-accounts + +Flask blueprint for All Paw Care website. + + +## Usage + +Include as a submodule or install as a package. + + +## What works + +Not much, at the moment. + + +## Work to be done + +- Database connection +- Database models + * Users + * Dogs + * Clients +- Login page +- Authentication +- Registration page +- Registration backend +- Installing as package + + +## Routes + +Routes handled by this blueprint. + +### /accounts/register + +Account registration and creation. + +### /accounts/login + +User login and authentication. + diff --git a/accounts/__init__.py b/accounts/__init__.py new file mode 100644 index 0000000..c1c4d63 --- /dev/null +++ b/accounts/__init__.py @@ -0,0 +1,9 @@ +from flask import Blueprint + +accounts = Blueprint('accounts', __name__, + template_folder='templates', + url_prefix='/accounts') + +# Placed here to avoid circular import error +from accounts import views + diff --git a/accounts/templates/login.html b/accounts/templates/login.html new file mode 100644 index 0000000..af44a18 --- /dev/null +++ b/accounts/templates/login.html @@ -0,0 +1,10 @@ +{% extends "base.html" %} + +{% set title %}Account Login{% endset %} + +{% block content %} +Login here +--------------- +Soon to come ;) +{% endblock %} + diff --git a/accounts/templates/registration.html b/accounts/templates/registration.html new file mode 100644 index 0000000..b0d1e12 --- /dev/null +++ b/accounts/templates/registration.html @@ -0,0 +1,10 @@ +{% extends "base.html" %} + +{% set title %}Account Registration{% endset %} + +{% block content %} +Register for an account +----------------------- +Soon to come ;) +{% endblock %} + diff --git a/accounts/views/__init__.py b/accounts/views/__init__.py new file mode 100644 index 0000000..6ba3881 --- /dev/null +++ b/accounts/views/__init__.py @@ -0,0 +1,3 @@ +from accounts.views import login +from accounts.views import register + diff --git a/accounts/views/login.py b/accounts/views/login.py new file mode 100644 index 0000000..3fe5aaf --- /dev/null +++ b/accounts/views/login.py @@ -0,0 +1,13 @@ +from flask import jsonify +from flask import render_template + +from accounts import accounts + +@accounts.route('/login', methods=['GET']) +def login(): + return render_template('login.html') + +@accounts.route('/login', methods=['POST']) +def authenticate(): + return jsonify({"message": "Login successful"}), 201 + diff --git a/accounts/views/register.py b/accounts/views/register.py new file mode 100644 index 0000000..1d1a3e8 --- /dev/null +++ b/accounts/views/register.py @@ -0,0 +1,14 @@ +from flask import jsonify +from flask import render_template + +from accounts import accounts + +@accounts.route('/register', methods=['GET']) +def sign_up(): + return render_template('registration.html') + +@accounts.route('/register', methods=['POST']) +def register(): + # Registration logic + return jsonify({"message": "Registration successful"}), 201 + diff --git a/dev-server.py b/dev-server.py new file mode 100755 index 0000000..1294454 --- /dev/null +++ b/dev-server.py @@ -0,0 +1,16 @@ +#! /usr/bin/env python3 + +from flask import Flask + +from accounts import accounts +from tests.config import TestConfig + +def create_app(): + accounts_app = Flask(__name__, template_folder='tests/templates') + accounts_app.register_blueprint(accounts) + accounts_app.config.from_object(TestConfig) + + return accounts_app + +if __name__ == '__main__': + create_app().run(debug=True) diff --git a/shell.nix b/shell.nix new file mode 100644 index 0000000..09f2cff --- /dev/null +++ b/shell.nix @@ -0,0 +1,30 @@ +{ pkgs ? import {} }: + + +with pkgs; +pkgs.mkShell { + nativeBuildInputs = [ + inlyne # markdown viewer + + # Python development environment + (python3.withPackages(ps: with ps; [ + # For blueprint configuration + python-dotenv + + # Testing + pytest + pytest-flask + + # web framework + flask + + # Database + alembic # migrations + flask-sqlalchemy # orm + sqlalchemy # orm + sqlite # driver + sqlite-utils # utilities + ])) + ]; +} + diff --git a/tests/README.md b/tests/README.md new file mode 100644 index 0000000..72e2e27 --- /dev/null +++ b/tests/README.md @@ -0,0 +1,13 @@ +# Testing + +Bugs and regressions don't stand a chance. + +## Templates + +[Templates](./templates) used for testing. + +## Development server + +The [script](./dev-server.py) is used to run a development server on the local +system for testing. + diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/config.py b/tests/config.py new file mode 100644 index 0000000..1324524 --- /dev/null +++ b/tests/config.py @@ -0,0 +1,3 @@ +class TestConfig(): + pass + diff --git a/tests/conftest.py b/tests/conftest.py new file mode 100644 index 0000000..ceea6cf --- /dev/null +++ b/tests/conftest.py @@ -0,0 +1,19 @@ +import pytest +from flask import Flask + +from accounts import accounts + +from .config import TestConfig + +@pytest.fixture(scope="module") +def accounts_app(): + accounts_app = Flask(__name__, template_folder='templates') + accounts_app.register_blueprint(accounts) + accounts_app.config.from_object(TestConfig) + + yield accounts_app + +@pytest.fixture(scope="module") +def client(accounts_app): + return accounts_app.test_client() + diff --git a/tests/templates/README.md b/tests/templates/README.md new file mode 100644 index 0000000..f070b89 --- /dev/null +++ b/tests/templates/README.md @@ -0,0 +1,4 @@ +# Mock application templates + +Jinja templates for testing can be found in this directory. + diff --git a/tests/templates/base.html b/tests/templates/base.html new file mode 100644 index 0000000..43125c8 --- /dev/null +++ b/tests/templates/base.html @@ -0,0 +1,24 @@ + + + + + + {{ title }} + + + + {% include "header.html" %} + +
+
+ {% block content %} + {% endblock %} +
+
+ + {% include "footer.html" %} + + + + + diff --git a/tests/templates/footer.html b/tests/templates/footer.html new file mode 100644 index 0000000..834983e --- /dev/null +++ b/tests/templates/footer.html @@ -0,0 +1,12 @@ +
+
+ +
+
+ diff --git a/tests/templates/header.html b/tests/templates/header.html new file mode 100644 index 0000000..bd5c04a --- /dev/null +++ b/tests/templates/header.html @@ -0,0 +1,17 @@ +
+ +
+ diff --git a/tests/test_login.py b/tests/test_login.py new file mode 100644 index 0000000..2d69bc6 --- /dev/null +++ b/tests/test_login.py @@ -0,0 +1,12 @@ +import pytest + +def test_login(client): + response = client.get('/accounts/login') + + assert response.status_code == 200 + +def test_authenticate(client): + response = client.post('/accounts/login') + + assert response.status_code == 201 + diff --git a/tests/test_registration.py b/tests/test_registration.py new file mode 100644 index 0000000..af22d9c --- /dev/null +++ b/tests/test_registration.py @@ -0,0 +1,12 @@ +import pytest + +def test_signup(client): + response = client.get('/accounts/register') + + assert response.status_code == 200 + +def test_registration(client): + response = client.post('/accounts/register') + + assert response.status_code == 201 +