class TestApplication: @pytest.fixture(scope='class', autouse=True) def setup(self): my_app.run_app() my_mock = MyHTTPServer('127.0.0.1', 1052) my_mock.start() close_func = SocketClient('127.0.0.1', 1050) yield close_func.get('/shutdown') my_mock.stop() @pytest.fixture(scope='function', autouse=True) def client(self): self.client = SocketClient('127.0.0.1', 1050) def test_status_get(self): assert self.client.get('/')['status_code'] == 200 def test_ok(self): self.client.put('/data_put', 'name=max') assert self.client.post('/data_post', 'name=max')['body'] == 'OK' def test_dont_ok(self): assert self.client.post('/data_post', 'name=oleg')['body'] == 'DONT OK' def test_put(self): self.client.put('/data_put', 'name=dima') assert 'dima' in self.client.get('/')['body'] def test_not_found(self): assert self.client.get('/fake')['status_code'] == 404 def test_mock_500(self): assert self.client.get('/500')['status_code'] == 424
def error500(): client = SocketClient('127.0.0.1', 1052) data = client.get('/500') if data['status_code'] == 500: return '', 424 else: return 'unknown'
def index(): try: client = SocketClient('127.0.0.1', 1052) output_get = client.get('/') return output_get['body'] except BrokenPipeError: return 'Mock is down'
def setup(self): my_app.run_app() my_mock = MyHTTPServer('127.0.0.1', 1052) my_mock.start() close_func = SocketClient('127.0.0.1', 1050) yield close_func.get('/shutdown') my_mock.stop()
class TestWithoutMock: @pytest.fixture(scope='class', autouse=True) def setup(self): my_app.run_app() close_func = SocketClient('127.0.0.1', 1050) yield close_func.get('/shutdown') @pytest.fixture(scope='function', autouse=True) def client(self): self.client = SocketClient('127.0.0.1', 1050) def test_status_get(self): time.sleep(1) assert self.client.get('/')['body'] == 'Mock is down'
def client(self): self.client = SocketClient('127.0.0.1', 1050)
def setup(self): my_app.run_app() close_func = SocketClient('127.0.0.1', 1050) yield close_func.get('/shutdown')
def data_put(): client = SocketClient('127.0.0.1', 1052) client.put('/data_put', request.form['name']) return ''
def data_post(): client = SocketClient('127.0.0.1', 1052) output_post = client.post('/data_post', request.form['name']) return output_post['body']