Skip to content
Permalink
Browse files

Linting cleanup

  • Loading branch information...
lovett committed Oct 7, 2019
1 parent 2e079c4 commit 6bd55d76606c8d3b4b98e29cac1b9ab9e3683920
Showing with 22 additions and 9 deletions.
  1. +4 −4 plugins/geography_test.py
  2. +18 −5 testing/helpers.py
@@ -27,7 +27,7 @@ def side_effect(*args, **_):

if args[0] == "urlfetch:get":
fixture = json.loads(
helpers.getFixture("dbpedia-area-success.json")
helpers.get_fixture("dbpedia-area-success.json")
)
return [fixture]
return mock.DEFAULT
@@ -48,7 +48,7 @@ def side_effect(*args, **_):

if args[0] == "urlfetch:get":
fixture = json.loads(
helpers.getFixture("dbpedia-area-fail.json")
helpers.get_fixture("dbpedia-area-fail.json")
)
return [fixture]
return mock.DEFAULT
@@ -70,7 +70,7 @@ def side_effect(*args, **_):

if args[0] == "urlfetch:get":
fixture = json.loads(
helpers.getFixture("dbpedia-state-fail.json")
helpers.get_fixture("dbpedia-state-fail.json")
)
return [fixture]
return mock.DEFAULT
@@ -90,7 +90,7 @@ def side_effect(*args, **_):

if args[0] == "urlfetch:get":
fixture = json.loads(
helpers.getFixture("dbpedia-state-success.json")
helpers.get_fixture("dbpedia-state-success.json")
)
return [fixture]
return mock.DEFAULT
@@ -1,15 +1,19 @@
import cherrypy
import plugins.jinja
import random
"""Utility functions to make unit tests easier."""

import os.path
import tempfile
import cherrypy
import plugins.jinja
import apps.shared.main
from tools import negotiable

def getFixture(path):

def get_fixture(path):
"""Return the contents of a file in the fixtures directory."""
with open("testing/fixtures/" + path) as handle:
return handle.read()


def start_server(app):
"""Create a cherrypy server for testing with an app mounted at root
using method dispatch"""
@@ -48,31 +52,40 @@ def start_server(app):
cherrypy.tools.negotiable = negotiable.Tool()
cherrypy.engine.start()


def stop_server():
"""Shut down the cherrypy server used by the current test suite."""
cherrypy.engine.exit()


def response_is_html(res):
"""Test a response object for an HTML content type header"""
return header_is(res.headers, "Content-Type", "text/html;charset=utf-8")


def response_is_json(res):
"""Test a response object for an JSON content type header"""
return header_is(res.headers, "Content-Type", "application/json")


def response_is_text(res):
"""Test a response object for a plain text content type header"""
return header_is(res.headers, "Content-Type", "text/plain;charset=utf-8")


def header_is(headers, name, value):
"""Test a dict of headers for an expected name/value pair"""
try:
return headers[name] == value
except KeyError:
return false
return False


def html_var(called_mock, key):
"""Retrieve a template variable from the HTML portion of a response."""
return called_mock.call_args[0][0]["html"][1].get(key)


def text_var(called_mock):
"""Retrieve a template variable from the text portion of a response."""
return called_mock.call_args[0][0]["text"]

0 comments on commit 6bd55d7

Please sign in to comment.
You can’t perform that action at this time.