diff --git a/.gitignore b/.gitignore index bc6f353..4b2fa93 100644 --- a/.gitignore +++ b/.gitignore @@ -12,3 +12,4 @@ coverage.xml env/ bin/ tmp/ +ghostdriver.log diff --git a/.travis.yml b/.travis.yml index 67d6f1e..bf99d94 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,8 +5,11 @@ python: install: - "pip install -r requirements.txt" - "pip install coveralls" +before_script: + - chmod +x ./tests/selenium/run.sh script: - - py.test -v --cov-report term-missing --cov=starter_weppy -r w tests + - py.test -v --cov-report term-missing --cov=starter_weppy -r w tests/client + - ./tests/selenium/run.sh after_success: - coveralls - coverage xml diff --git a/README.md b/README.md index b07f262..eec2403 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ [![Build Status](https://travis-ci.org/mijdavis2/starter_weppy.svg?branch=master)](https://travis-ci.org/mijdavis2/starter_weppy) [![Coverage Status](https://coveralls.io/repos/github/mijdavis2/starter_weppy/badge.svg?branch=master)](https://coveralls.io/github/mijdavis2/starter_weppy?branch=master) [![Codacy Badge](https://api.codacy.com/project/badge/Grade/3e6e8b44b40a4f12937557a794b7d6a3)](https://www.codacy.com/app/mdavis/starter_weppy?utm_source=github.com&utm_medium=referral&utm_content=mijdavis2/starter_weppy&utm_campaign=Badge_Grade) -[![Weppy Version](https://img.shields.io/badge/weppy-0.7.10-blue.svg)](https://github.com/gi0baro/weppy) +[![Weppy Version](https://img.shields.io/badge/weppy-0.8.2-blue.svg)](https://github.com/gi0baro/weppy) Starter Weppy is a python web application starter kit built on the [weppy framework](https://github.com/gi0baro/weppy). Current version is based on Weppy 0.7 with an MVC scaffolding. @@ -59,10 +59,23 @@ python run.py --dev See ```starter_weppy/cli.py``` for cli commands. ## Test + +Client testing: + +``` +py.test -v -s --cov-report term-missing --cov=starter_weppy -r w tests/client +``` + +Integration (selenium) testing: + ``` -py.test -v -s --cov-report term-missing --cov=starter_weppy -r w tests +./tests/selenium/run.sh ``` +## TODO + +- [ ] add test script that automatically runs test server + ## Caveats - The current setup.sh script is set to Python 3.5.2. Though I suggest upgrading to 3.5.2, you can replace PYTHON_VERSION with diff --git a/requirements.txt b/requirements.txt index 1eb2718..3410d30 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,6 +3,7 @@ codacy-coverage==1.2.12 coverage==4.0.3 pytest-cov==2.2.1 pytest==2.9.1 -weppy==0.7.10 +pytest-selenium==1.5.1 +selenium==3.0.1 +weppy==0.8.2 weppy-Haml==0.3 -wheel==0.29.0 diff --git a/run.py b/run.py index 44b3f24..f627661 100644 --- a/run.py +++ b/run.py @@ -17,13 +17,18 @@ def run_in_dev(): 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') + arg_parser.add_argument('-t', '--test', help="Run test server (setup dev users but squelch logging and reloader", + action='store_true') args = arg_parser.parse_args() - if args.dev: + if args.dev or args.test: from starter_weppy.dev_utils import setup_admin, setup_user TEST_ADMIN = setup_admin() TEST_USER = setup_user() print("Admin: {} \nUser: {}\n".format(TEST_ADMIN.as_dict(), TEST_USER.as_dict())) with run_in_dev(): - app.run() + if args.dev: + app.run() + else: + app.run(debug=False, reloader=False) else: app.run(host="0.0.0.0", debug=False) diff --git a/starter_weppy/views/_global_navbar.haml b/starter_weppy/views/_global_navbar.haml index b67a847..ffc463b 100644 --- a/starter_weppy/views/_global_navbar.haml +++ b/starter_weppy/views/_global_navbar.haml @@ -17,7 +17,7 @@ = T("Users") - if not current_user %li - %a{href: "{{=url('main.account', 'login')}}"} + %a{href: "{{=url('main.account', 'login')}}", id: "navbar-login"} = T("Login") - else %li diff --git a/starter_weppy/views/account.haml b/starter_weppy/views/account.haml index 4a27808..c2caad5 100644 --- a/starter_weppy/views/account.haml +++ b/starter_weppy/views/account.haml @@ -9,6 +9,6 @@ %a{href: "{{=url('main.account', 'register')}}"} Register Here - else - %h1 Profile + %h1{id:'loggedin-header'} Profile = form %br diff --git a/tests/client/__init__.py b/tests/client/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/api_test.py b/tests/client/api_test.py similarity index 89% rename from tests/api_test.py rename to tests/client/api_test.py index 362f39c..45bb949 100644 --- a/tests/api_test.py +++ b/tests/client/api_test.py @@ -1,5 +1,5 @@ import json -from .fixtures import client +from tests.fixtures import client def test_api_response(client): diff --git a/tests/client_test.py b/tests/client/client_test.py similarity index 94% rename from tests/client_test.py rename to tests/client/client_test.py index 57d6ffc..2ba21ed 100644 --- a/tests/client_test.py +++ b/tests/client/client_test.py @@ -1,6 +1,6 @@ from starter_weppy import User, db from starter_weppy import utils -from .fixtures import client, admin_client, logged_client, TEST_USER +from tests.fixtures import client, admin_client, logged_client, TEST_USER def test_welcome_page_access(client): diff --git a/tests/selenium/__init__.py b/tests/selenium/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/selenium/run.sh b/tests/selenium/run.sh new file mode 100644 index 0000000..43b7575 --- /dev/null +++ b/tests/selenium/run.sh @@ -0,0 +1,10 @@ +#!/usr/bin/env bash + +python run.py --test & + +sleep 1 + +py.test -v -s --driver PhantomJS tests/selenium +exit_code=$? + +pkill -9 -f run.py && exit ${exit_code} diff --git a/tests/selenium/selenium_test.py b/tests/selenium/selenium_test.py new file mode 100644 index 0000000..1686ef2 --- /dev/null +++ b/tests/selenium/selenium_test.py @@ -0,0 +1,18 @@ +from tests.fixtures import TEST_USER + + +def test_login(selenium): + selenium.implicitly_wait(10) + selenium.set_window_size(1124, 850) + selenium.get('http://127.0.0.1:8000') + selenium.find_element_by_id("navbar-login").click() + assert selenium.title == "StarterWeppy | Account" + email_input = selenium.find_element_by_id("email") + email_input.clear() + email_input.send_keys(TEST_USER.email) + password_input = selenium.find_element_by_id("password") + password_input.send_keys(TEST_USER.password) + login_btn = selenium.find_element_by_css_selector("form > div:nth-child(4) > input") + login_btn.click() + loggedin_header = selenium.find_element_by_id("loggedin-header") + assert loggedin_header.text == "Profile"