Skip to content

Commit

Permalink
✅ Add selenium integration test for login
Browse files Browse the repository at this point in the history
💚 Fix travis script permissions
  • Loading branch information
mijdavis2 committed Nov 10, 2016
1 parent cf9a045 commit 1f19f9c
Show file tree
Hide file tree
Showing 13 changed files with 62 additions and 11 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -12,3 +12,4 @@ coverage.xml
env/
bin/
tmp/
ghostdriver.log
5 changes: 4 additions & 1 deletion .travis.yml
Expand Up @@ -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
Expand Down
17 changes: 15 additions & 2 deletions README.md
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions requirements.txt
Expand Up @@ -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
9 changes: 7 additions & 2 deletions run.py
Expand Up @@ -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)
2 changes: 1 addition & 1 deletion starter_weppy/views/_global_navbar.haml
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion starter_weppy/views/account.haml
Expand Up @@ -9,6 +9,6 @@
%a{href: "{{=url('main.account', 'register')}}"}
Register Here
- else
%h1 Profile
%h1{id:'loggedin-header'} Profile
= form
%br
Empty file added tests/client/__init__.py
Empty file.
2 changes: 1 addition & 1 deletion tests/api_test.py → 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):
Expand Down
2 changes: 1 addition & 1 deletion tests/client_test.py → 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):
Expand Down
Empty file added tests/selenium/__init__.py
Empty file.
10 changes: 10 additions & 0 deletions 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}
18 changes: 18 additions & 0 deletions 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"

0 comments on commit 1f19f9c

Please sign in to comment.