-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added basic getter for tenant and user details #28
Changes from all commits
11fc21f
df066a5
a9c4d83
ebdf04a
78aeca9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
""" | ||
Stack-In-A-Box: Basic Test | ||
""" | ||
import json | ||
import unittest | ||
|
||
import httpretty | ||
import mock | ||
import requests | ||
import stackinabox.util_httpretty | ||
from stackinabox.stack import StackInABox | ||
|
||
from openstackinabox.models.keystone.model import KeystoneModel | ||
from openstackinabox.services.keystone import KeystoneV2Service | ||
|
||
|
||
@httpretty.activate | ||
class TestKeystoneV2GetAdmin(unittest.TestCase): | ||
|
||
def setUp(self): | ||
super(TestKeystoneV2GetAdmin, self).setUp() | ||
self.keystone = KeystoneV2Service() | ||
|
||
self.headers = { | ||
'x-auth-token': self.keystone.model.get_admin_token() | ||
} | ||
self.tenant_id = self.keystone.model.add_tenant(tenantname='neo', | ||
description='The One') | ||
self.user_info = { | ||
'user': { | ||
'username': 'trinity', | ||
'enabled': True, | ||
'email': '[email protected]', | ||
'password': 'Inl0veWithNeo' | ||
} | ||
} | ||
self.user_info['user']['userid'] =\ | ||
self.keystone.model.add_user(tenantid=self.tenant_id, | ||
username=self.user_info['user'][ | ||
'username'], | ||
email=self.user_info['user']['email'], | ||
password=self.user_info['user'][ | ||
'password'], | ||
enabled=self.user_info['user'][ | ||
'enabled']) | ||
self.keystone.model.add_token(self.tenant_id, | ||
self.user_info['user']['userid']) | ||
self.keystone.model.add_user_role_by_rolename( | ||
tenantid=self.tenant_id, | ||
userid=self.user_info['user']['userid'], | ||
rolename=self.keystone.model.IDENTITY_ADMIN_ROLE) | ||
StackInABox.register_service(self.keystone) | ||
|
||
|
||
def tearDown(self): | ||
super(TestKeystoneV2GetAdmin, self).tearDown() | ||
StackInABox.reset_services() | ||
|
||
@staticmethod | ||
def get_userid_url(host, userid): | ||
return 'http://{0}/keystone/v2.0/users/{1}/RAX-AUTH/admins'\ | ||
.format(host, userid) | ||
|
||
def test_get_admin_user_basic(self): | ||
stackinabox.util_httpretty.httpretty_registration('localhost') | ||
|
||
user_data = self.keystone.model.get_token_by_userid( | ||
self.user_info['user']['userid']) | ||
|
||
url = TestKeystoneV2GetAdmin.get_userid_url( | ||
'localhost', | ||
self.user_info['user']['userid']) | ||
|
||
self.headers['x-auth-token'] = user_data['token'] | ||
res = requests.get(url, | ||
headers=self.headers, | ||
data='') | ||
self.assertEqual(res.status_code, 200) | ||
|
||
def test_get_admin_user_incorrect_request(self): | ||
stackinabox.util_httpretty.httpretty_registration('localhost') | ||
|
||
user_data = self.keystone.model.get_token_by_userid( | ||
self.user_info['user']['userid']) | ||
|
||
url = TestKeystoneV2GetAdmin.get_userid_url( | ||
'localhost', | ||
self.user_info['user']['userid']) | ||
|
||
res = requests.get(url, | ||
headers=self.headers, | ||
data='') | ||
self.assertEqual(res.status_code, 404) | ||
|
||
def test_get_admin_user_no_token(self): | ||
stackinabox.util_httpretty.httpretty_registration('localhost') | ||
|
||
url = TestKeystoneV2GetAdmin.get_userid_url( | ||
'localhost', | ||
self.user_info['user']['userid']) | ||
|
||
res = requests.get(url, headers=None, data='') | ||
self.assertEqual(res.status_code, 403) | ||
|
||
def test_get_admin_user_invalid_token(self): | ||
stackinabox.util_httpretty.httpretty_registration('localhost') | ||
|
||
url = TestKeystoneV2GetAdmin.get_userid_url( | ||
'localhost', | ||
self.user_info['user']['userid']) | ||
self.headers['x-auth-token'] = 'new_token' | ||
res = requests.get(url, | ||
headers=self.headers, | ||
data='') | ||
self.assertEqual(res.status_code, 401) | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
""" | ||
Stack-In-A-Box: Basic Test | ||
""" | ||
import json | ||
import unittest | ||
|
||
import httpretty | ||
import mock | ||
import requests | ||
import stackinabox.util_httpretty | ||
from stackinabox.stack import StackInABox | ||
|
||
from openstackinabox.models.keystone.model import KeystoneModel | ||
from openstackinabox.services.keystone import KeystoneV2Service | ||
|
||
|
||
@httpretty.activate | ||
class TestKeystoneModel(unittest.TestCase): | ||
|
||
def setUp(self): | ||
super(TestKeystoneModel, self).setUp() | ||
self.keystone = KeystoneV2Service() | ||
self.headers = { | ||
'x-auth-token': self.keystone.model.get_admin_token() | ||
} | ||
|
||
def tearDown(self): | ||
super(TestKeystoneModel, self).tearDown() | ||
StackInABox.reset_services() | ||
|
||
def test_keystone_set_model(self): | ||
with self.assertRaises(TypeError): | ||
self.keystone.model = None | ||
|
||
self.keystone.model = KeystoneModel() | ||
|
||
def test_get_tenant_details(self): | ||
stackinabox.util_httpretty.httpretty_registration('localhost') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no need to register |
||
tenant_details = self.keystone.model.get_admin_tenant_details | ||
self.assertEqual(tenant_details['name'], 'system') | ||
self.assertEqual(tenant_details['description'], 'system administrator') | ||
|
||
def test_get_user_details(self): | ||
user_details = self.keystone.model.get_admin_user_details | ||
self.assertEqual(user_details['username'], 'system') | ||
self.assertEqual(user_details['email'], 'system@stackinabox') | ||
self.assertEqual(user_details['password'], 'stackinabox') | ||
self.assertEqual(user_details['apikey'], '537461636b496e41426f78') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Split the second half for the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as https://github.com/BenjamenMeyer/openstackinabox/pull/28/files#r31276988 but with respect to the user information...