Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions mocket/mockhttp.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,12 @@ def can_handle(self, data):
requestline, _ = decode_utf8(data).split(CRLF, 1)
method, path, version = self._parse_requestline(requestline)
except ValueError:
Mocket.remove_last_request()
return True
return self == Mocket._last_entry
uri = urlsplit(path)
kw = dict(keep_blank_values=True)
ch = uri.path == self.path and parse_qs(uri.query, **kw) == parse_qs(self.query, **kw) and method == self.method
if ch:
Mocket._last_entry = self
return ch

@staticmethod
Expand Down
2 changes: 1 addition & 1 deletion test_requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
flake8
flake8<3.0
pep8
pytest
pytest-cov
Expand Down
4 changes: 3 additions & 1 deletion tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

if PY2:
from urllib2 import urlopen, HTTPError
from urllib import urlencode
else:
from urllib.request import urlopen
from urllib.error import HTTPError
from urllib.parse import urlencode
from urllib.error import HTTPError
14 changes: 13 additions & 1 deletion tests/test_http.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import time
import json
import mock
from . import urlopen, HTTPError
from . import urlopen, urlencode, HTTPError
import pytest
import requests
from unittest import TestCase
Expand Down Expand Up @@ -177,6 +177,18 @@ def test_same_url_different_methods(self):
self.assertEquals(methods, methods_from_responses)
self.assertEquals(list(range(len(methods))), contents_from_responses)

@mocketize
def test_request_bodies(self):
url = 'http://bit.ly/fakeurl/{0}'

for e in range(5):
u = url.format(e)
Entry.single_register(Entry.POST, u, body=str(e))
request_body = urlencode({'key-{0}'.format(e): 'value={0}'.format(e)})
urlopen(u, request_body.encode('utf-8'))
last_request = Mocket.last_request()
assert last_request.body == request_body

def assertEqualHeaders(self, first, second, msg=None):
first = dict((k.lower(), v) for k, v in first.items())
second = dict((k.lower(), v) for k, v in second.items())
Expand Down