Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository is currently being migrated. It's locked while the migration is in progress.

Commit b8c1742

Browse files
author
Moritz Pein
committed
prepared responses are now Response objects and not built on call
1 parent 0329d55 commit b8c1742

2 files changed

Lines changed: 14 additions & 11 deletions

File tree

tests/conftest.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,22 +22,24 @@ def __init__(self, *args, **kwargs):
2222
@Request.application
2323
def __call__(self, request):
2424
try:
25-
status, content = self.responses[len(self.queries)]
25+
response = self.responses[len(self.queries)]
2626
except IndexError:
2727
response = Response("No prepared response")
2828
response.status_code = httplib.NOT_IMPLEMENTED
2929
return response
3030

3131
self.queries.append(request)
32+
return response
3233

33-
response = Response(json.dumps(content))
34+
def add_response(self, data=None, status=httplib.NO_CONTENT, headers=None):
35+
response = Response(data)
3436
response.status_code = status
35-
response.headers['content-type'] = 'application/json'
36-
37-
return response
37+
response.headers = headers or {'Content-Type': 'text/html'}
38+
self.responses.append(response)
3839

39-
def add_response(self, data, status=httplib.OK):
40-
self.responses.append((status, data))
40+
def add_json_response(self, data, status=httplib.OK):
41+
headers = {'Content-Type': 'application/json'}
42+
self.add_response(json.dumps(data), status=status, headers=headers)
4143

4244
@property
4345
def json_queries(self):

tests/test_dbapi.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def prepare_responses(self, festung):
5353
if not self.responses:
5454
return
5555
for response in self.responses:
56-
festung.add_response(response)
56+
festung.add_json_response(response)
5757

5858
@property
5959
def data(self):
@@ -111,7 +111,8 @@ class TestMultipleResponses(object):
111111

112112
def test_executemany(self, festung, cursor):
113113
for _ in range(3):
114-
festung.add_response({'data': [], 'headers': [], 'last_row_id': 0, 'rows_changed': 3})
114+
festung.add_json_response(
115+
{'data': [], 'headers': [], 'last_row_id': 0, 'rows_changed': 3})
115116

116117
query = 'UPDATE TABLE foo SET foo=?, bar=?, baz=?'
117118
params_list = [
@@ -125,7 +126,7 @@ def test_executemany(self, festung, cursor):
125126
assert data['params'] == params
126127

127128
def test_executemany_with_result(self, festung, cursor):
128-
festung.add_response({
129+
festung.add_json_response({
129130
'data': [[1]],
130131
'headers': [{'name': 'foo', 'type': 'int'}],
131132
'last_row_id': 0,
@@ -143,7 +144,7 @@ def test_executemany_with_result(self, festung, cursor):
143144
('dynamic', Type.UNKNOWN),
144145
])
145146
def test_types(self, festung, cursor, given, expected):
146-
festung.add_response({
147+
festung.add_json_response({
147148
'data': [],
148149
'headers': [{'name': 'foo', 'type': given}],
149150
'last_row_id': 0,

0 commit comments

Comments
 (0)