summaryrefslogtreecommitdiff
path: root/tests/unit/test_httpretty.py
Commit message (Collapse)AuthorAgeFilesLines
* Merge pull request #285 from hufman/use_tempfileGabriel Falcão2016-05-261-1/+1
|\ | | | | Use a tempfile instead of a StringIO object
| * Use a tempfile instead of a StringIO objectWalter Huf2016-02-031-1/+1
| | | | | | | | | | | | This provides a socket.fileno(), so libraries that call select.poll() work properly. Also supports mocking huge responses larger than memory, if needed.
* | Encode callable body length as str and not bytesWalter Huf2016-02-061-0/+10
|/ | | | | | | The bytes() constructor, when given an integer, creates a bytes object of that length, instead of casting the number to a string representation. This change uses str() to cast the integer, and then relies on the later utf8() call to convert it to bytes.
* revamping docs + testsGabriel Falcão2015-12-131-1/+3
|
* Fix py34 hangingBen Picolo2015-05-131-0/+24
|
* Added test to reproduce https://github.com/gabrielfalcao/HTTPretty/issues/206Andres Riancho2015-01-071-0/+12
|
* Fix bug that occurs when using custom schema/port/regexLuqmaan2014-04-031-1/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Reopens https://github.com/gabrielfalcao/HTTPretty/pull/145. Reopened as a new PR because Travis didn't seem to be running the correct tests. Removed the irrelevant changes, such as PEP8 and the `self.truesock.settimeout(0)` change. HTTPretty does not behave correctly when using regex matching, HTTPS and custom ports. When this scenario is triggered, a timeout/max retries exceeded error occurs. To duplicate run: ```python @httpretty.activate def exceed_max_retries_with_custom_port_and_https(): HTTPretty.register_uri( HTTPretty.GET, re.compile('https://api.yipit.com:1234/v1/deal;brand=(?P<brand_name>\w+)'), body='meow' ) uri = 'https://api.yipit.com:1234/v1/deal;brand=gap?first_name=chuck&last_name=norris' response = requests.get(uri) return response.content ``` Cause -- The combination of a regex URI, custom port, and HTTPS causes HTTPretty to get stuck at https://github.com/gabrielfalcao/HTTPretty/blob/2e814635fff916d3a8c246ca010245362266c89f/httpretty/core.py#L323 and eventually raise this error: ``` ConnectionError: HTTPSConnectionPool(host='api.yipit.com', port=1234): Max retries exceeded with url: /v1/deal;brand=gap?first_name=chuck&last_name=norris (Caused by <class 'socket.error'>: [Errno 36] Operation now in progress). ``` This error happens because URI schema's are reconstructed incorrectly during the URI matching. This should fail (http != https), but it does not! ```python @httpretty.activate def broken_reconstruction_of_uri_schema(): uri = 'api.yipit.com:1234/v1/deal' HTTPretty.register_uri(HTTPretty.GET, 'https://' + uri, body=lambda method, uri, headers: [200, headers, uri] ) response = requests.get(uri) expect(response.text).to.equal('http://' + uri) # incorrect! ``` Solution -- To correct the internal confusion between HTTP and HTTPS ports, we need to separate the two in our DEFAULT/POTENTIAL PORTS lists. When URIMatcher encounters a non-regex URI it uses URIInfo.from_uri to add the URIs port to the known ports. This behavior is now added for regex URIs. We now use the DEFAULT_PORTS lists in HTTPretty.reset() to reset the POTENTIAL_PORTS lists. Also, to avoid using the global keyword, we do an in-place reset with intersection_update. Added the following tests: - test_httpretty_should_work_with_non_standard_ports - test_httpretty_reset_by_switching_protocols_for_same_port - test_httpretty_should_allow_registering_regexes_with_port_and_give_a_proper_match_to_the_callback
* Merge pull request #88 from toumorokoshi/parsed_postGabriel Falcão2013-09-291-1/+41
|\ | | | | Adding parsed_body parameter to simplify checks
| * fixing tests for python3Yusuke Tsutsumi2013-09-081-2/+2
| |
| * Adding parsed_body parameter to simplify checksYusuke Tsutsumi2013-07-291-1/+41
| | | | | | | | | | | | | | | | parsed_body attempts to parse the post body if it matches a compatible content type * content is returned unaltered if it's not a compatible type * content parses json if content-type type is application/json * content parse querystring params if content-type is application/x-www-form-urlencoded * if the value cannot be parsed for any reason, it is unaltered
* | Merge pull request #89 from Gandi/masterGabriel Falcão2013-09-291-4/+2
|\ \ | | | | | | Don't duplicate http ports number
| * | Don't duplicate http ports numberGuillaume Gauvrit2013-07-291-4/+2
| |/ | | | | | | | | Use a set instead of a list to store ports in the POTENTIAL_HTTP_PORTS. Restore it to its initial value every tests that modify it.
* | Use common string case for URIInfo hostname comparison.Mike Waters2013-09-131-1/+25
|/
* Fix Python 3 supportGuillaume Gauvrit2013-07-261-2/+2
|
* Fix testsGuillaume Gauvrit2013-07-261-0/+1
| | | | | Functional test change the content of POTENTIAL_HTTP_PORTS but don't reset it. Ignore those changes.
* Add tests about the RuntimeError issueGuillaume Gauvrit2013-07-261-1/+42
| | | | | | | | | | | when HTTPretty.enable(), we should contine to do DNS query, like it's done in the test_httpretty_should_not_raise_on_socket_send_when_uri_not_registered test. The test test_httpretty_should_raise_on_socket_send_when_uri_registered is written to check that the RuntimeError is still raised when the port is used for http traffic.
* partial fix for some tests, 2 tests still failgcetusic2013-06-271-1/+5
|
* Merge pull request #61 from maxmind/masterGabriel Falcão2013-06-111-7/+7
|\ | | | | Remove 2.x style unicode literals
| * Whitespace and 'u' string fixesGregory Oschwald2013-05-061-4/+4
| |
| * Removed 2.x-style unicode literalsGregory Oschwald2013-05-061-5/+5
| |
* | Fix the calculation of Content-Lengthpapaeye2013-06-101-1/+9
|/ | | | | | HTTPretty calculates Content-Length as the length of the body in characters, when `body` is `unicode` of multibyte character set. But it should be the length of the body in bytes.
* regex matching should ignore querystringsSteve Pulec2013-04-301-0/+4
|
* Moving code around, simplifying API interface and releasing 0.6.00.6.0Gabriel Falcao2013-04-181-2/+4
|
* test all delegated socket methods using mockTim Cowlishaw2013-04-111-7/+23
|
* failing tests for other socket methods - as they call through to the real ↵Tim Cowlishaw2013-04-111-0/+47
| | | | socket implementation, some raise exceptions that we don't care about in this instance. This could be fixed with mocking
* ensure that calls to the 'getsockopt' method on fake sockets are delegated ↵Tim Cowlishaw2013-04-111-0/+6
| | | | to the underlying socket
* ensure that calls to the 'fileno' method on fake sockets are delegated to ↵Tim Cowlishaw2013-04-111-0/+6
| | | | the underlying socket
* ensure that calls to the 'setblocking' method on fake sockets are delegated ↵Tim Cowlishaw2013-04-111-0/+7
| | | | to the underlying socket
* fix headers capitalization on Entry classIgor Sobreira2013-04-021-1/+12
|
* add missing return to Py3kObjectIgor Sobreira2013-04-021-1/+10
|
* global stateGabriel Falcao2013-03-121-9/+16
|
* bumping to 0.5.10 + updating readme, changelog and adding a contributors listGabriel Falcao2013-02-191-1/+1
|
* Additional fixes for py3kSteve Pulec2013-02-171-1/+20
|
* py3k supportSteve Pulec2013-02-131-0/+1
|
* adding missing status codes. closes #14Gabriel Falcao2012-11-191-16/+94
|
* code cleanup. #refs #1Gabriel Falcao2012-11-111-2/+1
|
* updating licenseGabriel Falcao2012-11-091-1/+1
|
* adding a dummy last_request for the sake of meaningful assertion errors0.4Gabriel Falcao2011-06-291-0/+8
|
* adding the untracked test I forgot to `git add`Gabriel Falcão2011-02-081-0/+50