Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
@httprettified
@scenario(create_socket)
def test_httpretty_debugs_socket_recv(context):
"HTTPretty should debug socket.recv"
expect(context.sock.recv).when.called.to.throw(
RuntimeError,
"HTTPretty intercepted and unexpected socket method call."
)
@httprettified
def testParseKeysResponse(self):
""" Check that parsing plain keys returned by format = keys works """
zot = z.Zotero('myuserid', 'user', 'myuserkey')
zot.url_params = 'format=keys'
HTTPretty.register_uri(
HTTPretty.GET,
'https://api.zotero.org/users/myuserid/items?format=keys',
body=self.keys_response)
response = zot.items()
self.assertEqual('ABCDE\nFGHIJ\nKLMNO\n', response)
@httprettified
def test_move(self):
HTTPretty.register_uri(
HTTPretty.POST,
FAKE_EXCHANGE_URL,
body=MOVE_EVENT_RESPONSE.encode('utf-8'),
content_type='text/xml; charset=utf-8'
)
self.event.move_to('AAAhKSe7AAA=')
assert self.event.calendar_id == 'AAAhKSe7AAA='
assert self.event.id == TEST_EVENT_MOVED.id
@httprettified
def test_create_recurrence_weekly(self):
HTTPretty.register_uri(
HTTPretty.POST, FAKE_EXCHANGE_URL,
body=CREATE_ITEM_RESPONSE.encode('utf-8'),
content_type='text/xml; charset=utf-8',
)
self.event.create()
assert self.event.id == TEST_RECURRING_EVENT_WEEKLY.id
@httprettified
def test_fetch_backup_configurations_works(self):
url = '{0}/backup-configuration/system/{1}'.format(self.conn.host,
self.agent.id)
data = json.dumps([mock_config.backup_configuration()
for i in range(10)])
HTTPretty.register_uri(HTTPretty.GET, url, status=200, body=data)
confs = list(self.agent.backup_configurations)
self.assertEqual(len(confs), 10)
for conf in confs:
self.assertEqual(conf.name, 'mock')
@httprettified
@within(two=microseconds)
def test_can_inspect_last_request(now):
"HTTPretty.last_request is a mimetools.Message request from last match"
HTTPretty.register_uri(HTTPretty.POST, "http://api.github.com/",
body='{"repositories": ["HTTPretty", "lettuce"]}')
request = urllib2.Request(
'http://api.github.com',
b'{"username": "gabrielfalcao"}',
{
'content-type': 'text/json',
},
)
fd = urlopen(request)
got = fd.read()
@httprettified
def testGetTemplate(self):
""" Ensure that item templates are retrieved and converted into dicts
"""
zot = z.Zotero('myuserID', 'user', 'myuserkey')
HTTPretty.register_uri(
HTTPretty.GET,
'https://api.zotero.org/items/new?itemType=book',
body=self.item_templt)
t = zot.item_template('book')
self.assertEqual('book', t['itemType'])
@httprettified
def test_swbiodiversity_harvester():
httpretty.enable()
httpretty.allow_net_connect = False
config = SourceConfig.objects.get(label=('org.swbiodiversity'))
url = config.harvester_kwargs['list_url']
harvester = config.get_harvester()
httpretty.register_uri(httpretty.GET, url,
body=main_page, content_type='text/html', match_querystring=True)
collection = furl(url)
collection.args['collid'] = 223
httpretty.register_uri(httpretty.GET, url + ';collid=(\d+)',
body=collection_page, content_type='text/html', match_querystring=True)
start = pendulum.utcnow() - timedelta(days=3)
end = pendulum.utcnow()
@httprettified
def test_fetch_repo_list_multiple_sites(self):
responses = [
HTTPretty.Response(
body=open(self.test_data_folder + 'test_response_01.json').read(),
status=200,
link=';'
' rel="next", '
'; '
'rel="last"'),
HTTPretty.Response(
body=open(self.test_data_folder + 'test_response_02.json').read(),
status=200,
link='; '
'rel="next", '
';'
' rel="last"'),
@httprettified
def test_fetch_repo_list_wrong_response_status(self):
HTTPretty.register_uri(HTTPretty.GET, "https://api.github.com/orgs/some_org/repos",
body='Not found', status=404)
self.git_repo_updater_obj.refresh_repo_list()
self.assertTrue(self.git_repo_updater_obj.stop)