def test_headers(self): details = "hmm" challenge = 'Bearer realm="https://example.com"' e1 = errors.UnauthenticatedError(details, challenge=challenge) e2 = errors.UnauthenticatedError(details, challenge=challenge) self.assertEqual( e1.headers, [("WWW-Authenticate", 'Bearer realm="https://example.com"')], ) self.assertIsNot(e1.headers, e2.headers)
def app(request): raise errors.UnauthenticatedError( "who are you?", challenge='Digest realm="https://example.com"' )
def test_with_details(self): e = errors.UnauthenticatedError("don't you know who I am?", challenge="Digest") expected_msg = "Unauthenticated: don't you know who I am?" self.assertEqual(str(e), expected_msg)
def test_http_code(self): self.assertEqual( errors.UnauthenticatedError(challenge="Digest").http_code, 401)
def test_no_details(self): e = errors.UnauthenticatedError(challenge="Digest") expected_msg = "Unauthenticated" self.assertEqual(str(e), expected_msg)