コード例 #1
0
ファイル: test_security.py プロジェクト: anbangr/trusted-juju
class TokenDatabaseTest(TestCase):

    @inlineCallbacks
    def setUp(self):
        zookeeper.set_debug_level(0)
        self.client = yield self.get_zookeeper_client().connect()
        self.db = TokenDatabase(self.client, "/token-test")

    def tearDown(self):
        deleteTree(handle=self.client.handle)
        self.client.close()

    @inlineCallbacks
    def test_add(self):
        principal = Principal("zebra", "zoo")
        yield self.db.add(principal)
        content, stat = yield self.client.get("/token-test")
        data = yaml.load(content)
        self.assertEqual(data, {"zebra": principal.get_token()})

    @inlineCallbacks
    def test_remove(self):
        principal = Principal("zebra", "zoo")
        yield self.db.add(principal)
        yield self.db.remove(principal)
        content, stat = yield self.client.get("/token-test")
        data = yaml.load(content)
        self.assertEqual(data, {"zebra": principal.get_token()})

    @inlineCallbacks
    def test_get(self):
        principal = Principal("zebra", "zoo")
        yield self.db.add(principal)
        token = yield self.db.get(principal.name)
        self.assertEqual(token, principal.get_token())

    @inlineCallbacks
    def test_get_nonexistant(self):
        principal = Principal("zebra", "zoo")
        error = yield self.assertFailure(self.db.get(principal.name),
                                   PrincipalNotFound)
        self.assertEquals(str(error), "Principal 'zebra' not found")
コード例 #2
0
class TokenDatabaseTest(TestCase):
    @inlineCallbacks
    def setUp(self):
        zookeeper.set_debug_level(0)
        self.client = yield self.get_zookeeper_client().connect()
        self.db = TokenDatabase(self.client, "/token-test")

    def tearDown(self):
        deleteTree(handle=self.client.handle)
        self.client.close()

    @inlineCallbacks
    def test_add(self):
        principal = Principal("zebra", "zoo")
        yield self.db.add(principal)
        content, stat = yield self.client.get("/token-test")
        data = yaml.load(content)
        self.assertEqual(data, {"zebra": principal.get_token()})

    @inlineCallbacks
    def test_remove(self):
        principal = Principal("zebra", "zoo")
        yield self.db.add(principal)
        yield self.db.remove(principal)
        content, stat = yield self.client.get("/token-test")
        data = yaml.load(content)
        self.assertEqual(data, {"zebra": principal.get_token()})

    @inlineCallbacks
    def test_get(self):
        principal = Principal("zebra", "zoo")
        yield self.db.add(principal)
        token = yield self.db.get(principal.name)
        self.assertEqual(token, principal.get_token())

    @inlineCallbacks
    def test_get_nonexistant(self):
        principal = Principal("zebra", "zoo")
        error = yield self.assertFailure(self.db.get(principal.name),
                                         PrincipalNotFound)
        self.assertEquals(str(error), "Principal 'zebra' not found")