Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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'])
def test_file_field_get_file_success(self):
field = fields.FileField()
url = urlobject.URLObject('http://example.com/file.txt')
HTTPretty.register_uri(
HTTPretty.GET, text_type(url), body='I am text', status=200,
content_type='text/plain')
uploaded = field._get_file(url)
self.assertEqual(uploaded['content-type'], 'text/plain')
self.assertEqual(uploaded['content'], b'I am text')
def test_can_remove_all_attendees(self):
HTTPretty.register_uri(
HTTPretty.POST,
FAKE_EXCHANGE_URL,
responses=[
self.get_change_key_response,
self.update_event_response,
]
)
self.event.attendees = None
self.event.update()
assert RESOURCE.email not in HTTPretty.last_request.body.decode('utf-8')
def test_callback_body_remains_callable_for_any_subsequent_requests(now):
("HTTPretty should call a callback function more than one"
" requests")
def request_callback(request, uri, headers):
return [200, headers, "The {} response from {}".format(decode_utf8(request.method), uri)]
HTTPretty.register_uri(
HTTPretty.GET, "https://api.yahoo.com/test",
body=request_callback)
response = requests.get('https://api.yahoo.com/test')
expect(response.text).to.equal("The GET response from https://api.yahoo.com/test")
response = requests.get('https://api.yahoo.com/test')
expect(response.text).to.equal("The GET response from https://api.yahoo.com/test")
'social.pipeline.user.get_username',
'social.pipeline.user.create_user',
'social.pipeline.social_auth.associate_user',
'social.pipeline.social_auth.load_extra_data',
'tests.pipeline.set_password',
'social.pipeline.user.user_details'
)
})
self.do_start()
url = self.strategy.build_absolute_uri('/password')
redirect = self.strategy.complete()
expect(redirect.url).to.equal(url)
HTTPretty.register_uri(HTTPretty.GET, redirect.url, status=200,
body='foobar')
HTTPretty.register_uri(HTTPretty.POST, redirect.url, status=200)
password = 'foobar'
requests.get(url)
requests.post(url, data={'password': password})
data = parse_qs(HTTPretty.last_request.body)
expect(data['password']).to.equal(password)
self.strategy.session_set('password', data['password'])
data = self.strategy.session_pop('partial_pipeline')
idx, backend, xargs, xkwargs = self.strategy.from_session(data)
expect(backend).to.equal(self.backend.name)
user = self.strategy.continue_pipeline(pipeline_index=idx,
*xargs, **xkwargs)
expect(user.username).to.equal(self.expected_username)
def render(self, template, json_mocks):
if type(json_mocks) is not list:
json_mocks = [json_mocks]
responses = [HTTPretty.Response(get_json(_)) for _ in json_mocks]
HTTPretty.register_uri(HTTPretty.GET, self.api_url, responses=responses, content_type='application/json')
return render_template(template=template)
def test_create_works(self):
url = '{0}/backup-configuration'.format(self.connection.host)
HTTPretty.register_uri(HTTPretty.POST, url, status=200,
body=json.dumps({'BackupConfigurationId': 100}))
old_id = self.config.id
self.config.create()
self.assertEqual(self.config.id, 100)
self.assertNotEqual(self.config.id, old_id)
def testRateLimitWithBackoff(self):
""" Test 429 response handling when a backoff header is received
"""
zot = z.Zotero("myuserID", "user", "myuserkey")
HTTPretty.register_uri(
HTTPretty.GET,
"https://api.zotero.org/users/myuserID/items",
status=429,
adding_headers={"backoff": 10},
)
zot.items()
self.assertTrue(zot.backoff)
def __init__(self, base_url, pk_maps={}, default_pk="_id"):
self.items = defaultdict(dict)
self.base_url = base_url
self.default_pk = default_pk
self.pk_maps = pk_maps
self.etag = {}
# Register all URIs for resources
resource_url = urljoin(self.base_url, "([^/]+/?$)")
resource_regex = re.compile(resource_url)
HTTPretty.register_uri(HTTPretty.GET,
resource_regex,
body=self.generate_resource_response)
HTTPretty.register_uri(HTTPretty.POST,
resource_regex,
body=self.generate_resource_response)
HTTPretty.register_uri(HTTPretty.DELETE,
resource_regex,
body=self.generate_resource_response)
# Register URIs for items
item_regex = re.compile(urljoin(self.base_url, "([a-zA-Z0-9-_]+)/([a-zA-Z0-9-_]+)"))
HTTPretty.register_uri(HTTPretty.GET,
item_regex,
body=self.generate_item_response)