Here are the examples of the python api mocket.mockhttp.Entry.GET taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
6 Examples
3
Example 1
@mocketize
def test_sendall(self):
with mock.patch('time.gmtime') as tt:
tt.return_value = time.struct_time((2013, 4, 30, 10, 39, 21, 1, 120, 0))
Entry.single_register(Entry.GET, 'http://testme.org/get/p/?a=1&b=2', body='test_body')
resp = urlopen('http://testme.org/get/p/?b=2&a=1', timeout=10)
self.assertEqual(resp.code, 200)
self.assertEqual(resp.read(), b'test_body')
self.assertEqualHeaders(dict(resp.headers), {
u'Status': u'200',
u'Content-length': u'9',
u'Server': u'Python/Mocket',
u'Connection': u'close',
u'Date': u'Tue, 30 Apr 2013 10:39:21 GMT',
u'Content-type': u'text/plain; charset=utf-8'
})
self.assertEqual(len(Mocket._requests), 1)
3
Example 2
Project: python-mocket Source File: test_http.py
@mocketize
def test_sendall_double(self):
Entry.register(Entry.GET, 'http://testme.org/', Response(status=404), Response())
self.assertRaises(HTTPError, urlopen, 'http://testme.org/')
response = urlopen('http://testme.org/')
self.assertEqual(response.code, 200)
response = urlopen('http://testme.org/')
self.assertEqual(response.code, 200)
self.assertEqual(len(Mocket._requests), 3)
3
Example 3
@mocketize
def test_file_object(self):
url = 'http://github.com/fluidicon.png'
filename = 'tests/fluidicon.png'
file_obj = open(filename, 'rb')
Entry.single_register(Entry.GET, url, body=file_obj)
r = requests.get(url)
remote_content = r.content
local_file_obj = open(filename, 'rb')
local_content = local_file_obj.read()
self.assertEqual(remote_content, local_content)
self.assertEqual(len(remote_content), len(local_content))
self.assertEqual(int(r.headers['Content-Length']), len(local_content))
self.assertEqual(r.headers['Content-Type'], 'image/png')
0
Example 4
Project: python-mocket Source File: test_http.py
@mocketize
def test_wrongpath_truesendall(self):
Entry.register(Entry.GET, 'http://httpbin.org/user.agent', Response())
response = urlopen('http://httpbin.org/ip')
self.assertEqual(response.code, 200)
0
Example 5
Project: python-mocket Source File: test_http.py
def test_register(self):
with mock.patch('time.gmtime') as tt:
tt.return_value = time.struct_time((2013, 4, 30, 10, 39, 21, 1, 120, 0))
Entry.register(
Entry.GET,
'http://testme.org/get?a=1&b=2#test',
Response('{"a": "€"}', headers={'content-type': 'application/json'})
)
entries = Mocket._entries[('testme.org', 80)]
self.assertEqual(len(entries), 1)
entry = entries[0]
self.assertEqual(entry.method, 'GET')
self.assertEqual(entry.schema, 'http')
self.assertEqual(entry.path, '/get')
self.assertEqual(entry.query, 'a=1&b=2')
self.assertEqual(len(entry.responses), 1)
response = entry.responses[0]
self.assertEqual(response.body, b'{"a": "\xe2\x82\xac"}')
self.assertEqual(response.status, 200)
self.assertEqual(response.headers, {
u'Status': u'200',
u'Date': u'Tue, 30 Apr 2013 10:39:21 GMT',
u'Connection': u'close',
u'Server': u'Python/Mocket',
u'Content-Length': u'12',
u'Content-Type': u'application/json',
})
0
Example 6
Project: python-mocket Source File: test_http.py
@mocketize
def test_sendall_json(self):
with mock.patch('time.gmtime') as tt:
tt.return_value = time.struct_time((2013, 4, 30, 10, 39, 21, 1, 120, 0))
Entry.single_register(
Entry.GET,
'http://testme.org/get?a=1&b=2#test',
body='{"a": "€"}',
headers={'content-type': 'application/json'}
)
response = urlopen('http://testme.org/get?b=2&a=1#test', timeout=10)
self.assertEqual(response.code, 200)
self.assertEqual(response.read(), b'{"a": "\xe2\x82\xac"}')
self.assertEqualHeaders(dict(response.headers), {
u'status': u'200',
u'content-length': u'12',
u'server': u'Python/Mocket',
u'connection': u'close',
u'date': u'Tue, 30 Apr 2013 10:39:21 GMT',
u'content-type': u'application/json',
})
self.assertEqual(len(Mocket._requests), 1)