Skip to content

Commit a0f9103

Browse files
committed
Merge pull request #27 from mocketize/old-issues
Fix for #13.
2 parents da80bb4 + 3067b4d commit a0f9103

2 files changed

Lines changed: 22 additions & 1 deletion

File tree

mocket/mockhttp.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,8 @@ def can_handle(self, data):
9393
return True
9494
uri = urlsplit(path)
9595
kw = dict(keep_blank_values=True)
96-
return uri.path == self.path and parse_qs(uri.query, **kw) == parse_qs(self.query, **kw)
96+
ch = uri.path == self.path and parse_qs(uri.query, **kw) == parse_qs(self.query, **kw) and method == self.method
97+
return ch
9798

9899
@staticmethod
99100
def _parse_requestline(line):

tests/test_http.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# coding=utf-8
22
from __future__ import unicode_literals
33
import time
4+
import json
45
import mock
56
from . import urlopen, HTTPError
67
import pytest
@@ -154,6 +155,25 @@ def test_file_object(self):
154155
self.assertEqual(int(r.headers['Content-Length']), len(local_content))
155156
self.assertEqual(r.headers['Content-Type'], 'image/png')
156157

158+
@mocketize
159+
def test_same_url_different_methods(self):
160+
url = 'http://bit.ly/fakeurl'
161+
response_to_mock = {
162+
'body': 'this is my body value',
163+
'method': None,
164+
}
165+
responses = []
166+
methods = [Entry.PUT, Entry.GET, Entry.POST]
167+
168+
for m in methods:
169+
response_to_mock['method'] = m
170+
Entry.single_register(m, url, body=json.dumps(response_to_mock))
171+
for m in methods:
172+
responses.append(requests.request(m, url).json())
173+
174+
methods_from_responses = [r['method'] for r in responses]
175+
self.assertEquals(methods, methods_from_responses)
176+
157177
def assertEqualHeaders(self, first, second, msg=None):
158178
first = dict((k.lower(), v) for k, v in first.items())
159179
second = dict((k.lower(), v) for k, v in second.items())

0 commit comments

Comments
 (0)