clean up TestHttpBasicAuth
This commit is contained in:
+11
-21
@@ -1,27 +1,17 @@
|
||||
# coding=UTF-8
|
||||
|
||||
import unittest2
|
||||
import flask_testing
|
||||
import base64
|
||||
from api import create_app
|
||||
|
||||
try:
|
||||
import httplib
|
||||
except ImportError:
|
||||
# support for python 3
|
||||
import http.client as httplib
|
||||
|
||||
|
||||
class ApiTest(unittest2.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
self.app = create_app('tests.config')
|
||||
self.client = self.app.test_client()
|
||||
|
||||
|
||||
class TestHttpBasicAuth(ApiTest):
|
||||
class TestHttpBasicAuth(flask_testing.TestCase):
|
||||
|
||||
api_key = 'secret'
|
||||
|
||||
def create_app(self):
|
||||
return create_app('tests.config')
|
||||
|
||||
def _enable_basic_auth(self):
|
||||
self.app.config['API_KEYS'] = [self.api_key]
|
||||
|
||||
@@ -32,15 +22,15 @@ class TestHttpBasicAuth(ApiTest):
|
||||
|
||||
def test_missing_credentials(self):
|
||||
self._enable_basic_auth()
|
||||
resp = self.client.get('/')
|
||||
self.assertEqual(resp.status_code, httplib.UNAUTHORIZED)
|
||||
response = self.client.get('/')
|
||||
self.assert401(response)
|
||||
|
||||
def test_correct_credentials(self):
|
||||
self._enable_basic_auth()
|
||||
headers = self._create_auth_headers(self.api_key)
|
||||
resp = self.client.get('/', headers=headers)
|
||||
self.assertEqual(resp.status_code, httplib.OK)
|
||||
response = self.client.get('/', headers=headers)
|
||||
self.assert200(response)
|
||||
|
||||
def test_basic_auth_disabled(self):
|
||||
resp = self.client.get('/')
|
||||
self.assertEqual(resp.status_code, httplib.OK)
|
||||
response = self.client.get('/')
|
||||
self.assert200(response)
|
||||
Reference in New Issue
Block a user