Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
chr-peters committed Mar 13, 2021
0 parents commit df4713e
Show file tree
Hide file tree
Showing 11 changed files with 103 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .flaskenv
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
FLASK_APP=strong_but_simple_passwords
FLASK_ENV=development

SBSP_SECRET_KEY=something-secret
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
venv/
htmlcov/
.coverage
__pycache__/
*.egg-info
1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
graft strong_but_simple_passwords/templates
9 changes: 9 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -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"],
)
16 changes: 16 additions & 0 deletions strong_but_simple_passwords/__init__.py
Original file line number Diff line number Diff line change
@@ -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
8 changes: 8 additions & 0 deletions strong_but_simple_passwords/config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import os


def get_config_from_env_vars():
class Config:
SECRET_KEY = os.environ["SBSP_SECRET_KEY"]

return Config
13 changes: 13 additions & 0 deletions strong_but_simple_passwords/templates/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!DOCTYPE html>
<html>

<head>
<meta charset="utf-8">
<title>First test!</title>
</head>

<body>
This is a template!
</body>

</html>
5 changes: 5 additions & 0 deletions strong_but_simple_passwords/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from flask import render_template


def index():
return render_template("index.html")
17 changes: 17 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -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()
22 changes: 22 additions & 0 deletions tests/test_app.py
Original file line number Diff line number Diff line change
@@ -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
3 changes: 3 additions & 0 deletions tests/test_index.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
def test_index_http_ok(client):
response = client.get("/")
assert response.status_code == 200

0 comments on commit df4713e

Please sign in to comment.