add some tests and get others to pass
This commit is contained in:
parent
4c8a5ac747
commit
912c222703
|
@ -27,12 +27,13 @@ class KvsIdentity(object):
|
|||
user_ref = self.get_user(user_id)
|
||||
tenant_ref = None
|
||||
extras_ref = None
|
||||
if user_ref['password'] != password:
|
||||
if not user_ref or user_ref.get('password') != password:
|
||||
raise AssertionError('Invalid user / password')
|
||||
if tenant_id and tenant_id not in user_ref['tenants']:
|
||||
raise AssertionError('Invalid tenant')
|
||||
|
||||
if tenant_id and tenant_id in user_ref['tenants']:
|
||||
tenant_ref = self.get_tenant(tenant_id)
|
||||
extras_ref = self.get_extras(user_id, tenant_id)
|
||||
tenant_ref = self.get_tenant(tenant_id)
|
||||
extras_ref = self.get_extras(user_id, tenant_id)
|
||||
return (user_ref, tenant_ref, extras_ref)
|
||||
|
||||
def get_tenant(self, tenant_id):
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
import ConfigParser
|
||||
import logging
|
||||
import os
|
||||
import unittest
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
from paste import deploy
|
||||
|
@ -24,13 +26,16 @@ def checkout_vendor(repo, rev):
|
|||
name = name[:-4]
|
||||
|
||||
revdir = os.path.join(VENDOR, '%s-%s' % (name, rev.replace('/', '_')))
|
||||
try:
|
||||
if not os.path.exists(revdir):
|
||||
utils.git('clone', repo, revdir)
|
||||
|
||||
if not os.path.exists(revdir):
|
||||
utils.git('clone', repo, revdir)
|
||||
|
||||
cd(revdir)
|
||||
utils.git('pull')
|
||||
utils.git('checkout', '-q', rev)
|
||||
cd(revdir)
|
||||
utils.git('pull')
|
||||
utils.git('checkout', '-q', rev)
|
||||
except subprocess.CalledProcessError as e:
|
||||
logging.warning('Failed to checkout %s', repo)
|
||||
pass
|
||||
return revdir
|
||||
|
||||
|
||||
|
|
|
@ -21,7 +21,9 @@ class KvsIdentity(test.TestCase):
|
|||
name='FOO',
|
||||
password='foo2',
|
||||
tenants=[self.tenant_bar['id']]))
|
||||
|
||||
self.extras_foobar = self.identity_api._create_extras(
|
||||
'foo', 'bar',
|
||||
{'extra': 'extra'})
|
||||
|
||||
def test_authenticate_bad_user(self):
|
||||
self.assertRaises(AssertionError,
|
||||
|
@ -37,10 +39,26 @@ class KvsIdentity(test.TestCase):
|
|||
tenant_id=self.tenant_bar['id'],
|
||||
password=self.user_foo['password'] + 'WRONG')
|
||||
|
||||
|
||||
def test_authenticate_invalid_tenant(self):
|
||||
self.assertRaises(AssertionError,
|
||||
self.identity_api.authenticate,
|
||||
user_id=self.user_foo['id'],
|
||||
tenant_id=self.tenant_bar['id'] + 'WRONG',
|
||||
password=self.user_foo['password'])
|
||||
|
||||
def test_authenticate_no_tenant(self):
|
||||
user_ref, tenant_ref, extras_ref = self.identity_api.authenticate(
|
||||
user_id=self.user_foo['id'],
|
||||
password=self.user_foo['password'])
|
||||
self.assertDictEquals(user_ref, self.user_foo)
|
||||
self.assert_(tenant_ref is None)
|
||||
self.assert_(extras_ref is None)
|
||||
|
||||
def test_authenticate(self):
|
||||
user_ref, tenant_ref, extras_ref = self.identity_api.authenticate(
|
||||
user_id=self.user_foo['id'],
|
||||
tenant_id=self.tenant_bar['id'],
|
||||
password=self.user_foo['password'])
|
||||
self.assertDictEquals(user_ref, self.user_foo)
|
||||
self.assertDictEquals(tenant_ref, self.tenant_bar)
|
||||
self.assertDictEquals(extras_ref, self.extras_foobar)
|
||||
|
|
Loading…
Reference in New Issue