How to use the klein.test.test_resource.requestMock function in klein

To help you get started, we’ve selected a few klein examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ddi-lab / generion-middleware / neo / api / REST / test_notification_rest_api.py View on Github external
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)
github CityOfZion / neo-python / neo / api / JSONRPC / test_json_rpc_api.py View on Github external
def mock_post_request(body):
    return requestMock(path=b'/', method=b"POST", body=body)
github Netflix-Skunkworks / stethoscope / tests / test_hostchecker.py View on Github external
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'
github Netflix-Skunkworks / stethoscope / tests / test_auth.py View on Github external
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)
github Netflix-Skunkworks / stethoscope / tests / test_validation.py View on Github external
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())
github Netflix-Skunkworks / stethoscope / tests / test_factory.py View on Github external
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)
github Netflix-Skunkworks / stethoscope / tests / test_hostchecker.py View on Github external
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)
github Netflix-Skunkworks / stethoscope / tests / test_validation.py View on Github external
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")))