Пример #1
0
 def test_fetch_return_when_cache_file_does_not_exist(self):
     '''
     Tests that the fetch function returns an empty dic when the cache key file
     doesn't exist.
     '''
     with patch('os.path.isfile', MagicMock(return_value=False)):
         self.assertEqual(localfs.fetch(bank='', key='', cachedir=''), {})
Пример #2
0
 def test_fetch_return_when_cache_file_does_not_exist(self):
     """
     Tests that the fetch function returns an empty dic when the cache key file
     doesn't exist.
     """
     with patch("os.path.isfile", MagicMock(return_value=False)):
         self.assertEqual(localfs.fetch(bank="", key="", cachedir=""), {})
Пример #3
0
    def test_fetch_success(self):
        """
        Tests that the fetch function is able to read the cache file and return its data.
        """
        # Create a temporary cache dir
        tmp_dir = tempfile.mkdtemp(dir=RUNTIME_VARS.TMP)

        # Use the helper function to create the cache file using localfs.store()
        self._create_tmp_cache_file(tmp_dir)

        # Now fetch the data from the new cache key file
        with patch.dict(localfs.__opts__, {"cachedir": tmp_dir}):
            self.assertIn(
                "payload data",
                localfs.fetch(bank="bank", key="key", cachedir=tmp_dir),
            )
Пример #4
0
    def test_fetch_success(self):
        """
        Tests that the fetch function is able to read the cache file and return its data.
        """
        # Create a temporary cache dir
        tmp_dir = tempfile.mkdtemp(dir=integration.SYS_TMP_DIR)

        # Create a new serializer object to use in function patches
        serializer = salt.payload.Serial(self)

        # Use the helper function to create the cache file using localfs.store()
        self._create_tmp_cache_file(tmp_dir, serializer)

        # Now fetch the data from the new cache key file
        with patch.dict(localfs.__opts__, {"cachedir": tmp_dir}):
            with patch.dict(localfs.__context__, {"serial": serializer}):
                self.assertIn("payload data", localfs.fetch(bank="bank", key="key"))
Пример #5
0
    def test_fetch_success(self):
        '''
        Tests that the fetch function is able to read the cache file and return its data.
        '''
        # Create a temporary cache dir
        tmp_dir = tempfile.mkdtemp(dir=TMP)

        # Create a new serializer object to use in function patches
        serializer = salt.payload.Serial(self)

        # Use the helper function to create the cache file using localfs.store()
        self._create_tmp_cache_file(tmp_dir, serializer)

        # Now fetch the data from the new cache key file
        with patch.dict(localfs.__opts__, {'cachedir': tmp_dir}):
            with patch.dict(localfs.__context__, {'serial': serializer}):
                self.assertIn('payload data', localfs.fetch(bank='bank', key='key', cachedir=tmp_dir))
Пример #6
0
    def test_mix_of_utf8_and_non_utf8_can_be_round_tripped(self):

        tmp_dir = tempfile.mkdtemp(dir=RUNTIME_VARS.TMP)

        data = {
            # Any unicode, which ideally is invalid ascii.
            "unicode": "áéí",
            # Any bytes so long as they're not valid utf-8
            "bytes": b"\xfe\x99\x00\xff",
        }
        bank = "bank"
        key = "key"

        self.addCleanup(shutil.rmtree, tmp_dir)
        with patch.dict(localfs.__opts__, {"cachedir": tmp_dir}):
            localfs.store(bank, key, data, tmp_dir)

            actual = localfs.fetch(bank, key, tmp_dir)

        self.assertEqual(data, actual)
Пример #7
0
 def test_fetch_return_when_cache_file_does_not_exist(self):
     '''
     Tests that the fetch function returns None when the cache key file doesn't
     exist.
     '''
     self.assertIsNone(localfs.fetch(bank='', key='', cachedir=''))
Пример #8
0
 def test_fetch_return_when_cache_file_does_not_exist(self):
     """
     Tests that the fetch function returns None when the cache key file doesn't
     exist.
     """
     self.assertIsNone(localfs.fetch(bank="", key=""))