From c761a572ae14368ad002a911d07d14c5c5c1b703 Mon Sep 17 00:00:00 2001 From: SerenaFeng Date: Wed, 14 Mar 2018 16:17:34 +0800 Subject: bugfix: TestAPI Cookie cannot be found Change-Id: Ibab60aba26e30669dddab74ce61ed00197dc86a8 Signed-off-by: SerenaFeng --- .../testapiclient/tests/unit/fakes.py | 72 ++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 testapi/testapi-client/testapiclient/tests/unit/fakes.py (limited to 'testapi/testapi-client/testapiclient/tests/unit/fakes.py') diff --git a/testapi/testapi-client/testapiclient/tests/unit/fakes.py b/testapi/testapi-client/testapiclient/tests/unit/fakes.py new file mode 100644 index 0000000..8424745 --- /dev/null +++ b/testapi/testapi-client/testapiclient/tests/unit/fakes.py @@ -0,0 +1,72 @@ +import json +import sys + +import requests +import six +import httplib + + +class FakeResponse(requests.Response): + + def __init__(self, headers=None, status_code=httplib.OK, + data=None, encoding=None): + super(FakeResponse, self).__init__() + + headers = headers or {} + + self.status_code = status_code + + self.headers.update(headers) + if status_code != httplib.OK: + self.reason = data + + self._content = json.dumps(data) + if not isinstance(self._content, six.binary_type): + self._content = self._content.encode() + + +class FakeApp(object): + + def __init__(self, _stdout, _log): + self.stdout = _stdout + self.client_manager = None + self.stdin = sys.stdin + self.stdout = _stdout or sys.stdout + self.stderr = sys.stderr + self.log = _log + + +class FakeLog(object): + + def __init__(self): + self.messages = {} + + def debug(self, msg): + self.messages['debug'] = msg + + def info(self, msg): + self.messages['info'] = msg + + def warning(self, msg): + self.messages['warning'] = msg + + def error(self, msg): + self.messages['error'] = msg + + def critical(self, msg): + self.messages['critical'] = msg + + +class FakeStdout(object): + + def __init__(self): + self.content = [] + + def write(self, text): + self.content.append(text) + + def make_string(self): + result = '' + for line in self.content: + result = result + line + return result -- cgit 1.2.3-korg