Skip to content
This repository has been archived by the owner on Oct 1, 2020. It is now read-only.

Commit

Permalink
reorg tests, add some selenium tests
Browse files Browse the repository at this point in the history
  • Loading branch information
monty5811 committed Oct 13, 2015
1 parent 58dbfe0 commit 2f5920a
Show file tree
Hide file tree
Showing 12 changed files with 108 additions and 11 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,7 @@ target/
#
.idea/*
.c9/

.testmondata
.tmontmp/
.coverage*
10 changes: 10 additions & 0 deletions apostello/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from django.test import Client
from django.utils import timezone
from django.utils.timezone import get_current_timezone
from selenium import webdriver

from apostello.models import *

Expand Down Expand Up @@ -262,3 +263,12 @@ def users(recipients, keywords):
'c_out': c_out}

return objs


@pytest.mark.usefixtures("users")
@pytest.yield_fixture(scope='module')
def browser(request):
driver = webdriver.Firefox()

yield driver
driver.quit()
70 changes: 70 additions & 0 deletions apostello/tests/integration_tests/test_login.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import pytest


@pytest.mark.django_db
class TestLogin:
@pytest.mark.parametrize("uri", [
'/',
'/send/adhoc/',
'/send/group/',
'/group/all/',
'/group/new/',
'/group/edit/1/',
'/recipient/all/',
'/recipient/new/',
'/recipient/edit/1/',
'/keyword/all/',
'/keyword/new/',
'/keyword/edit/1/',
'/keyword/responses/1/',
'/keyword/responses/1/archive/',
'/keyword/responses/csv/1/',
'/incoming/',
'/outgoing/',
'/incoming/curate_wall/',
'/incoming/curate_wall/',
])
def test_not_logged_in(self, uri, live_server, browser, users):
browser.get(live_server + uri)
assert len(browser.find_elements_by_name('login')) == 1
assert len(browser.find_elements_by_name('password')) == 1
assert len(browser.find_elements_by_name('remember')) == 1

@pytest.mark.parametrize("uri", [
'/',
'/send/adhoc/',
'/send/group/',
'/group/all/',
'/group/new/',
'/group/edit/1/',
'/recipient/all/',
'/recipient/new/',
'/recipient/edit/1/',
'/keyword/all/',
'/keyword/new/',
'/keyword/edit/1/',
'/keyword/responses/1/',
'/keyword/responses/1/archive/',
'/keyword/responses/csv/1/',
'/incoming/',
'/outgoing/',
'/incoming/curate_wall/',
'/incoming/curate_wall/',
])
def test_log_in(self, uri, live_server, browser, users):
# login
browser.get(live_server + uri)
email_box = browser.find_elements_by_name('login')[0]
email_box.send_keys(users['staff'].email)
password_box = browser.find_elements_by_name('password')[0]
password_box.send_keys('top_secret')
login_button = browser.find_elements_by_xpath('html/body/div/div/div/form/button')[0]
login_button.click()
# check we have been redirected
assert live_server + uri in browser.current_url

# log out again
browser.get(live_server + '/accounts/logout')
logout_confirm = browser.find_elements_by_xpath('html/body/div/div/div/form/button')[0]
logout_confirm.click()
assert 'accounts/login' in browser.current_url
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# -*- coding: utf-8 -*-
import pytest

from ..models import Keyword, SmsInbound
from ..utils import fetch_default_reply
from apostello.models import Keyword, SmsInbound
from apostello.utils import fetch_default_reply


@pytest.mark.django_db
Expand Down Expand Up @@ -71,7 +71,7 @@ def test_no_match(self, keywords):
assert Keyword.match("nope") == 'No Match'

def test_get_log_link_keyword(self, keywords):
assert Keyword.get_log_link(keywords['test']) == '/keyword/responses/1/'
assert Keyword.get_log_link(keywords['test']) == '/keyword/responses/{0}/'.format(keywords['test'].pk)

def test_lookup_colour_test(self, keywords):
assert Keyword.lookup_colour('test') == '#098f6b'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from django.contrib.auth.models import User
from django.utils import timezone

from .. import models
from apostello import models


@pytest.mark.django_db
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def test_personalise(self, recipients):
assert recipients['calvin'].personalise('Hi %name%!') == 'Hi John!'

def test_get_abs_url(self, recipients):
assert recipients['calvin'].get_absolute_url() == '/recipient/edit/1/'
assert recipients['calvin'].get_absolute_url() == '/recipient/edit/{0}/'.format(recipients['calvin'].pk)

def test_archiving(self, recipients):
recipients['calvin'].archive()
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
3 changes: 3 additions & 0 deletions requirements.in
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,11 @@ pytest-env
pytest-flakes
pytest-isort
pytest-pep8
pytest-testmon
pytest-watch
pytest-xdist
python-dotenv
python3-memcached
requests
selenium
twilio
22 changes: 16 additions & 6 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,18 @@
amqp==1.4.7
anyjson==0.3.3
apipkg==1.4 # via execnet
argh==0.26.1 # via watchdog
billiard==3.3.0.20
celery==3.1.18
click==5.1 # via python-dotenv
coverage==4.0 # via pytest-cov
colorama==0.3.3 # via pytest-watch
coverage==3.7.1 # via pytest-cov, pytest-testmon
decorator==4.0.4 # via ipython, traitlets
defusedxml==0.4.1 # via python3-openid
django-allauth==0.23.0
django-appconf==1.0.1
django-bootstrap3==6.2.2
django-celery==3.1.16
django-celery==3.1.17
django-compressor==1.5
django-datetime-widget==0.9.3
django-debug-toolbar==1.4
Expand All @@ -26,6 +28,7 @@ django-solo==1.1.0
django-twilio==0.8.0
django==1.8.5
djangorestframework==3.2.4
docopt==0.6.2 # via pytest-watch
docutils==0.12
elvantoapi==1.3.3.2
execnet==1.4.1 # via pytest-cache, pytest-xdist
Expand All @@ -34,13 +37,15 @@ httplib2==0.9.2 # via twilio
ipython-genutils==0.1.0 # via traitlets
ipython==4.0.0
isort==4.2.2 # via pytest-isort
kombu==3.0.26 # via celery
kombu==3.0.28 # via celery
oauthlib==1.0.3 # via requests-oauthlib
opbeat==3.1.1
ordereddict==1.1 # via python-dotenv
path.py==8.1.2 # via pickleshare
pathtools==0.1.2 # via watchdog
pep8==1.6.2 # via pytest-pep8
pexpect==4.0.1 # via ipython
phonenumbers==7.0.11 # via django-phonenumber-field
phonenumbers==7.1.0 # via django-phonenumber-field
pickleshare==0.5 # via ipython
psycopg2==2.6.1
ptyprocess==0.5 # via pexpect
Expand All @@ -55,16 +60,21 @@ pytest-env==0.5.1
pytest-flakes==1.0.1
pytest-isort==0.1.0
pytest-pep8==1.0.6
pytest-testmon==0.7
pytest-watch==3.5.0
pytest-xdist==1.13.1
pytest==2.8.1
python-dotenv==0.1.3
pytest==2.8.2
python-dotenv==0.1.5
python3-memcached==1.51
python3-openid==3.0.7 # via django-allauth
pytz==2015.6 # via celery, django-datetime-widget, twilio
pyyaml==3.11 # via watchdog
requests-oauthlib==0.5.0 # via django-allauth
requests==2.8.0
selenium==2.48.0
simplegeneric==0.8.1 # via ipython
six==1.10.0 # via django-appconf, django-extensions, twilio
sqlparse==0.1.16 # via django-debug-toolbar
traitlets==4.0.0 # via ipython
twilio==4.6.0
watchdog==0.8.3 # via pytest-watch

0 comments on commit 2f5920a

Please sign in to comment.