From: Crístian Viana <vianac(a)linux.vnet.ibm.com>
The "fake_user" credentials are used along with the mockmodel. Instead
of having it declared on a test file, move the declaration to a more
generic place.
Move the "fake_user" credentials from the test files to the mockmodel.
Signed-off-by: Crístian Viana <vianac(a)linux.vnet.ibm.com>
---
src/kimchi/mockmodel.py | 3 +++
tests/test_rest.py | 8 ++++----
tests/utils.py | 7 +++----
3 files changed, 10 insertions(+), 8 deletions(-)
diff --git a/src/kimchi/mockmodel.py b/src/kimchi/mockmodel.py
index 0e45d1e..f8e33b7 100644
--- a/src/kimchi/mockmodel.py
+++ b/src/kimchi/mockmodel.py
@@ -57,6 +57,9 @@
from kimchi.vmtemplate import VMTemplate
+fake_user = { 'admin': 'letmein!' }
+
+
class MockModel(object):
def __init__(self, objstore_loc=None):
self.reset()
diff --git a/tests/test_rest.py b/tests/test_rest.py
index 3c8c537..935ed81 100644
--- a/tests/test_rest.py
+++ b/tests/test_rest.py
@@ -35,7 +35,7 @@
import kimchi.mockmodel
import kimchi.server
from kimchi.rollbackcontext import RollbackContext
-from utils import fake_user, get_free_port, patch_auth, request
+from utils import get_free_port, patch_auth, request
from utils import run_server
@@ -108,7 +108,7 @@ def test_404(self):
# We must be authenticated first. Otherwise all requests will return
# HTTP:401. Since HTTP Simple Auth is not allowed for text/html, we
# need to use the login API and establish a session.
- user, pw = fake_user.items()[0]
+ user, pw = kimchi.mockmodel.fake_user.items()[0]
req = json.dumps({'username': user, 'password': pw})
resp = self.request('/login', req, 'POST')
self.assertEquals(200, resp.status)
@@ -1502,7 +1502,7 @@ def test_auth_unprotected(self):
resp = self.request(uri, None, 'HEAD', hdrs)
self.assertEquals(200, resp.status)
- user, pw = fake_user.items()[0]
+ user, pw = kimchi.mockmodel.fake_user.items()[0]
req = json.dumps({'username': user, 'password': pw})
resp = self.request('/login', req, 'POST', hdrs)
self.assertEquals(200, resp.status)
@@ -1548,7 +1548,7 @@ def test_auth_session(self):
self.assertEquals(401, resp.status)
# Execute a login call
- user, pw = fake_user.items()[0]
+ user, pw = kimchi.mockmodel.fake_user.items()[0]
req = json.dumps({'username': user, 'password': pw})
resp = self.request('/login', req, 'POST', hdrs)
self.assertEquals(200, resp.status)
diff --git a/tests/utils.py b/tests/utils.py
index 12961cc..f452854 100644
--- a/tests/utils.py
+++ b/tests/utils.py
@@ -32,13 +32,12 @@
from lxml import etree
+import kimchi.mockmodel
import kimchi.server
from kimchi.exception import OperationFailed
_ports = {}
-fake_user = {'admin': 'letmein!'}
-
# provide missing unittest decorators and API for python 2.6; these decorators
# do not actually work, just avoid the syntax failure
if sys.version_info[:2] == (2, 6):
@@ -136,7 +135,7 @@ def _request(conn, path, data, method, headers):
headers = {'Content-Type': 'application/json',
'Accept': 'application/json'}
if 'AUTHORIZATION' not in headers.keys():
- user, pw = fake_user.items()[0]
+ user, pw = kimchi.mockmodel.fake_user.items()[0]
hdr = "Basic " + base64.b64encode("%s:%s" % (user, pw))
headers['AUTHORIZATION'] = hdr
conn.request(method, path, data, headers)
@@ -162,7 +161,7 @@ def _has_sudo(self, result):
def _authenticate(username, password, service="passwd"):
try:
- return fake_user[username] == password
+ return kimchi.mockmodel.fake_user[username] == password
except KeyError, e:
raise OperationFailed("KCHAUTH0001E", {'username':
'username',
'code': e.message})
--
1.9.3