diff options
| author | Todd Willey <todd@ansolabs.com> | 2010-07-26 15:01:42 -0400 |
|---|---|---|
| committer | Todd Willey <todd@ansolabs.com> | 2010-07-26 15:01:42 -0400 |
| commit | d6e74751fa156f3879ff2136caccf2a40d4b9e8c (patch) | |
| tree | bcd57bf0efe0ee01df1cba1eddc7a3db79a522c5 /nova/tests | |
| parent | 17096b0eef78680164746303d65f9f9a50a91562 (diff) | |
Basic standup of SessionToken model for shortlived auth tokens.
Diffstat (limited to 'nova/tests')
| -rw-r--r-- | nova/tests/model_unittest.py | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/nova/tests/model_unittest.py b/nova/tests/model_unittest.py index 1bd7e527f..7823991b9 100644 --- a/nova/tests/model_unittest.py +++ b/nova/tests/model_unittest.py @@ -66,6 +66,12 @@ class ModelTestCase(test.TrialTestCase): daemon.save() return daemon + def create_session_token(self): + session_token = model.SessionToken('tk12341234') + session_token['user'] = 'testuser' + session_token.save() + return session_token + @defer.inlineCallbacks def test_create_instance(self): """store with create_instace, then test that a load finds it""" @@ -204,3 +210,49 @@ class ModelTestCase(test.TrialTestCase): if x.identifier == 'testhost:nova-testdaemon': found = True self.assertTrue(found) + + @defer.inlineCallbacks + def test_create_session_token(self): + """create""" + d = yield self.create_session_token() + d = model.SessionToken(d.token) + self.assertFalse(d.is_new_record()) + + @defer.inlineCallbacks + def test_delete_session_token(self): + """create, then destroy, then make sure loads a new record""" + instance = yield self.create_session_token() + yield instance.destroy() + newinst = yield model.SessionToken(instance.token) + self.assertTrue(newinst.is_new_record()) + + @defer.inlineCallbacks + def test_session_token_added_to_set(self): + """create, then check that it is included in list""" + instance = yield self.create_session_token() + found = False + for x in model.SessionToken.all(): + if x.identifier == instance.token: + found = True + self.assert_(found) + + @defer.inlineCallbacks + def test_session_token_associates_user(self): + """create, then check that it is listed for the user""" + instance = yield self.create_session_token() + found = False + for x in model.SessionToken.associated_to('user', 'testuser'): + if x.identifier == instance.identifier: + found = True + self.assertTrue(found) + + @defer.inlineCallbacks + def test_session_token_generation(self): + instance = yield model.SessionToken.generate('username', 'TokenType') + self.assertFalse(instance.is_new_record()) + + @defer.inlineCallbacks + def test_find_generated_session_token(self): + instance = yield model.SessionToken.generate('username', 'TokenType') + found = yield model.SessionToken.lookup(instance.identifier) + self.assert_(found) |
