Update mock server
This commit is contained in:
parent
3d6a2a639a
commit
5aff76fee7
@ -1,5 +1,7 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
import io
|
||||||
import logging
|
import logging
|
||||||
|
import types
|
||||||
|
|
||||||
from anki.sync import HttpSyncer, RemoteServer, RemoteMediaServer
|
from anki.sync import HttpSyncer, RemoteServer, RemoteMediaServer
|
||||||
|
|
||||||
@ -14,23 +16,21 @@ class MockServerConnection:
|
|||||||
def __init__(self, server_app_to_test):
|
def __init__(self, server_app_to_test):
|
||||||
self.test_app = server_app_to_test
|
self.test_app = server_app_to_test
|
||||||
|
|
||||||
def request(self, uri, method='GET', headers=None, body=None):
|
def post(self, url, data, headers):
|
||||||
if method == 'POST':
|
logging.debug("Posting to URI '{}'.".format(url))
|
||||||
logging.debug("Posting to URI '{}'.".format(uri))
|
test_response = self.test_app.post(url,
|
||||||
logging.info("Posting to URI '{}'.".format(uri))
|
params=data.read(),
|
||||||
test_response = self.test_app.post(uri,
|
|
||||||
params=body,
|
|
||||||
headers=headers,
|
headers=headers,
|
||||||
status="*")
|
status="*")
|
||||||
|
|
||||||
resp = test_response.headers
|
r = types.SimpleNamespace()
|
||||||
resp.update({
|
r.status_code = test_response.status_int
|
||||||
"status": str(test_response.status_int)
|
r.body = test_response.body
|
||||||
})
|
return r
|
||||||
cont = test_response.body
|
|
||||||
return resp, cont
|
|
||||||
else:
|
def streamContent(self, r):
|
||||||
raise Exception('Unexpected HttpSyncer.req() behavior.')
|
return r.body
|
||||||
|
|
||||||
|
|
||||||
class MockRemoteServer(RemoteServer):
|
class MockRemoteServer(RemoteServer):
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user