def test_full_server_stack_post_handling(self): self.rb.get_entry.return_value = Stub(id=2) server = Server() try: server.start() response = urlopen('http://localhost:7003/rest/song/2', data=bytes('rating=5', 'UTF-8')) self.assertEquals(response.code, 200) finally: server.stop()
def test_full_server_stack(self): server = Server() try: server.start() response = urlopen('http://localhost:7003') self.assertEquals(response.code, 200) html = response.read().decode('UTF-8') self.assertTrue('html' in html) finally: server.stop()
def test_full_server_stack_error_handling(self): self.rb.get_entry.side_effect = RuntimeError('just because') server = Server() try: server.start() urlopen('http://localhost:7003/rest/song/1') self.assertTrue(False) except HTTPError as e: self.assertEquals(e.code, 500) finally: server.stop()
def test_full_server_stack_not_found_handling(self): self.rb.get_entry.return_value = None server = Server() try: server.start() urlopen('http://localhost:7003/rest/song/1') self.assertTrue(False) except HTTPError as e: self.assertEquals(e.code, 404) finally: server.stop()