コード例 #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",
            )
コード例 #2
0
ファイル: test_memcached.py プロジェクト: morinap/salt-1
    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')
コード例 #3
0
ファイル: memcached_test.py プロジェクト: DaveQB/salt
    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')