Changeset View
Changeset View
Standalone View
Standalone View
swh/core/api/tests/test_api.py
Show All 31 Lines | def test_server(self): | ||||
backend_class=TestStorage, | backend_class=TestStorage, | ||||
backend_factory=lambda: TestStorage()) | backend_factory=lambda: TestStorage()) | ||||
@app.errorhandler(Exception) | @app.errorhandler(Exception) | ||||
def my_error_handler(exception): | def my_error_handler(exception): | ||||
return error_handler(exception, encode_data_server) | return error_handler(exception, encode_data_server) | ||||
client = WerkzeugTestClient(app, BaseResponse) | client = WerkzeugTestClient(app, BaseResponse) | ||||
res = client.post('/test_endpoint_url', | res = client.post( | ||||
headers={'Content-Type': 'application/x-msgpack'}, | '/test_endpoint_url', | ||||
headers=[('Content-Type', 'application/x-msgpack'), | |||||
('Accept', 'application/x-msgpack')], | |||||
data=b'\x81\xa9test_data\xa4spam') | data=b'\x81\xa9test_data\xa4spam') | ||||
self.assertEqual(nb_endpoint_calls, 1) | self.assertEqual(nb_endpoint_calls, 1) | ||||
self.assertEqual(b''.join(res.response), b'\xa3egg') | self.assertEqual(b''.join(res.response), b'\xa3egg') | ||||
def test_client(self): | def test_client(self): | ||||
class TestStorage: | class TestStorage: | ||||
@remote_api_endpoint('test_endpoint_url') | @remote_api_endpoint('test_endpoint_url') | ||||
def test_endpoint(self, test_data, db=None, cur=None): | def test_endpoint(self, test_data, db=None, cur=None): | ||||
Show All 34 Lines |