From 40d2d71fb3535c06fb3c9b4f80ea29fdecf95625 Mon Sep 17 00:00:00 2001 From: mijdavis2 Date: Sun, 24 Apr 2016 13:11:11 -0700 Subject: [PATCH] :new: DOCKERIZE starter weppy README.md edited online with Bitbucket :up: Update readme's python version --- .coveragerc | 2 +- Dockerfile | 12 ++--- README.md | 12 +++-- my_weppy_app/cli.py | 19 -------- requirements.txt | 6 +-- run.py | 8 ++-- setup.sh | 13 ++++-- {my_weppy_app => starter_weppy}/__init__.py | 8 ++-- starter_weppy/cli.py | 19 ++++++++ .../controllers/__init__.py | 0 .../controllers/api.py | 2 +- .../controllers/main.py | 12 ++--- {my_weppy_app => starter_weppy}/dev_utils.py | 12 ++--- .../models/__init__.py | 0 .../models/user.py | 0 .../static/bs3/bootstrap-theme.css | 0 .../static/bs3/bootstrap.min.css | 0 .../static/bs3/bootstrap.min.js | 0 .../static/images/favicon.ico | Bin .../templates/404.haml | 4 +- .../templates/account.haml | 0 .../templates/layout.haml | 6 +-- .../templates/profile.haml | 0 .../templates/users.haml | 0 .../templates/welcome.haml | 2 +- {my_weppy_app => starter_weppy}/utils.py | 0 tests/api_test.py | 8 +--- tests/client_test.py | 31 +++---------- tests/fixtures.py | 43 ++++++++++++++---- 29 files changed, 111 insertions(+), 108 deletions(-) delete mode 100644 my_weppy_app/cli.py rename {my_weppy_app => starter_weppy}/__init__.py (83%) create mode 100644 starter_weppy/cli.py rename {my_weppy_app => starter_weppy}/controllers/__init__.py (100%) rename {my_weppy_app => starter_weppy}/controllers/api.py (90%) rename {my_weppy_app => starter_weppy}/controllers/main.py (68%) rename {my_weppy_app => starter_weppy}/dev_utils.py (71%) rename {my_weppy_app => starter_weppy}/models/__init__.py (100%) rename {my_weppy_app => starter_weppy}/models/user.py (100%) rename {my_weppy_app => starter_weppy}/static/bs3/bootstrap-theme.css (100%) rename {my_weppy_app => starter_weppy}/static/bs3/bootstrap.min.css (100%) rename {my_weppy_app => starter_weppy}/static/bs3/bootstrap.min.js (100%) rename {my_weppy_app => starter_weppy}/static/images/favicon.ico (100%) rename {my_weppy_app => starter_weppy}/templates/404.haml (91%) rename {my_weppy_app => starter_weppy}/templates/account.haml (100%) rename {my_weppy_app => starter_weppy}/templates/layout.haml (89%) rename {my_weppy_app => starter_weppy}/templates/profile.haml (100%) rename {my_weppy_app => starter_weppy}/templates/users.haml (100%) rename {my_weppy_app => starter_weppy}/templates/welcome.haml (69%) rename {my_weppy_app => starter_weppy}/utils.py (100%) diff --git a/.coveragerc b/.coveragerc index 99db874..8943aaa 100644 --- a/.coveragerc +++ b/.coveragerc @@ -1,2 +1,2 @@ [run] -omit = my_weppy_app/cli.py,my_weppy_app/dev_utils.py \ No newline at end of file +omit = starter_weppy/cli.py,starter_weppy/dev_utils.py \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 3acdd1b..2919399 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,9 +1,3 @@ -FROM ubuntu:latest -MAINTAINER Michael J Davis "mdavisinsc@gmail.com" -RUN apt-get update -y -RUN apt-get install -y python-pip python-dev build-essential -COPY . /app -WORKDIR /app -RUN pip install -r requirements.txt -ENTRYPOINT ["python"] -CMD ["run.py"] \ No newline at end of file +FROM python:3.5-onbuild +EXPOSE 8000 +CMD ["python3", "./run.py"] diff --git a/README.md b/README.md index b46325c..d96a87f 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,7 @@ weppy" structure with an app name as an argument. ## Run Requirements: -- Python 2.7.11 +- Python 3.5.1 For automated pip and virtual env setup and creation, clone this repository and in your terminal do: @@ -40,6 +40,12 @@ pip install -r requirements.txt python run.py ``` +**Run in Docker** + +``` +docker build -t starter-weppy . +docker run -it -p 80:8000 --rm --name starter-weppy starter-weppy +``` ## Develop @@ -54,7 +60,7 @@ To start the app in development mode, do: python run.py --dev ``` -See ```my_weppy_app_/cli.py``` for cli commands. +See ```starter_weppy/cli.py``` for cli commands. ## Test @@ -64,5 +70,5 @@ testing. Run the app in dev mode. Then in another shell, do: ``` -py.test -v -s --cov-report term-missing --cov=my_weppy_app tests +py.test -v -s --cov-report term-missing --cov=starter_weppy tests ``` diff --git a/my_weppy_app/cli.py b/my_weppy_app/cli.py deleted file mode 100644 index ebf17c6..0000000 --- a/my_weppy_app/cli.py +++ /dev/null @@ -1,19 +0,0 @@ -""" -Usage: weppy --app=my_weppy_app -Example: weppy --app=my_weppy_app shell -""" -from my_weppy_app import app - - -@app.cli.command('routes') -def print_routing(): - print app.route.routes_out - - -@app.cli.command('get_users') -def print_users(): - from my_weppy_app import db - from my_weppy_app.models.user import User - rows = db(User.email).select() - for row in rows: - print row diff --git a/requirements.txt b/requirements.txt index 171ecda..75e014e 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,7 +1,7 @@ argparse==1.4.0 +coverage==4.0.3 pytest-cov==2.2.1 -weppy-BS3==0.4 -wsgiref==0.1.2 +pytest==2.9.1 +weppy==0.6.4 weppy-Haml==0.3 -weppy-Assets==0.3.1 wheel==0.29.0 diff --git a/run.py b/run.py index d2607a7..6ea0ae3 100644 --- a/run.py +++ b/run.py @@ -1,11 +1,11 @@ from contextlib import contextmanager from argparse import ArgumentParser -from my_weppy_app import app +from starter_weppy import app @contextmanager def run_in_dev(): - from my_weppy_app.dev_utils import setup_dev_users, remove_dev_users + from starter_weppy.dev_utils import setup_dev_users, remove_dev_users setup_dev_users() try: yield @@ -14,7 +14,7 @@ def run_in_dev(): if __name__ == "__main__": - arg_parser = ArgumentParser(description="MyWeppyApp running utility.") + arg_parser = ArgumentParser(description="StarterWeppy running utility.") arg_parser.add_argument('-d', '--dev', help="Setup add dev users and enable verbose logging", action='store_true') args = arg_parser.parse_args() @@ -22,4 +22,4 @@ def run_in_dev(): with run_in_dev(): app.run() else: - app.run(debug=False) + app.run(host="0.0.0.0", debug=False) diff --git a/setup.sh b/setup.sh index 7978c46..101da61 100644 --- a/setup.sh +++ b/setup.sh @@ -8,6 +8,9 @@ VERSION=0.1.0 USAGE='Usage: source setup.sh -hv -p "/path/to/python/" -r "repoName" -q "/path/to/requirements.txt"' +PY_MAJ_REQ=3 +PY_MIN_REQ=5 +PY_PAT_REQ=1 # --- Option processing -------------------------------------------- while getopts ":v:h:p:r:q:" o; do @@ -59,19 +62,19 @@ fi if [ ! "$PYTHON" ] then echo "No python version designated." - echo "Using machine's default python version" - PYTHON="$( which python )" + echo "Using machine's default python$PY_MAJ_REQ.$PY_MIN_REQ version" + PYTHON="$( which python"$PY_MAJ_REQ"."$PY_MIN_REQ" )" fi PMAJOR="$( "$PYTHON" -c 'import platform; major, minor, patch = platform.python_version_tuple(); print(major);' )" PMINOR="$( "$PYTHON" -c 'import platform; major, minor, patch = platform.python_version_tuple(); print(minor);' )" PPATCH="$( "$PYTHON" -c 'import platform; major, minor, patch = platform.python_version_tuple(); print(patch);' )" -if [[ "$PMAJOR" -eq 2 ]] && [[ "$PMINOR" -eq 7 ]] && [[ "$PPATCH" -gt 10 ]] +if [[ "$PMAJOR" -ge $PY_MAJ_REQ ]] && [[ "$PMINOR" -ge $PYMIN_REQ ]] && [[ "$PPATCH" -ge $PY_PAT_REQ ]] then echo "Python version is good enough: $PMAJOR.$PMINOR.$PPATCH." else - echo "Python version must be 2.7.11." + echo "Python version must be $PY_MAJ_REQ.$PY_MIN_REQ.$PY_PAT_REQ." echo "Yours is $PMAJOR.$PMINOR.$PPATCH :(" return 1 fi @@ -150,4 +153,4 @@ while read dependency; do fi done < "$REQUIREMENTS_DIR"/requirements.txt -export PYTHONPATH="$THIS_DIR":$HOME/.virtualenvs/"$REQUIRED_VENV"/lib/python2.7/site-packages:"$REQUIREMENTS_DIR" +export PYTHONPATH="$THIS_DIR":$HOME/.virtualenvs/"$REQUIRED_VENV"/lib/python"$PMAJOR"."$PMINOR"/site-packages:"$REQUIREMENTS_DIR" diff --git a/my_weppy_app/__init__.py b/starter_weppy/__init__.py similarity index 83% rename from my_weppy_app/__init__.py rename to starter_weppy/__init__.py index 92d587a..65b57b6 100644 --- a/my_weppy_app/__init__.py +++ b/starter_weppy/__init__.py @@ -16,7 +16,7 @@ app.language_write = True # init database and auth -from models.user import User +from starter_weppy.models.user import User # init auth before passing db models due to dependencies # on auth tables in the other models @@ -26,7 +26,7 @@ ) # adding sessions and authorization handlers -from utils import get_cryptogen_string +from starter_weppy.utils import get_cryptogen_string app.route.common_handlers = [ SessionCookieManager(get_cryptogen_string(16)), db.handler, @@ -40,7 +40,7 @@ app.use_extension(Haml) # Expose controllers -from controllers import main, api +from starter_weppy.controllers import main, api # Commands -import cli +from starter_weppy import cli diff --git a/starter_weppy/cli.py b/starter_weppy/cli.py new file mode 100644 index 0000000..bea3cbe --- /dev/null +++ b/starter_weppy/cli.py @@ -0,0 +1,19 @@ +""" +Usage: weppy --app=starter_weppy +Example: weppy --app=starter_weppy shell +""" +from starter_weppy import app + + +@app.cli.command('routes') +def print_routing(): + print(app.route.routes_out) + + +@app.cli.command('get_users') +def print_users(): + from starter_weppy import db + from starter_weppy.models.user import User + rows = db(User.email).select() + for row in rows: + print(row) diff --git a/my_weppy_app/controllers/__init__.py b/starter_weppy/controllers/__init__.py similarity index 100% rename from my_weppy_app/controllers/__init__.py rename to starter_weppy/controllers/__init__.py diff --git a/my_weppy_app/controllers/api.py b/starter_weppy/controllers/api.py similarity index 90% rename from my_weppy_app/controllers/api.py rename to starter_weppy/controllers/api.py index bae9a27..a6bbf5e 100644 --- a/my_weppy_app/controllers/api.py +++ b/starter_weppy/controllers/api.py @@ -1,6 +1,6 @@ from weppy import AppModule from weppy.tools import ServiceHandler -from my_weppy_app import app +from starter_weppy import app api = AppModule(app, 'api', __name__, url_prefix='api') api.common_handlers = [ServiceHandler('json')] diff --git a/my_weppy_app/controllers/main.py b/starter_weppy/controllers/main.py similarity index 68% rename from my_weppy_app/controllers/main.py rename to starter_weppy/controllers/main.py index 5dce001..178a942 100644 --- a/my_weppy_app/controllers/main.py +++ b/starter_weppy/controllers/main.py @@ -1,30 +1,30 @@ from weppy import response, url from weppy.tools import requires -from my_weppy_app import app, auth, db +from starter_weppy import app, auth, db @app.on_error(404) def error_404(): - response.meta.title = "MyWeppyApp-404" + response.meta.title = "StarterWeppy-404" return app.render_template("404.haml") @app.route("/") def welcome(): - response.meta.title = "MyWeppyApp" + response.meta.title = "StarterWeppy" return dict() @app.route('/account(/)?(/)?') def account(f, k): - response.meta.title = "MyWeppyApp | Account" + response.meta.title = "StarterWeppy | Account" form = auth(f, k) return dict(req=f, form=form) @app.route() def users(): - response.meta.title = "MyWeppyApp | Users" + response.meta.title = "StarterWeppy | Users" users = db(db.User.id > 0).select() return dict(users=users) @@ -33,6 +33,6 @@ def users(): @requires(auth.is_logged_in, url('main.account', 'login')) def profile(userid): user = db.User(id=userid) - response.meta.title = "MyWeppyApp | " + user.first_name + " " + \ + response.meta.title = "StarterWeppy | " + user.first_name + " " + \ user.last_name + " profile" return dict(user=user) diff --git a/my_weppy_app/dev_utils.py b/starter_weppy/dev_utils.py similarity index 71% rename from my_weppy_app/dev_utils.py rename to starter_weppy/dev_utils.py index 7f1bbe1..e0a50b0 100644 --- a/my_weppy_app/dev_utils.py +++ b/starter_weppy/dev_utils.py @@ -1,4 +1,4 @@ -from my_weppy_app import db +from starter_weppy import db from tests.fixtures import * @@ -16,15 +16,15 @@ def setup_dev_users(): password=TEST_USER.password ) db.commit() - print "Admin: {}\n" \ - "User: {}\n".format(admin.__dict__, user.__dict__) + print("Admin: {}\n" + "User: {}\n".format(admin.__dict__, user.__dict__)) def remove_dev_users(): - from my_weppy_app.models.user import User + from starter_weppy.models.user import User from tests.fixtures import TEST_ADMIN, TEST_USER - print db(User.email == TEST_ADMIN.email).select() - print db(User.email == TEST_USER.email).select() + print(db(User.email == TEST_ADMIN.email).select()) + print(db(User.email == TEST_USER.email).select()) db(User.email == TEST_ADMIN.email).delete() db(User.email == TEST_USER.email).delete() db.commit() diff --git a/my_weppy_app/models/__init__.py b/starter_weppy/models/__init__.py similarity index 100% rename from my_weppy_app/models/__init__.py rename to starter_weppy/models/__init__.py diff --git a/my_weppy_app/models/user.py b/starter_weppy/models/user.py similarity index 100% rename from my_weppy_app/models/user.py rename to starter_weppy/models/user.py diff --git a/my_weppy_app/static/bs3/bootstrap-theme.css b/starter_weppy/static/bs3/bootstrap-theme.css similarity index 100% rename from my_weppy_app/static/bs3/bootstrap-theme.css rename to starter_weppy/static/bs3/bootstrap-theme.css diff --git a/my_weppy_app/static/bs3/bootstrap.min.css b/starter_weppy/static/bs3/bootstrap.min.css similarity index 100% rename from my_weppy_app/static/bs3/bootstrap.min.css rename to starter_weppy/static/bs3/bootstrap.min.css diff --git a/my_weppy_app/static/bs3/bootstrap.min.js b/starter_weppy/static/bs3/bootstrap.min.js similarity index 100% rename from my_weppy_app/static/bs3/bootstrap.min.js rename to starter_weppy/static/bs3/bootstrap.min.js diff --git a/my_weppy_app/static/images/favicon.ico b/starter_weppy/static/images/favicon.ico similarity index 100% rename from my_weppy_app/static/images/favicon.ico rename to starter_weppy/static/images/favicon.ico diff --git a/my_weppy_app/templates/404.haml b/starter_weppy/templates/404.haml similarity index 91% rename from my_weppy_app/templates/404.haml rename to starter_weppy/templates/404.haml index ea3f836..6ad4d49 100644 --- a/my_weppy_app/templates/404.haml +++ b/starter_weppy/templates/404.haml @@ -19,7 +19,7 @@ %span.icon-bar %span.icon-bar %span.icon-bar - %a.navbar-brand{href: "{{=url('main.welcome')}}"} MyWeppyApp + %a.navbar-brand{href: "{{=url('main.welcome')}}"} StarterWeppy .collapse.navbar-collapse %ul.nav.navbar-nav %li @@ -34,6 +34,6 @@ %footer.footer.navbar.navbar-inverse.navbar-fixed-bottom .container{style: "padding-top:10px"} - %p.text-muted copyright MyWeppyApp 2016 + %p.text-muted copyright StarterWeppy 2016 - include_static 'bs3/bootstrap.min.js' diff --git a/my_weppy_app/templates/account.haml b/starter_weppy/templates/account.haml similarity index 100% rename from my_weppy_app/templates/account.haml rename to starter_weppy/templates/account.haml diff --git a/my_weppy_app/templates/layout.haml b/starter_weppy/templates/layout.haml similarity index 89% rename from my_weppy_app/templates/layout.haml rename to starter_weppy/templates/layout.haml index a021643..7777776 100644 --- a/my_weppy_app/templates/layout.haml +++ b/starter_weppy/templates/layout.haml @@ -21,7 +21,7 @@ %span.icon-bar %span.icon-bar %span.icon-bar - %a.navbar-brand{href: "{{=url('main.welcome')}}"} MyWeppyApp + %a.navbar-brand{href: "{{=url('main.welcome')}}"} StarterWeppy .collapse.navbar-collapse %ul.nav.navbar-nav %li @@ -40,7 +40,7 @@ - include %footer.footer.navbar.navbar-inverse.navbar-fixed-bottom - .container{style: "padding-top:10px"} - %p.text-muted copyright MyWeppyApp 2016 + .container{style: "padding-top:15px"} + %p.text-muted copyright StarterWeppy 2016 - include_static 'bs3/bootstrap.min.js' diff --git a/my_weppy_app/templates/profile.haml b/starter_weppy/templates/profile.haml similarity index 100% rename from my_weppy_app/templates/profile.haml rename to starter_weppy/templates/profile.haml diff --git a/my_weppy_app/templates/users.haml b/starter_weppy/templates/users.haml similarity index 100% rename from my_weppy_app/templates/users.haml rename to starter_weppy/templates/users.haml diff --git a/my_weppy_app/templates/welcome.haml b/starter_weppy/templates/welcome.haml similarity index 69% rename from my_weppy_app/templates/welcome.haml rename to starter_weppy/templates/welcome.haml index b501ede..c0b3058 100644 --- a/my_weppy_app/templates/welcome.haml +++ b/starter_weppy/templates/welcome.haml @@ -1,5 +1,5 @@ - extend "layout.haml" .container - %h1 Welcome to MyWeppyApp + %h1 Welcome to StarterWeppy %p Let's build something cool. diff --git a/my_weppy_app/utils.py b/starter_weppy/utils.py similarity index 100% rename from my_weppy_app/utils.py rename to starter_weppy/utils.py diff --git a/tests/api_test.py b/tests/api_test.py index 05e64bb..0efd20e 100644 --- a/tests/api_test.py +++ b/tests/api_test.py @@ -1,11 +1,5 @@ -import pytest import json -from my_weppy_app import app - - -@pytest.fixture() -def client(): - return app.test_client() +from tests.fixtures import * def test_api_response(client): diff --git a/tests/client_test.py b/tests/client_test.py index e9b73f1..ebd2d33 100644 --- a/tests/client_test.py +++ b/tests/client_test.py @@ -1,43 +1,26 @@ -import pytest -from my_weppy_app import app, db, User -from my_weppy_app import utils -from tests.fixtures import TEST_USER - - -@pytest.fixture() -def client(): - return app.test_client() +from starter_weppy import User, db +from starter_weppy import utils +from .fixtures import * def test_welcome_page_access(client): resp = client.get('/') - assert 'Welcome to MyWeppyApp' in resp.data + assert 'Welcome to StarterWeppy' in resp.data def test_error_404(client): resp = client.get(utils.get_cryptogen_string()) - assert "MyWeppyApp-404" in resp.data + assert "StarterWeppy-404" in resp.data def test_account_page_access(client): resp = client.get('/account/login') - assert "MyWeppyApp | Account" in resp.data + assert "StarterWeppy | Account" in resp.data def test_users_page_access(client): resp = client.get('/users/') - assert "MyWeppyApp | Users" in resp.data - - -@pytest.fixture() -def logged_client(client): - resp = client.get('/account/login') - client.post('/account/login', data={ - 'email': TEST_USER.email, - 'password': TEST_USER.password, - '_csrf_token': list(resp.context.session._csrf)[-1] - }, follow_redirects=True) - return client + assert "StarterWeppy | Users" in resp.data def test_login_page(logged_client): diff --git a/tests/fixtures.py b/tests/fixtures.py index fdb011b..73afbf4 100644 --- a/tests/fixtures.py +++ b/tests/fixtures.py @@ -1,4 +1,10 @@ -class TestUser(object): +import pytest +from weppy import session + +from starter_weppy import app + + +class UserMock(object): def __init__(self, email, first_name, last_name, password): self.email = email self.first_name = first_name @@ -6,18 +12,35 @@ def __init__(self, email, first_name, last_name, password): self.password = password def __str__(self): - print "Email: {}\n" \ - "First_Name: {}\n" \ - "Last_Name: {}\n" \ - "Password: {}\n".format(self.email, self.first_name, self.last_name, self.password) + print("Email: {}\n" + "First_Name: {}\n" + "Last_Name: {}\n" + "Password: {}\n".format(self.email, self.first_name, self.last_name, self.password)) -TEST_ADMIN = TestUser('test_admin@example.com', +TEST_ADMIN = UserMock('test_admin@example.com', 'TestAdminFirst', 'TestAdminLast', 'testadmin') -TEST_USER = TestUser('test_user@example.com', - 'TestUserFirst', - 'TestUserLast', - 'testuser') +TEST_USER = UserMock('test_user@example.com', + 'TestUserFirst', + 'TestUserLast', + 'testuser') + + +@pytest.fixture() +def client(): + return app.test_client() + + +@pytest.fixture() +def logged_client(): + user_client = app.test_client() + user_client.get("/account/login") + user_client.post('/account/login', data={ + 'email': TEST_USER.email, + 'password': TEST_USER.password, + '_csrf_token': list(session._csrf)[-1] + }, follow_redirects=True) + return user_client