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_9_by_tx(self):
mock_req = requestMock(path=b'/tx/0x4c927a7f365cb842ea3576eae474a89183c9e43970a8509b23570a86cb4f5121')
res = self.app.get_by_tx(mock_req, '0x4c927a7f365cb842ea3576eae474a89183c9e43970a8509b23570a86cb4f5121')
jsn = json.loads(res)
self.assertEqual(jsn['total'], 1)
results = jsn['results']
self.assertEqual(len(results), 1)
def mock_post_request(body):
return requestMock(path=b'/', method=b"POST", body=body)
def test_get_host_nonstandard_https_port(hostchecker):
request = requestMock(b"/foo", host=b'example.com', port=8443, isSecure=True)
request.requestHeaders.removeHeader(b'host') # force hostchecker to use transport attributes
assert hostchecker.get_host(request) == 'example.com:8443'
def test_route_match_required_with_cookie(self):
request = requestMock(b"/api/user@example.com")
request.received_cookies = {b'token': mock.sentinel}
deferred = _render(self.kr, request)
self.assertEqual(self.successResultOf(deferred), None)
self.assertEqual(request.getWrittenData(), json.dumps(self.userinfo).encode('ascii'))
self.auth.decode_token.assert_called_once_with(mock.sentinel)
def test_invalid_serial(self):
request = requestMock(b"/api/not a valid serial")
deferred = _render(KleinResource(self.app), request)
self.assertEqual(self.successResultOf(deferred), None)
self.assertEqual(request.code, 400)
self.assertTrue(b"Invalid serial number: 'not a valid serial'." in request.getWrittenData())
def check_result(self, app, path, expected, callback=None):
# see klein's test_resource.py
request = klein.test.test_resource.requestMock(path)
deferred = klein.test.test_resource._render(KleinResource(app), request)
self.assertEqual(self.successResultOf(deferred), None)
self.assertEqual(request.getWrittenData(), six.b(json.dumps(expected)))
if callback is not None:
callback.assert_called_once_with(expected)
def test_get_host_untrusted():
hostchecker_ = hostchecker({'TRUSTED_HOSTS': ['example.net']})
request = requestMock(b"/foo", host=b'example.com', port=80)
with pytest.raises(werkzeug.exceptions.SecurityError):
hostchecker_.get_host(request)
def test_valid_email(self):
request = requestMock(b"/api/user@example.com")
deferred = _render(KleinResource(self.app), request)
self.assertEqual(self.successResultOf(deferred), None)
self.assertEqual(request.code, 200)
self.assertEqual(request.getWrittenData(), six.b(json.dumps("user@example.com")))