Skip to content

Commit

Permalink
Allow top line to be blank
Browse files Browse the repository at this point in the history
Fixes #14
  • Loading branch information
jacebrowning committed Jun 18, 2015
1 parent 294a1fb commit 63eb9f7
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
7 changes: 5 additions & 2 deletions memegen/domain/text.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def __getitem__(self, key):
except (IndexError, ValueError):
return ""
else:
return part
return part.strip()

def get_line(self, index):
return self._format_line(self[index])
Expand Down Expand Up @@ -65,4 +65,7 @@ def _format_line(part):

@staticmethod
def _format_path(line):
return line.replace(' ', '-').lower()
if line == ' ':
return '_'
else:
return line.replace(' ', '-').lower()
8 changes: 8 additions & 0 deletions memegen/test/test_domain_text.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ def test_lines_ignore_capital_after_sep(self):
text = Text("hello-World")
assert ["HELLO WORLD"] == text.lines

def test_lines_strip_spaces(self):
text = Text(" hello World / ")
assert ["HELLO WORLD"] == text.lines

def test_path(self):
text = Text("hello/World")
assert "hello/world" == text.path
Expand All @@ -65,3 +69,7 @@ def test_path_with_underscores(self):
def test_path_with_case_changes(self):
text = Text("withCaseChanges/InIT")
assert "with-case-changes/in-it" == text.path

def test_path_strips_spaces(self):
text = Text(" with spaces/ in it / ")
assert "with--spaces/in-it" == text.path
10 changes: 9 additions & 1 deletion tests/test_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,22 @@ def test_get_links(self, client):
hidden="http://localhost/aXcJaGVsbG8vd29ybGQJ.jpg",
) == load(response)

def test_get_links_with_1_line(self, client):
def test_get_links_with_top_only(self, client):
response = client.get("/iw/hello")
assert response.status_code == 200
assert dict(
visible="http://localhost/iw/hello.jpg",
hidden="http://localhost/aXcJaGVsbG8J.jpg",
) == load(response)

def test_get_links_with_bottom_only(self, client):
response = client.get("/iw/_/hello")
assert response.status_code == 200
assert dict(
visible="http://localhost/iw/_/hello.jpg",
hidden="http://localhost/aXcJXy9oZWxsbwkJ.jpg",
) == load(response)

def test_get_links_redirects_to_dashes(self, client):
response = client.get("/iw/HelloThere_World/How-areYOU")
assert response.status_code == 302
Expand Down

0 comments on commit 63eb9f7

Please sign in to comment.