diff --git a/.flaskenv b/.flaskenv new file mode 100644 index 0000000..f5b59b8 --- /dev/null +++ b/.flaskenv @@ -0,0 +1,4 @@ +FLASK_APP=strong_but_simple_passwords +FLASK_ENV=development + +SBSP_SECRET_KEY=something-secret diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..7849652 --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +venv/ +htmlcov/ +.coverage +__pycache__/ +*.egg-info diff --git a/MANIFEST.in b/MANIFEST.in new file mode 100644 index 0000000..6069e45 --- /dev/null +++ b/MANIFEST.in @@ -0,0 +1 @@ +graft strong_but_simple_passwords/templates diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..84569af --- /dev/null +++ b/setup.py @@ -0,0 +1,9 @@ +from setuptools import setup, find_packages + +setup( + name="strong-but-simple-passwords", + version="0.1.0", + packages=find_packages(), + include_package_data=True, + install_requires=["flask"], +) diff --git a/strong_but_simple_passwords/__init__.py b/strong_but_simple_passwords/__init__.py new file mode 100644 index 0000000..9ed42a4 --- /dev/null +++ b/strong_but_simple_passwords/__init__.py @@ -0,0 +1,16 @@ +from flask import Flask +from .config import get_config_from_env_vars +from . import views + + +def create_app(config=None): + app = Flask(__name__) + + if config is None: + config = get_config_from_env_vars() + + app.config.from_object(config) + + app.add_url_rule("/", "index", view_func=views.index) + + return app diff --git a/strong_but_simple_passwords/config.py b/strong_but_simple_passwords/config.py new file mode 100644 index 0000000..d4e1834 --- /dev/null +++ b/strong_but_simple_passwords/config.py @@ -0,0 +1,8 @@ +import os + + +def get_config_from_env_vars(): + class Config: + SECRET_KEY = os.environ["SBSP_SECRET_KEY"] + + return Config diff --git a/strong_but_simple_passwords/templates/index.html b/strong_but_simple_passwords/templates/index.html new file mode 100644 index 0000000..93eaf34 --- /dev/null +++ b/strong_but_simple_passwords/templates/index.html @@ -0,0 +1,13 @@ + + + + + + First test! + + + + This is a template! + + + \ No newline at end of file diff --git a/strong_but_simple_passwords/views.py b/strong_but_simple_passwords/views.py new file mode 100644 index 0000000..b0de204 --- /dev/null +++ b/strong_but_simple_passwords/views.py @@ -0,0 +1,5 @@ +from flask import render_template + + +def index(): + return render_template("index.html") diff --git a/tests/conftest.py b/tests/conftest.py new file mode 100644 index 0000000..32ce5bf --- /dev/null +++ b/tests/conftest.py @@ -0,0 +1,17 @@ +import pytest +from strong_but_simple_passwords import create_app + + +class TestConfig: + SECRET_KEY = "something-secret" + TESTING = True + + +@pytest.fixture +def app(): + return create_app(TestConfig) + + +@pytest.fixture +def client(app): + return app.test_client() diff --git a/tests/test_app.py b/tests/test_app.py new file mode 100644 index 0000000..2a5e387 --- /dev/null +++ b/tests/test_app.py @@ -0,0 +1,22 @@ +from strong_but_simple_passwords import create_app +import os + + +def test_custom_config(): + class Config: + SECRET_KEY = "custom-secret-key" + TESTING = True + + app = create_app(Config) + + assert app.config["SECRET_KEY"] == "custom-secret-key" + assert app.testing + + +def test_config_from_env_vars(): + os.environ["SBSP_SECRET_KEY"] = "secret-key-from-env-var" + + app = create_app() + + assert app.config["SECRET_KEY"] == "secret-key-from-env-var" + assert not app.testing diff --git a/tests/test_index.py b/tests/test_index.py new file mode 100644 index 0000000..7cf2186 --- /dev/null +++ b/tests/test_index.py @@ -0,0 +1,3 @@ +def test_index_http_ok(client): + response = client.get("/") + assert response.status_code == 200