Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_microsecond_unit():
"testing microseconds convertion"
cfrom, cto = sure.UNITS[sure.microsecond]
assert_equals(cfrom(1), 100000)
assert_equals(cto(1), 1)
cfrom, cto = sure.UNITS[sure.microseconds]
assert_equals(cfrom(1), 100000)
assert_equals(cto(1), 1)
@within(two=microseconds)
def test_httpretty_should_mock_a_simple_get_with_requests_read(now):
"HTTPretty should mock a simple GET with requests.get"
HTTPretty.register_uri(HTTPretty.GET, "http://yipit.com/",
body="Find the best daily deals")
response = requests.get('http://yipit.com')
expect(response.text).to.equal('Find the best daily deals')
expect(HTTPretty.last_request.method).to.equal('GET')
expect(HTTPretty.last_request.path).to.equal('/')
@within(two=microseconds)
def test_httpretty_should_mock_a_simple_get_with_httplib2_read(now):
"HTTPretty should mock a simple GET with httplib2.context.http"
HTTPretty.register_uri(HTTPretty.GET, "http://yipit.com/",
body="Find the best daily deals")
_, got = httplib2.Http().request('http://yipit.com', 'GET')
expect(got).to.equal(b'Find the best daily deals')
expect(HTTPretty.last_request.method).to.equal('GET')
expect(HTTPretty.last_request.path).to.equal('/')
@within(two=microseconds)
def test_httpretty_should_allow_adding_and_overwritting_httplib2(now):
"HTTPretty should allow adding and overwritting headers with httplib2"
HTTPretty.register_uri(HTTPretty.GET, "http://github.com/foo",
body="this is supposed to be the response",
adding_headers={
'Server': 'Apache',
'Content-Length': '27',
'Content-Type': 'application/json',
})
headers, _ = httplib2.Http().request('http://github.com/foo', 'GET')
expect(dict(headers)).to.equal({
'content-type': 'application/json',
'content-location': 'http://github.com/foo',
@within(two=microseconds)
def test_httpretty_should_mock_headers_urllib2(now):
"HTTPretty should mock basic headers with urllib2"
HTTPretty.register_uri(HTTPretty.GET, "http://github.com/",
body="this is supposed to be the response",
status=201)
request = urlopen('http://github.com')
headers = dict(request.headers)
request.close()
request.code.should.equal(201)
headers.should.equal({
'content-type': 'text/plain; charset=utf-8',
'connection': 'close',
@within(two=microseconds)
def test_httpretty_should_mock_a_simple_get_with_urllib2_read():
"HTTPretty should mock a simple GET with urllib2.read()"
HTTPretty.register_uri(HTTPretty.GET, "http://yipit.com/",
body="Find the best daily deals")
fd = urlopen('http://yipit.com')
got = fd.read()
fd.close()
got.should.equal(b'Find the best daily deals')
@within(two=microseconds)
def test_httpretty_should_allow_adding_and_overwritting_requests(now):
"HTTPretty should allow adding and overwritting headers with requests"
HTTPretty.register_uri(HTTPretty.GET, "http://github.com/foo",
body="this is supposed to be the response",
adding_headers={
'Server': 'Apache',
'Content-Length': '27',
'Content-Type': 'application/json',
})
response = requests.get('http://github.com/foo')
expect(dict(response.headers)).to.equal({
'content-type': 'application/json',
'connection': 'close',