Commit 215f74e706
Verified · cmc
Layout: unified · split
tests/test_main.py +11 −10
| @@ -24,21 +24,22 @@ class TestBuildMessage(unittest.TestCase): | |||
| 24 | self.assertIn("one\ntwo", msg.get_payload()) | 24 | self.assertIn("one\ntwo", msg.get_payload()) |
| 25 | 25 | ||
| 26 | 26 | ||
| 27 | PAYLOAD = [ | ||
| 28 | { | ||
| 29 | "title": "Sonnet", | ||
| 30 | "author": "Anon", | ||
| 31 | "linecount": "2", | ||
| 32 | "lines": ["first line", "second line"], | ||
| 33 | } | ||
| 34 | ] | ||
| 35 | |||
| 36 | |||
| 27 | class TestFetchPoem(unittest.TestCase): | 37 | class TestFetchPoem(unittest.TestCase): |
| 28 | """PoetryDB is stubbed: the test covers the shape this code expects from it, | 38 | """PoetryDB is stubbed: the test covers the shape this code expects from it, |
| 29 | not the service being up.""" | 39 | not the service being up.""" |
| 30 | 40 | ||
| 31 | PAYLOAD = [ | ||
| 32 | { | ||
| 33 | "title": "Sonnet", | ||
| 34 | "author": "Anon", | ||
| 35 | "linecount": "2", | ||
| 36 | "lines": ["first line", "second line"], | ||
| 37 | } | ||
| 38 | ] | ||
| 39 | |||
| 40 | def test_fields_are_extracted_and_lines_joined(self): | 41 | def test_fields_are_extracted_and_lines_joined(self): |
| 41 | with patch("main.requests.get", return_value=FakeResponse(self.PAYLOAD)): | 42 | with patch("main.requests.get", return_value=FakeResponse(PAYLOAD)): |
| 42 | title, author, line_count, lines = fetch_poem() | 43 | title, author, line_count, lines = fetch_poem() |
| 43 | 44 | ||
| 44 | self.assertEqual(title, "Sonnet") | 45 | self.assertEqual(title, "Sonnet") |