Exemple #1
0
 def test_esme_init_with_simple_keyvaluestore(self):
     key_value_store = KeyValueStore()
     self.esme = ESME(None, key_value_store, None)
     kvstc = KeyValueStoreTestCase()
     kvstc.prefix = __name__
     kvstc.run_all_tests_on_instance(self.esme.kvs)
     self.assertTrue(key_value_store.is_empty())
Exemple #2
0
 def setUp(self):
     self.kvs = KeyValueStore()
     KeyValueBase.register(self.kvs.__class__)
     self.prefix = "smpp_test_%s" % uuid.uuid4()
Exemple #3
0
class KeyValueStoreTestCase(unittest.TestCase):

    def setUp(self):
        self.kvs = KeyValueStore()
        KeyValueBase.register(self.kvs.__class__)
        self.prefix = "smpp_test_%s" % uuid.uuid4()

    def tearDown(self):
        pass

    def run_all_tests_on_instance(self, instance):
        self.kvs = instance
        KeyValueBase.register(instance.__class__)
        self.test_implements_abstract()
        self.test_set_get_delete()
        self.test_incr()

    def test_instance_test(self):
        newKeyValueStoreTestCase = KeyValueStoreTestCase()
        newKeyValueStoreTestCase.prefix = "smpp_test_%s" % uuid.uuid4()
        instance = KeyValueStore()
        newKeyValueStoreTestCase.run_all_tests_on_instance(instance)

    def test_implements_abstract(self):
        self.assertTrue(issubclass(KeyValueStore, KeyValueBase))
        self.assertTrue(isinstance(self.kvs, KeyValueBase))

    def test_set_get_delete(self):
        key1 = "%s#cookie" % self.prefix

        try:
            self.assertEqual(self.kvs.get(key1), None)
            self.kvs.set(key1, "monster")
            self.assertEqual(self.kvs.get(key1), "monster")
            self.kvs.set(key1, "crumbles")
            self.assertNotEqual(self.kvs.get(key1), "monster")
            self.assertEqual(self.kvs.get(key1), "crumbles")
            self.assertEqual(self.kvs.delete(key1), True)
            self.assertEqual(self.kvs.get(key1), None)

        except:
            self.kvs.delete(key1)
            raise

    def test_incr(self):
        key1 = "%s#counter" % self.prefix

        try:
            self.assertEqual(self.kvs.get(key1), None)
            self.assertEqual(self.kvs.incr(key1), 1)
            self.kvs.set(key1, 1)
            self.assertEqual(self.kvs.incr(key1), 2)
            self.kvs.set(key1, "1")
            self.assertEqual(self.kvs.incr(key1), 2)
            self.kvs.delete(key1)
            self.assertEqual(self.kvs.incr(key1), 1)
            self.assertEqual(self.kvs.incr(key1), 2)
            self.assertEqual(self.kvs.incr(key1), 3)
            self.assertEqual(self.kvs.delete(key1), True)

        except:
            self.kvs.delete(key1)
            raise
Exemple #4
0
 def test_instance_test(self):
     newKeyValueStoreTestCase = KeyValueStoreTestCase()
     newKeyValueStoreTestCase.prefix = "smpp_test_%s" % uuid.uuid4()
     instance = KeyValueStore()
     newKeyValueStoreTestCase.run_all_tests_on_instance(instance)
Exemple #5
0
 def setUp(self):
     self.kvs = KeyValueStore()
     KeyValueBase.register(self.kvs.__class__)
     self.prefix = "smpp_test_%s" % uuid.uuid4()
Exemple #6
0
class KeyValueStoreTestCase(unittest.TestCase):
    def setUp(self):
        self.kvs = KeyValueStore()
        KeyValueBase.register(self.kvs.__class__)
        self.prefix = "smpp_test_%s" % uuid.uuid4()

    def tearDown(self):
        pass

    def run_all_tests_on_instance(self, instance):
        self.kvs = instance
        KeyValueBase.register(instance.__class__)
        self.test_implements_abstract()
        self.test_set_get_delete()
        self.test_incr()

    def test_instance_test(self):
        newKeyValueStoreTestCase = KeyValueStoreTestCase()
        newKeyValueStoreTestCase.prefix = "smpp_test_%s" % uuid.uuid4()
        instance = KeyValueStore()
        newKeyValueStoreTestCase.run_all_tests_on_instance(instance)

    def test_implements_abstract(self):
        self.assertTrue(issubclass(KeyValueStore, KeyValueBase))
        self.assertTrue(isinstance(self.kvs, KeyValueBase))

    def test_set_get_delete(self):
        key1 = "%s#cookie" % self.prefix

        try:
            self.assertEqual(self.kvs.get(key1), None)
            self.kvs.set(key1, "monster")
            self.assertEqual(self.kvs.get(key1), "monster")
            self.kvs.set(key1, "crumbles")
            self.assertNotEqual(self.kvs.get(key1), "monster")
            self.assertEqual(self.kvs.get(key1), "crumbles")
            self.assertEqual(self.kvs.delete(key1), True)
            self.assertEqual(self.kvs.get(key1), None)

        except:
            self.kvs.delete(key1)
            raise

    def test_incr(self):
        key1 = "%s#counter" % self.prefix

        try:
            self.assertEqual(self.kvs.get(key1), None)
            self.assertEqual(self.kvs.incr(key1), 1)
            self.kvs.set(key1, 1)
            self.assertEqual(self.kvs.incr(key1), 2)
            self.kvs.set(key1, "1")
            self.assertEqual(self.kvs.incr(key1), 2)
            self.kvs.delete(key1)
            self.assertEqual(self.kvs.incr(key1), 1)
            self.assertEqual(self.kvs.incr(key1), 2)
            self.assertEqual(self.kvs.incr(key1), 3)
            self.assertEqual(self.kvs.delete(key1), True)

        except:
            self.kvs.delete(key1)
            raise