def test_valid_auth(self): http_auth = 'Basic {0}'.format(base64.encodestring(settings.API_KEY)) request = self.req_factory.post('/api/v1/metric/', {}, HTTP_AUTHORIZATION=http_auth) auth = SettingsAuthentication() auth_resp = auth.authenticate(request) self.assertFalse(auth_resp is None, "Authentication failed")
def test_valid_auth(self): http_auth = 'Basic {0}'.format( base64.encodestring(settings.API_KEY)) request = self.req_factory.post('/api/v1/metric/', {}, HTTP_AUTHORIZATION=http_auth) auth = SettingsAuthentication() auth_resp = auth.authenticate(request) self.assertFalse(auth_resp is None, "Authentication failed")
def test_invalid_auth(self): http_auth = 'Basic {0}'.format(base64.encodestring('wrongkey')) request = self.req_factory.post('/api/v1/metric/', {}, HTTP_AUTHORIZATION=http_auth) auth = SettingsAuthentication() self.assertRaises(exceptions.AuthenticationFailed, auth.authenticate, request)
def test_no_auth(self): request = self.req_factory.post('/api/v1/metric/', {}) auth = SettingsAuthentication() auth_resp = auth.authenticate(request) self.assertTrue(auth_resp is None, "Authentication succeeded")