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_body(self):
httpretty.register_uri(httpretty.POST, 'http://example.com/',
body='[]')
secret = 's33333krit'
auth = JWTAuth(secret)
auth.add_field('body', requests_jwt.payload_body)
resp = requests.post('http://example.com/',
data={'Hope this': 'Is encoded'},
auth=auth)
req = httpretty.last_request()
auth_hdr = req.headers['Authorization']
token = auth_hdr[auth_hdr.find('"'):].strip('"')
claim = jwt.decode(token, secret)
self.assertEqual(claim['body']['hash'],
hashlib.sha256(req.body).hexdigest())
HTTPretty.GET,
"https://api.zotero.org/itemFields",
body=self.item_fields,
content_type="application/json",
)
HTTPretty.register_uri(
HTTPretty.PATCH,
"https://api.zotero.org/users/myuserID/items/ABC123",
body="",
content_type="application/json",
status=204,
)
# now let's test something
resp = zot.update_item(update)
self.assertEqual(resp, True)
request = httpretty.last_request()
self.assertEqual(request.headers["If-Unmodified-Since-Version"], "3")
'pagesize': ['1'],
'order': ['desc'],
'sort': ['activity'],
'tagged': ['python'],
'site': ['stackoverflow'],
'key': ['aaa'],
'filter': [QUESTIONS_FILTER],
'min': [str(from_date_unixtime)]
}
client = StackExchangeClient(site="stackoverflow", tagged="python", token="aaa", max_questions=1)
raw_questions = [questions for questions in client.get_questions(from_date=from_date)]
self.assertEqual(len(raw_questions), 1)
self.assertEqual(raw_questions[0], question)
self.assertDictEqual(httpretty.last_request().querystring, payload)
self.assertEqual(len(group_tweets), 2)
expected = {
'q': ['query'],
'since_id': ['1'],
'max_id': ['1005163131042193407'],
'count': ['2'],
'include_entities': ['False'],
'result_type': ['popular'],
'geocode': ['37.781157 -122.398720 1km'],
'lang': ['eu']
}
self.assertDictEqual(httpretty.last_request().querystring, expected)
self.assertEqual(httpretty.last_request().headers["Authorization"], "Bearer aaa")
def test_open_shutter(self, device):
url = BASE_URL + "/device/device-9/exec"
httpretty.register_uri(httpretty.POST, url, body='{"job_id": "9"}')
device.open_shutter()
assert httpretty.last_request().parsed_body == {
"name": "shutter_open",
"parameters": [],
}
"reason" : "",
"sessionId" : "SESSIONID",
"size" : 42165242,
"status" : "available",
"hasAudio": true,
"hasVideo": true,
"outputMode": "composed",
"url" : "http://tokbox.com.archive2.s3.amazonaws.com/123456%2F832641bf-5dbf-41a1-ad94-fea213e59a92%2Farchive.mp4?Expires=1395188695&AWSAccessKeyId=AKIAI6LQCPIXYVWCQV6Q&Signature=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
} ]
}""")),
status=200,
content_type=u('application/json'))
archive_list = self.opentok.get_archives()
validate_jwt_header(self, httpretty.last_request().headers[u('x-opentok-auth')])
expect(httpretty.last_request().headers[u('user-agent')]).to(contain(u('OpenTok-Python-SDK/')+__version__))
expect(httpretty.last_request().headers[u('content-type')]).to(equal(u('application/json')))
expect(archive_list).to(be_an(ArchiveList))
expect(archive_list).to(have_property(u('count'), 6))
expect(list(archive_list.items)).to(have_length(6))
# TODO: we could inspect each item in the list
('c4f3c8c773e8e26eb87b7f5e014768b7977f82e3', 1458596193.695)]
for x in range(len(expected)):
build = builds[x]
self.assertEqual(build['origin'], 'http://example.com/ci')
self.assertEqual(build['uuid'], expected[x][0])
self.assertEqual(build['updated_on'], expected[x][1])
self.assertEqual(build['category'], 'build')
self.assertEqual(build['tag'], 'http://example.com/ci')
# Check request params
expected = {
'depth': ['1']
}
req = httpretty.last_request()
self.assertEqual(req.method, 'GET')
self.assertRegex(req.path, '/ci/job')
self.assertDictEqual(req.querystring, expected)
client = GitHubClient("zhquan_example", "repo", "aaa",
base_url=GITHUB_ENTERPRISE_URL)
raw_issues = [issues for issues in client.issues()]
self.assertEqual(raw_issues[0], issue)
# Check requests
expected = {
'per_page': ['100'],
'state': ['all'],
'direction': ['asc'],
'sort': ['updated']
}
self.assertDictEqual(httpretty.last_request().querystring, expected)
self.assertEqual(httpretty.last_request().headers["Authorization"], "token aaa")
old_password = uuid.uuid4().hex
new_password = uuid.uuid4().hex
self.stub_url(httpretty.POST,
[self.collection_key, self.TEST_USER, 'password'])
self.client.user_id = self.TEST_USER
self.manager.update_password(old_password, new_password)
exp_req_body = {
'user': {
'password': new_password, 'original_password': old_password
}
}
self.assertEqual('/v3/users/test/password',
httpretty.last_request().path)
self.assertRequestBodyIs(json=exp_req_body)
def test_url_extra_slashes(self):
util.setup_expected_instance_discovery_request(200,
cp['authorityHosts']['global'],
{
'tenant_discovery_endpoint': 'http://foobar'
},
self.nonHardCodedAuthorizeEndpoint)
authority_url = self.nonHardCodedAuthority + '/' # This should pass for one or more than one slashes
authority = Authority(authority_url, True)
obj = util.create_empty_adal_object()
authority.validate(obj['call_context'])
req = httpretty.last_request()
util.match_standard_request_headers(req)