1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
|
# Tests for SecretStorage
# Author: Dmitry Shachnev, 2013
# License: BSD
# This file tests the compatibility functions in __init__.py.
import secretstorage
import random
import unittest
rand = str(random.randint(0, 1000))
ATTRIBUTES = {'application': 'secretstorage-test', 'attribute': rand}
PASSWORD = b'pa$$word'
class CompatFunctionsTest(unittest.TestCase):
"""A test case that tests compatibility functions, based on old
SecretStorage test."""
@classmethod
def setUpClass(cls):
cls.item_id = secretstorage.create_item('Test item',
ATTRIBUTES, PASSWORD)
def test_get_items(self):
attrs, secret = secretstorage.get_items(ATTRIBUTES)[-1]
self.assertEqual(attrs['application'], 'secretstorage-test')
self.assertEqual(secret, PASSWORD)
def test_get_items_ids(self):
item_id = secretstorage.get_items_ids(ATTRIBUTES)[-1]
self.assertEqual(item_id, self.item_id)
def test_get_item(self):
attrs, secret = secretstorage.get_item(self.item_id)
self.assertEqual(attrs['application'], 'secretstorage-test')
self.assertEqual(secret, PASSWORD)
def test_get_item_attributes(self):
attrs = secretstorage.get_item_attributes(self.item_id)
self.assertEqual(attrs['application'], 'secretstorage-test')
self.assertEqual(attrs['attribute'], rand)
@classmethod
def tearDownClass(cls):
secretstorage.delete_item(cls.item_id)
if __name__ == '__main__':
unittest.main()
|