예제 #1
0
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
예제 #2
0
def error500():
    client = SocketClient('127.0.0.1', 1052)
    data = client.get('/500')
    if data['status_code'] == 500:
        return '', 424
    else:
        return 'unknown'
예제 #3
0
def index():
    try:
        client = SocketClient('127.0.0.1', 1052)
        output_get = client.get('/')
        return output_get['body']
    except BrokenPipeError:
        return 'Mock is down'
예제 #4
0
 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()
예제 #5
0
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'
예제 #6
0
 def client(self):
     self.client = SocketClient('127.0.0.1', 1050)
예제 #7
0
 def setup(self):
     my_app.run_app()
     close_func = SocketClient('127.0.0.1', 1050)
     yield
     close_func.get('/shutdown')
예제 #8
0
def data_put():
    client = SocketClient('127.0.0.1', 1052)
    client.put('/data_put', request.form['name'])
    return ''
예제 #9
0
def data_post():
    client = SocketClient('127.0.0.1', 1052)
    output_post = client.post('/data_post', request.form['name'])

    return output_post['body']