Ejemplo n.º 1
0
def keystone_request_callback(request, uri, headers):
    response_headers = {"content-type": "application/json"}
    token_id = TOKENID
    if uri == BASE_URL:
        return (200, headers, V3_VERSION_LIST)
    elif uri == BASE_URL + "/v2.0":
        v2_token = ks_v2_fixture.Token(token_id)
        return (200, response_headers, json.dumps(v2_token))
    elif uri == BASE_URL + "/v3":
        v3_token = ks_v3_fixture.Token()
        response_headers["X-Subject-Token"] = token_id
        return (201, response_headers, json.dumps(v3_token))
class TestBetamaxFixture(testtools.TestCase):

    TEST_USERNAME = '******'
    TEST_PASSWORD = '******'
    TEST_TENANT_NAME = 'test_tenant_name'
    TEST_AUTH_URL = 'http://keystoneauth-betamax.test/v2.0/'

    V2_TOKEN = v2Fixtures.Token(tenant_name=TEST_TENANT_NAME,
                                user_name=TEST_USERNAME)

    def setUp(self):
        super(TestBetamaxFixture, self).setUp()
        self.ksa_betamax_fixture = self.useFixture(
            keystoneauth_betamax.BetamaxFixture(
                cassette_name='ksa_betamax_test_cassette',
                cassette_library_dir='keystoneauth1/tests/unit/data/',
                record=False))

    def _replay_cassette(self):
        plugin = v2.Password(
            auth_url=self.TEST_AUTH_URL,
            password=self.TEST_PASSWORD,
            username=self.TEST_USERNAME,
            tenant_name=self.TEST_TENANT_NAME)
        s = session.Session()
        s.get_token(auth=plugin)

    def test_keystoneauth_betamax_fixture(self):
        self._replay_cassette()

    def test_replay_of_bad_url_fails(self):
        plugin = v2.Password(
            auth_url='http://invalid-auth-url/v2.0/',
            password=self.TEST_PASSWORD,
            username=self.TEST_USERNAME,
            tenant_name=self.TEST_TENANT_NAME)
        s = session.Session()
        self.assertRaises(exceptions.BetamaxError, s.get_token, auth=plugin)
Ejemplo n.º 3
0
 def clear_tokens(self):
     self.v2_token = v2.Token(tenant_id=self.project_id)
     self.v3_token = v3.Token(project_id=self.project_id)