How to use the klein.test.test_resource._render 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 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_validation.py View on Github external
def test_valid_macaddr(self):
    request = requestMock(b"/api/00:00:DE:CA:FB:AD")
    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("00:00:DE:CA:FB:AD")))
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")))
github Netflix-Skunkworks / stethoscope / tests / test_validation.py View on Github external
def test_invalid_email(self):
    request = requestMock(b"/api/not-a-valid-email")
    deferred = _render(KleinResource(self.app), request)

    self.assertEqual(self.successResultOf(deferred), None)
    self.assertEqual(request.code, 400)
    self.assertTrue(b"Invalid email address: 'not-a-valid-email'." in request.getWrittenData())
github Netflix-Skunkworks / stethoscope / tests / test_validation.py View on Github external
def test_invalid_macaddr(self):
    request = requestMock(b"/api/not-a-valid-mac")
    deferred = _render(KleinResource(self.app), request)

    self.assertEqual(self.successResultOf(deferred), None)
    self.assertEqual(request.code, 400)
    self.assertTrue(b"Invalid MAC address: 'not-a-valid-mac'." in request.getWrittenData())
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_validation.py View on Github external
def test_valid_serial(self):
    request = requestMock(b"/api/0xDECAFBAD")
    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("0xDECAFBAD")))
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_auth.py View on Github external
def test_route_match_required_with_header(self):
    request = requestMock(b"/api/user@example.com",
        headers={b'Authorization': [str(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_header_value.assert_called_once_with(str(mock.sentinel))