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