Skip to content

Commit

Permalink
Convert the auth test to use the helper
Browse files Browse the repository at this point in the history
  • Loading branch information
cyli committed Jul 15, 2014
1 parent cf8c9e1 commit e30f344
Showing 1 changed file with 21 additions and 21 deletions.
42 changes: 21 additions & 21 deletions mimic/test/test_auth.py
@@ -1,18 +1,18 @@

import io
import json

import treq

from twisted.trial.unittest import SynchronousTestCase
from twisted.internet.task import Clock
from characteristic import attributes

from mimic.core import MimicCore
from mimic.rest.auth_api import AuthApi
from mimic.resource import MimicRoot
from mimic.canned_responses.auth import (
get_token, HARD_CODED_TOKEN, HARD_CODED_USER_ID,
HARD_CODED_USER_NAME, HARD_CODED_ROLES,
get_endpoints
)
from mimic.test.helpers import request


class ExampleCatalogEndpoint:
Expand Down Expand Up @@ -208,30 +208,30 @@ class APITests(SynchronousTestCase):

def test_token_has_token(self):
"""
AuthApi.get_service_catalog_and_token (the handler for
``/identity/v2.0/tokens``) returns a JSON response with an
access.token.id key corresponding to its MimicCore session, and
therefore access.token.tenant.id should match that session's tenant_id.
"""
core = MimicCore(Clock())
api = AuthApi(core)

@attributes(["content"])
class FakeRequest(object):
def setResponseCode(self, responsecode):
pass
request = FakeRequest(content=io.BytesIO(json.dumps(
{"auth": {
"passwordCredentials": {
"username": "demoauthor",
"password": "theUsersPassword"
root = MimicRoot(core).app.resource()

response = request(
self, root, "POST", "/identity/v2.0/tokens",
json.dumps({
"auth": {
"passwordCredentials": {
"username": "demoauthor",
"password": "theUsersPassword"
}
}
}}))
})
)
result = api.get_service_catalog_and_token(request)
value = json.loads(result)
token = value['access']['token']['id']
tenant_id = value['access']['token']['tenant']['id']

auth_response = self.successResultOf(response)
json_body = self.successResultOf(treq.json_content(auth_response))

token = json_body['access']['token']['id']
tenant_id = json_body['access']['token']['tenant']['id']
session = core.session_for_token(token)
self.assertEqual(token, session.token)
self.assertEqual(tenant_id, session.tenant_id)

0 comments on commit e30f344

Please sign in to comment.