Skip to content

Commit

Permalink
Add a test for no latest generated meme
Browse files Browse the repository at this point in the history
  • Loading branch information
jacebrowning committed Aug 22, 2015
1 parent d65a16a commit e3367ba
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
11 changes: 11 additions & 0 deletions tests/test_routes_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

TESTS = os.path.dirname(__file__)
ROOT = os.path.dirname(TESTS)
LATEST = os.path.join(ROOT, "data", "images", "latest.jpg")


class TestImage:
Expand Down Expand Up @@ -66,6 +67,16 @@ def test_get_redirects_when_jpeg_with_text(self, client):
load(response, as_json=False)

def test_get_latest(self, client):
open(LATEST, 'w').close() # force the file to exist
response = client.get("/latest.jpg")
assert response.status_code == 200
assert response.mimetype == 'image/jpeg'

def test_get_latest_when_no_images(self, client):
try:
os.remove(LATEST)
except FileNotFoundError:
pass
response = client.get("/latest.jpg")
assert response.status_code == 302
assert '<a href="/fry/_.jpg">' in load(response, as_json=False)
2 changes: 1 addition & 1 deletion tests/test_routes_latest.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ def test_get_latest(self, client):
response = client.get("/latest")
assert response.status_code == 200
assert response.mimetype == 'text/html'
assert '<img src="' in response.get_data(as_text=True)
assert '<img src="/latest.jpg"' in response.get_data(as_text=True)

0 comments on commit e3367ba

Please sign in to comment.