Skip to content

Commit

Permalink
Upgrade mock usage across all tests to get them working again
Browse files Browse the repository at this point in the history
  • Loading branch information
lovett committed Dec 30, 2018
1 parent c744da5 commit dd41fde
Show file tree
Hide file tree
Showing 12 changed files with 38 additions and 36 deletions.
4 changes: 3 additions & 1 deletion apps/bookmarks/test_main.py
Expand Up @@ -30,7 +30,7 @@ def test_allow(self):
response = self.request("/", method="HEAD")
self.assertAllowedMethods(response, ("GET", "POST", "DELETE"))

@mock.patch("cherrypy.tools.negotiable._renderHtml")
@mock.patch("cherrypy.tools.negotiable.render_html")
@mock.patch("cherrypy.engine.publish")
def test_recent(self, publish_mock, render_mock):
"""If the database is empty, a no-records message is returned"""
Expand Down Expand Up @@ -61,6 +61,8 @@ def side_effect(*args, **_):
return [True]
return mock.DEFAULT

publish_mock.side_effect = side_effect

response = self.request("/", url="http://example.com", method="POST")

self.assertEqual(response.code, 204)
Expand Down
10 changes: 5 additions & 5 deletions apps/bounce/test_main.py
Expand Up @@ -111,7 +111,7 @@ def test_keyword_redution(self):
result = self.controller.host_to_keyword(pair[0])
self.assertEqual(result, pair[1])

@mock.patch("cherrypy.tools.negotiable._renderHtml")
@mock.patch("cherrypy.tools.negotiable.render_html")
@mock.patch("cherrypy.engine.publish")
def test_site_in_group(self, publish_mock, render_mock):
"""A request with a URL that belongs to known group returns
Expand Down Expand Up @@ -182,7 +182,7 @@ def side_effect(*args, **_):
"othersite"
)

@mock.patch("cherrypy.tools.negotiable._renderHtml")
@mock.patch("cherrypy.tools.negotiable.render_html")
@mock.patch("cherrypy.engine.publish")
def test_site_not_in_group(self, publish_mock, render_mock):
"""A request with a URL that belongs to known group but does not match
Expand Down Expand Up @@ -220,7 +220,7 @@ def side_effect(*args, **_):

self.assertEqual(len(bounces), 0)

@mock.patch("cherrypy.tools.negotiable._renderHtml")
@mock.patch("cherrypy.tools.negotiable.render_html")
@mock.patch("cherrypy.engine.publish")
def test_unrecognized_site(self, publish_mock, render_mock):
"""A URL that does not belong to known group returns a form."""
Expand Down Expand Up @@ -254,7 +254,7 @@ def side_effect(*args, **_):
helpers.html_var(render_mock, "bounces")
)

@mock.patch("cherrypy.tools.negotiable._renderHtml")
@mock.patch("cherrypy.tools.negotiable.render_html")
@mock.patch("cherrypy.engine.publish")
def test_bookmarklet_url_https(self, publish_mock, render_mock):
"""The bookmarklet URL respects HTTPS."""
Expand All @@ -281,7 +281,7 @@ def side_effect(*args, **_):
helpers.html_var(render_mock, "app_url").startswith("https")
)

@mock.patch("cherrypy.tools.negotiable._renderHtml")
@mock.patch("cherrypy.tools.negotiable.render_html")
@mock.patch("cherrypy.engine.publish")
def test_departing_site(self, publish_mock, render_mock):
"""If the given URL matches a record in the registry, it is considered
Expand Down
2 changes: 1 addition & 1 deletion apps/calls/test_main.py
Expand Up @@ -63,7 +63,7 @@ def side_effect(*args, **_):
offset=0
)

@mock.patch("cherrypy.tools.negotiable._renderHtml")
@mock.patch("cherrypy.tools.negotiable.render_html")
@mock.patch("cherrypy.engine.publish")
def test_pagination(self, publish_mock, render_mock):
"""The call list supports pagination"""
Expand Down
2 changes: 1 addition & 1 deletion apps/captures/test_main.py
Expand Up @@ -31,7 +31,7 @@ def test_allow(self):
response = self.request("/", method="HEAD")
self.assertAllowedMethods(response, ("GET",))

@mock.patch("cherrypy.tools.negotiable._renderHtml")
@mock.patch("cherrypy.tools.negotiable.render_html")
@mock.patch("cherrypy.engine.publish")
def test_search_by_path(self, publish_mock, render_mock):
"""Captures can be searched by path"""
Expand Down
8 changes: 4 additions & 4 deletions apps/grids/test_main.py
Expand Up @@ -29,7 +29,7 @@ def test_allow(self):
response = self.request("/", method="HEAD")
self.assertAllowedMethods(response, ("GET",))

@mock.patch("cherrypy.tools.negotiable._renderHtml")
@mock.patch("cherrypy.tools.negotiable.render_html")
@mock.patch("cherrypy.engine.publish")
def test_month_layout(self, publish_mock, render_mock):
"""The first two columns of a template with layout=month are Date and
Expand All @@ -51,7 +51,7 @@ def side_effect(*args, **_):
['Date', 'Day', 'Column 1', 'Column 2', 'Column 3']
)

@mock.patch("cherrypy.tools.negotiable._renderHtml")
@mock.patch("cherrypy.tools.negotiable.render_html")
@mock.patch("cherrypy.engine.publish")
def test_month_layout_invalid_start(self, publish_mock, render_mock):
"""An invalid start date for a monthly layout is handled gracefully"""
Expand All @@ -74,7 +74,7 @@ def side_effect(*args, **_):
first_of_current_month.strftime("%b %-d, %Y")
)

@mock.patch("cherrypy.tools.negotiable._renderHtml")
@mock.patch("cherrypy.tools.negotiable.render_html")
@mock.patch("cherrypy.engine.publish")
def test_plain_layout(self, publish_mock, render_mock):
"""No additional columns are added to a plain-layout template"""
Expand All @@ -94,7 +94,7 @@ def side_effect(*args, **_):
['Column A', 'Column B']
)

@mock.patch("cherrypy.tools.negotiable._renderHtml")
@mock.patch("cherrypy.tools.negotiable.render_html")
@mock.patch("cherrypy.engine.publish")
def test_default_view(self, publish_mock, render_mock):
"""The default view of the app is a list of available templates"""
Expand Down
8 changes: 4 additions & 4 deletions apps/ip/test_main.py
Expand Up @@ -28,7 +28,7 @@ def test_allow(self):
response = self.request("/", method="HEAD")
self.assertAllowedMethods(response, ("GET",))

@mock.patch("cherrypy.tools.negotiable._renderHtml")
@mock.patch("cherrypy.tools.negotiable.render_html")
@mock.patch("cherrypy.engine.publish")
def test_returns_html(self, publish_mock, render_mock):
"""GET returns text/html by default"""
Expand All @@ -54,7 +54,7 @@ def side_effect(*args, **_):
"127.0.0.1"
)

@mock.patch("cherrypy.tools.negotiable._renderJson")
@mock.patch("cherrypy.tools.negotiable.render_json")
@mock.patch("cherrypy.engine.publish")
def test_returns_json(self, publish_mock, render_mock):
"""GET returns application/json if requested"""
Expand All @@ -76,7 +76,7 @@ def side_effect(*args, **_):
"1.1.1.1"
)

@mock.patch("cherrypy.tools.negotiable._renderText")
@mock.patch("cherrypy.tools.negotiable.render_text")
@mock.patch("cherrypy.engine.publish")
def test_returns_text(self, publish_mock, render_mock):
"""GET returns text/plain if requested"""
Expand All @@ -94,7 +94,7 @@ def side_effect(*args, **_):

self.assertTrue("external_ip=1.1.1.1" in helpers.text_var(render_mock))

@mock.patch("cherrypy.tools.negotiable._renderHtml")
@mock.patch("cherrypy.tools.negotiable.render_html")
@mock.patch("cherrypy.engine.publish")
def test_honors_xreal_ip(self, publish_mock, render_mock):
"""The X-Real-IP header takes precedence over Remote-Addr"""
Expand Down
8 changes: 4 additions & 4 deletions apps/later/test_main.py
Expand Up @@ -39,7 +39,7 @@ def test_populates_title(self):
response = self.request("/", title=sample[0])
self.assertTrue(sample[1] in response.body)

@mock.patch("cherrypy.tools.negotiable._renderHtml")
@mock.patch("cherrypy.tools.negotiable.render_html")
@mock.patch("cherrypy.engine.publish")
def test_populates_tags(self, publish_mock, render_mock):
"""The tags field is prepopulated if provided via querystring"""
Expand All @@ -59,7 +59,7 @@ def side_effect(*args, **_):
"abc123"
)

@mock.patch("cherrypy.tools.negotiable._renderHtml")
@mock.patch("cherrypy.tools.negotiable.render_html")
@mock.patch("cherrypy.engine.publish")
def test_populates_comments(self, publish_mock, render_mock):
"""The comments field is prepopulated if provided via querystring
Expand All @@ -81,7 +81,7 @@ def side_effect(*args, **_):
"This is sentence 1. This is sentence 2."
)

@mock.patch("cherrypy.tools.negotiable._renderHtml")
@mock.patch("cherrypy.tools.negotiable.render_html")
@mock.patch("cherrypy.engine.publish")
def test_ignores_reddit_comment(self, publish_mock, render_mock):
"""The comments field of a reddit.com URL is discarded if it came from
Expand Down Expand Up @@ -109,7 +109,7 @@ def side_effect(*args, **_):

self.assertIsNone(helpers.html_var(render_mock, "comments"))

@mock.patch("cherrypy.tools.negotiable._renderHtml")
@mock.patch("cherrypy.tools.negotiable.render_html")
@mock.patch("cherrypy.engine.publish")
def test_url_lookup(self, publish_mock, render_mock):
"""An existing bookmark is fetched by url, overwriting querystring
Expand Down
8 changes: 4 additions & 4 deletions apps/phone/test_main.py
Expand Up @@ -30,7 +30,7 @@ def test_allow(self):
response = self.request("/", method="HEAD")
self.assertAllowedMethods(response, ("GET",))

@mock.patch("cherrypy.tools.negotiable._renderHtml")
@mock.patch("cherrypy.tools.negotiable.render_html")
@mock.patch("cherrypy.engine.publish")
def test_no_number(self, publish_mock, render_mock):
"""An HTML request with no number displays the search form"""
Expand All @@ -45,7 +45,7 @@ def side_effect(*args, **_):
self.request("/")
self.assertFalse(helpers.html_var(render_mock, "error"))

@mock.patch("cherrypy.tools.negotiable._renderHtml")
@mock.patch("cherrypy.tools.negotiable.render_html")
@mock.patch("cherrypy.engine.publish")
def test_invalid_number_as_html(self, publish_mock, render_mock):
"""An HTML request with an invalid number redirects with a message"""
Expand Down Expand Up @@ -101,7 +101,7 @@ def side_effect(*args, **_):
apps.phone.main.Controller.messages["invalid"]
)

@mock.patch("cherrypy.tools.negotiable._renderHtml")
@mock.patch("cherrypy.tools.negotiable.render_html")
@mock.patch("cherrypy.engine.publish")
def test_valid_number(self, publish_mock, render_mock):
"""A valid number lookup performs a state abbreviation lookup"""
Expand All @@ -128,7 +128,7 @@ def side_effect(*args, **_):
"XY"
)

@mock.patch("cherrypy.tools.negotiable._renderHtml")
@mock.patch("cherrypy.tools.negotiable.render_html")
@mock.patch("cherrypy.engine.publish")
def test_valid_number_cached(self, publish_mock, render_mock):
"""Successful number lookups are cached"""
Expand Down
8 changes: 4 additions & 4 deletions apps/redirect/test_main.py
Expand Up @@ -30,7 +30,7 @@ def test_allow(self):
response = self.request("/", method="HEAD")
self.assertAllowedMethods(response, ("GET",))

@mock.patch("cherrypy.tools.negotiable._renderHtml")
@mock.patch("cherrypy.tools.negotiable.render_html")
def test_no_destination(self, render_mock):
"""If no URL is provided, no redirect occurs."""
self.request("/")
Expand All @@ -44,7 +44,7 @@ def test_no_destination(self, render_mock):
helpers.html_var(render_mock, "dest")
)

@mock.patch("cherrypy.tools.negotiable._renderHtml")
@mock.patch("cherrypy.tools.negotiable.render_html")
def test_encoded_destination(self, render_mock):
"""Encoded URLs are decoded."""

Expand All @@ -60,7 +60,7 @@ def test_encoded_destination(self, render_mock):
"http://example.com"
)

@mock.patch("cherrypy.tools.negotiable._renderHtml")
@mock.patch("cherrypy.tools.negotiable.render_html")
def test_unencoded_destination(self, render_mock):
"""Unencoded URLs are used as-is."""

Expand All @@ -76,7 +76,7 @@ def test_unencoded_destination(self, render_mock):
"http://example.net"
)

@mock.patch("cherrypy.tools.negotiable._renderHtml")
@mock.patch("cherrypy.tools.negotiable.render_html")
def test_encoded_querystring(self, render_mock):
"""URL decoding preserves querystring values."""

Expand Down
8 changes: 4 additions & 4 deletions apps/registry/test_main.py
Expand Up @@ -30,7 +30,7 @@ def test_allow(self):
response = self.request("/", method="HEAD")
self.assertAllowedMethods(response, ("GET", "PUT", "DELETE"))

@mock.patch("cherrypy.tools.negotiable._renderHtml")
@mock.patch("cherrypy.tools.negotiable.render_html")
@mock.patch("cherrypy.engine.publish")
def test_get_by_uid_success(self, publish_mock, render_mock):
"""Searching for a valid uid returns a list of the one record"""
Expand All @@ -48,7 +48,7 @@ def side_effect(*args, **_):
entries = helpers.html_var(render_mock, "entries")
self.assertEqual(entries[0]["rowid"], "test")

@mock.patch("cherrypy.tools.negotiable._renderHtml")
@mock.patch("cherrypy.tools.negotiable.render_html")
@mock.patch("cherrypy.engine.publish")
def test_get_by_uid_fail(self, publish_mock, render_mock):
"""Searching for an invalid uid returns an empty list of entries"""
Expand All @@ -66,7 +66,7 @@ def side_effect(*args, **_):
entries = helpers.html_var(render_mock, "entries")
self.assertEqual(len(entries), 0)

@mock.patch("cherrypy.tools.negotiable._renderHtml")
@mock.patch("cherrypy.tools.negotiable.render_html")
@mock.patch("cherrypy.engine.publish")
def test_get_by_search(self, publish_mock, render_mock):
"""Entries can be searched by key"""
Expand All @@ -87,7 +87,7 @@ def side_effect(*args, **_):
"abc456"
)

@mock.patch("cherrypy.tools.negotiable._renderHtml")
@mock.patch("cherrypy.tools.negotiable.render_html")
@mock.patch("cherrypy.engine.publish")
def test_default_view(self, publish_mock, render_mock):
"""An invalid view returns the search view"""
Expand Down
2 changes: 1 addition & 1 deletion apps/speak/test_main.py
Expand Up @@ -28,7 +28,7 @@ def tearDownClass(cls):
def test_allow(self):
"""Verify the controller's supported HTTP methods"""
response = self.request("/", method="HEAD")
self.assertAllowedMethods(response, ("POST",))
self.assertAllowedMethods(response, ("GET", "HEAD", "POST"))

@mock.patch("cherrypy.engine.publish")
def test_muted(self, publish_mock):
Expand Down
6 changes: 3 additions & 3 deletions apps/whois/test_main.py
Expand Up @@ -49,7 +49,7 @@ def side_effect(*args, **_):
response = self.request("/", address="invalid")
self.assertEqual(response.code, 303)

@mock.patch("cherrypy.tools.negotiable._renderHtml")
@mock.patch("cherrypy.tools.negotiable.render_html")
@mock.patch("cherrypy.engine.publish")
def test_valid_address_as_hostname(self, publish_mock, render_mock):
"""Request lookup of a valid hostname"""
Expand Down Expand Up @@ -86,7 +86,7 @@ def side_effect(*args, **_):
response = self.request("/", address="333.333.333.333")
self.assertEqual(response.code, 303)

@mock.patch("cherrypy.tools.negotiable._renderHtml")
@mock.patch("cherrypy.tools.negotiable.render_html")
@mock.patch("cherrypy.engine.publish")
def test_address_as_ip(self, publish_mock, render_mock):
"""Request lookup of a cached IP address"""
Expand All @@ -108,7 +108,7 @@ def side_effect(*args, **_):
self.assertEqual(helpers.html_var(render_mock, "whois"), cache_fake)
self.assertEqual(helpers.html_var(render_mock, "ip_facts"), cache_fake)

@mock.patch("cherrypy.tools.negotiable._renderHtml")
@mock.patch("cherrypy.tools.negotiable.render_html")
@mock.patch("cherrypy.engine.publish")
def test_address_as_ip_nocache(self, publish_mock, render_mock):
"""Request lookup of an uncached IP address"""
Expand Down

0 comments on commit dd41fde

Please sign in to comment.