Skip to content

Commit

Permalink
fix tests pep8
Browse files Browse the repository at this point in the history
  • Loading branch information
jeanphix committed Jan 12, 2015
1 parent df5c4d1 commit 65f72e6
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 28 deletions.
20 changes: 14 additions & 6 deletions tests/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ def echo(arg):
@app.route('/no-cache')
def no_cahce():
response = make_response("No cache for me.", 200)
response.headers['Cache-Control'] = 'no-store, no-cache, must-revalidate, post-check=0, pre-check=0'
response.headers['Cache-Control'] = (
'no-store, no-cache, must-revalidate, post-check=0, pre-check=0'
)
return response


Expand All @@ -45,21 +47,25 @@ def cookie():
resp.set_cookie('mycookies', 'mycookie value')
return resp


@app.route('/set/cookie')
def set_cookie():
resp = make_response('Response text')
resp.set_cookie('_path', value='/get/', path='/get/')
resp.set_cookie('_path_fail', value='/set/', path='/set/' )
resp.set_cookie('_domain', value='127.0.0.1' )
resp.set_cookie('_path_fail', value='/set/', path='/set/')
resp.set_cookie('_domain', value='127.0.0.1')
resp.set_cookie('_secure_fail', value='sslonly', secure=True)
resp.set_cookie('_expires', value='2147483647', expires=2147483647)
return resp


@app.route('/get/cookie')
def get_cookie():
cookies = { '_expires': '2147483647' \
, '_domain': '127.0.0.1' \
, '_path': '/get/'}
cookies = {
'_expires': '2147483647',
'_domain': '127.0.0.1',
'_path': '/get/',
}
# make sure only what we expect is received.
if cookies != request.cookies:
return make_response('FAIL')
Expand Down Expand Up @@ -106,10 +112,12 @@ def send_file():
return Response(open(os.path.join(os.path.dirname(__file__), 'static',
'foo.tar.gz'), 'r'), headers=h)


@app.route('/url-hash')
def url_hash():
return render_template('url_hash.html')


@app.route('/url-hash-header')
def url_hash_header():
response = make_response("Redirecting.", 302)
Expand Down
56 changes: 34 additions & 22 deletions tests/run.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-


import os
import logging
import unittest
import cookielib

from app import app
from ghost import GhostTestCase, Ghost
from ghost import GhostTestCase


PORT = 5000
Expand Down Expand Up @@ -49,13 +47,14 @@ def test_evaluate(self):

def test_extra_resource_content(self):
page, resources = self.ghost.open(base_url)
self.assertIn('globals alert',
resources[4].content)
self.assertIn('globals alert', resources[4].content)

def test_extra_resource_binaries(self):
page, resources = self.ghost.open(base_url)
self.assertEqual(resources[5].content.__class__.__name__,
'QByteArray')
self.assertEqual(
resources[5].content.__class__.__name__,
'QByteArray',
)

def test_wait_for_selector(self):
page, resources = self.ghost.open(base_url)
Expand Down Expand Up @@ -128,7 +127,10 @@ def test_global_exists(self):

def test_resource_headers(self):
page, resources = self.ghost.open(base_url)
self.assertEqual(page.headers['Content-Type'], 'text/html; charset=utf-8')
self.assertEqual(
page.headers['Content-Type'],
'text/html; charset=utf-8',
)

def test_click_link(self):
page, resources = self.ghost.open(base_url)
Expand All @@ -151,7 +153,7 @@ def test_save_load_cookies(self):
self.ghost.delete_cookies()
self.ghost.load_cookies('testcookie.txt')
self.ghost.open("%sget/cookie" % base_url)
self.assertTrue( 'OK' in self.ghost.content )
self.assertTrue('OK' in self.ghost.content)

def test_load_cookies_expire_is_none(self):
self.ghost.delete_cookies()
Expand Down Expand Up @@ -266,8 +268,10 @@ def test_set_field_value_checkbox_false(self):

def test_set_field_value_checkbox_multiple(self):
self.ghost.open(base_url)
self.ghost.set_field_value('[name=multiple-checkbox]',
'second choice')
self.ghost.set_field_value(
'[name=multiple-checkbox]',
'second choice',
)
value, resources = self.ghost.evaluate(
'document.getElementById("multiple-checkbox-first").checked')
self.assertEqual(value, False)
Expand All @@ -277,7 +281,7 @@ def test_set_field_value_checkbox_multiple(self):

def test_set_field_value_email(self):
expected = 'my@awesome.email'
self.ghost.open( base_url)
self.ghost.open(base_url)
self.ghost.set_field_value('[name=email]', expected)
value, resssources = self.ghost\
.evaluate('document.getElementById("email").value')
Expand All @@ -293,8 +297,7 @@ def test_set_field_value_text(self):

def test_set_field_value_radio(self):
self.ghost.open(base_url)
self.ghost.set_field_value('[name=radio]',
'first choice')
self.ghost.set_field_value('[name=radio]', 'first choice')
value, resources = self.ghost.evaluate(
'document.getElementById("radio-first").checked')
self.assertEqual(value, True)
Expand Down Expand Up @@ -322,23 +325,32 @@ def test_set_field_value_select(self):

def test_set_field_value_simple_file_field(self):
self.ghost.open(base_url)
self.ghost.set_field_value('[name=simple-file]',
os.path.join(os.path.dirname(__file__), 'static', 'blackhat.jpg'))
page, resources = self.ghost.call('form', 'submit',
expect_loading=True)
self.ghost.set_field_value(
'[name=simple-file]',
os.path.join(os.path.dirname(__file__), 'static', 'blackhat.jpg'),
)
page, resources = self.ghost.call(
'form',
'submit',
expect_loading=True,
)
file_path = os.path.join(
os.path.dirname(__file__), 'uploaded_blackhat.jpg')
self.assertTrue(os.path.isfile(file_path))
os.remove(file_path)

def test_basic_http_auth_success(self):
page, resources = self.ghost.open("%sbasic-auth" % base_url,
auth=('admin', 'secret'))
page, resources = self.ghost.open(
"%sbasic-auth" % base_url,
auth=('admin', 'secret'),
)
self.assertEqual(page.http_status, 200)

def test_basic_http_auth_error(self):
page, resources = self.ghost.open("%sbasic-auth" % base_url,
auth=('admin', 'wrongsecret'))
page, resources = self.ghost.open(
"%sbasic-auth" % base_url,
auth=('admin', 'wrongsecret'),
)
self.assertEqual(page.http_status, 401)

def test_unsupported_content(self):
Expand Down

0 comments on commit 65f72e6

Please sign in to comment.