Add tests about the RuntimeError issue

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.
This commit is contained in:
Guillaume Gauvrit
2013-07-26 15:44:50 +02:00
parent cdce9aba69
commit 793f8e3e9a

View File

@@ -26,7 +26,7 @@
# OTHER DEALINGS IN THE SOFTWARE.
from __future__ import unicode_literals
from sure import expect
from httpretty import HTTPretty, HTTPrettyError
from httpretty import HTTPretty, HTTPrettyError, core
from httpretty.core import URIInfo, BaseClass, Entry, FakeSockFile
from httpretty.http import STATUSES
@@ -53,6 +53,47 @@ def test_httpretty_should_raise_proper_exception_on_inconsistent_length():
)
def test_httpretty_should_raise_on_socket_send_when_uri_registered():
"""HTTPretty should raise a RuntimeError when the fakesocket is used in
an invalid usage.
"""
import socket
HTTPretty.enable()
defaults = core.POTENTIAL_HTTP_PORTS[:]
HTTPretty.register_uri(HTTPretty.GET,
'http://127.0.0.1:5000')
expect(core.POTENTIAL_HTTP_PORTS).to.be.equal([80, 443, 5000])
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.connect(('127.0.0.1', 5000))
expect(sock.send).when.called_with('whatever').to.throw(RuntimeError)
sock.close()
# restore the previous value
core.POTENTIAL_HTTP_PORTS = defaults
HTTPretty.reset()
HTTPretty.disable()
def test_httpretty_should_not_raise_on_socket_send_when_uri_not_registered():
"""HTTPretty should not raise a RuntimeError when the fakesocket is used in
an invalid usage.
"""
import socket
HTTPretty.enable()
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, 0)
sock.setblocking(0)
expect(sock.sendto).when.called_with('whatever',
('127.0.0.1', 53)
).should_not.throw(RuntimeError)
sock.close()
HTTPretty.reset()
HTTPretty.disable()
def test_does_not_have_last_request_by_default():
'HTTPretty.last_request is a dummy object by default'
HTTPretty.reset()