Esempio n. 1
0
    def test_add(self):
        """
        Test if it add a key from memcache server
        """

        class MockMemcache(object):
            """
            Mock of memcache
            """

            def __init__(self):
                self.key = None
                self.value = None
                self.time = None
                self.min_compress_len = None

            @staticmethod
            def get_stats():
                """
                Mock of stats method
                """
                return [("127.0.0.1:11211 (1)", {})]

            def add(self, key, value, time, min_compress_len):
                """
                Mock of add method
                """
                self.key = key
                self.value = value
                self.time = time
                self.min_compress_len = min_compress_len
                return True

        with patch.object(
            memcached, "_connect", MagicMock(return_value=MockMemcache())
        ):
            self.assertTrue(memcached.add("salt", "1111"))

            self.assertRaises(
                SaltInvocationError, memcached.add, "salt", "1111", time="0.1"
            )

            self.assertRaises(
                SaltInvocationError,
                memcached.add,
                "salt",
                "1111",
                min_compress_len="0.1",
            )
Esempio n. 2
0
    def test_add(self):
        '''
        Test if it add a key from memcache server
        '''
        class MockMemcache(object):
            """
            Mock of memcache
            """
            def __init__(self):
                self.key = None
                self.value = None
                self.time = None
                self.min_compress_len = None

            @staticmethod
            def get_stats():
                """
                Mock of stats method
                """
                return [('127.0.0.1:11211 (1)', {})]

            def add(self, key, value, time, min_compress_len):
                """
                Mock of add method
                """
                self.key = key
                self.value = value
                self.time = time
                self.min_compress_len = min_compress_len
                return True

        with patch.object(memcached, '_connect',
                          MagicMock(return_value=MockMemcache())):
            self.assertTrue(memcached.add('salt', '1111'))

            self.assertRaises(SaltInvocationError,
                              memcached.add,
                              'salt',
                              '1111',
                              time='0.1')

            self.assertRaises(SaltInvocationError,
                              memcached.add,
                              'salt',
                              '1111',
                              min_compress_len='0.1')
Esempio n. 3
0
    def test_add(self):
        '''
        Test if it add a key from memcache server
        '''
        class MockMemcache(object):
            """
            Mock of memcache
            """
            def __init__(self):
                self.key = None
                self.value = None
                self.time = None
                self.min_compress_len = None

            @staticmethod
            def get_stats():
                """
                Mock of stats method
                """
                return [('127.0.0.1:11211 (1)', {})]

            def add(self, key, value, time, min_compress_len):
                """
                Mock of add method
                """
                self.key = key
                self.value = value
                self.time = time
                self.min_compress_len = min_compress_len
                return True

        with patch.object(memcached, '_connect',
                          MagicMock(return_value=MockMemcache())):
            self.assertTrue(memcached.add('salt', '1111'))

            self.assertRaises(SaltInvocationError, memcached.add,
                              'salt', '1111', time='0.1')

            self.assertRaises(SaltInvocationError, memcached.add,
                              'salt', '1111', min_compress_len='0.1')