示例#1
0
def test_cached_file_client(get_loader, minion_opts):
    """
    Multiple instantiations of SaltCacheLoader use the cached file client
    """
    with patch("salt.channel.client.ReqChannel.factory", Mock()):
        loader_a = SaltCacheLoader(minion_opts)
        loader_b = SaltCacheLoader(minion_opts)
    assert loader_a._file_client is loader_b._file_client
示例#2
0
 def test_mockclient(self):
     '''
     A MockFileClient is used that records all file request normally send to the master.
     '''
     loader = SaltCacheLoader({'cachedir': TEMPLATES_DIR}, 'test')
     fc = MockFileClient(loader)
     res = loader.get_source(None, 'hello_simple')
     assert len(res) == 3
     self.assertEqual(res[0], 'world\n')
     self.assertEqual(res[1], '%s/files/test/hello_simple' % TEMPLATES_DIR)
     assert res[2](), "Template up to date?"
     assert len(fc.requests)
     self.assertEqual(fc.requests[0]['path'], 'salt://hello_simple')
示例#3
0
文件: jinja_test.py 项目: vonion/salt
 def test_mockclient(self):
     '''
     A MockFileClient is used that records all file requests normally sent
     to the master.
     '''
     loader = SaltCacheLoader({'cachedir': TEMPLATES_DIR}, 'test')
     fc = MockFileClient(loader)
     res = loader.get_source(None, 'hello_simple')
     assert len(res) == 3
     # res[0] on Windows is unicode and use os.linesep so it works cross OS
     self.assertEqual(str(res[0]), 'world' + os.linesep)
     tmpl_dir = os.path.join(TEMPLATES_DIR, 'files', 'test', 'hello_simple')
     self.assertEqual(res[1], tmpl_dir)
     assert res[2](), 'Template up to date?'
     assert len(fc.requests)
     self.assertEqual(fc.requests[0]['path'], 'salt://hello_simple')
示例#4
0
文件: jinja_test.py 项目: vonion/salt
 def test_searchpath(self):
     '''
     The searchpath is based on the cachedir option and the saltenv parameter
     '''
     tmp = tempfile.gettempdir()
     loader = SaltCacheLoader({'cachedir': tmp}, saltenv='test')
     assert loader.searchpath == [os.path.join(tmp, 'files', 'test')]
示例#5
0
 def test_mockclient(self):
     '''
     A MockFileClient is used that records all file requests normally sent
     to the master.
     '''
     loader = SaltCacheLoader({'cachedir': TEMPLATES_DIR}, 'test')
     fc = MockFileClient(loader)
     res = loader.get_source(None, 'hello_simple')
     assert len(res) == 3
     # res[0] on Windows is unicode and use os.linesep so it works cross OS
     self.assertEqual(str(res[0]), 'world' + os.linesep)
     tmpl_dir = os.path.join(TEMPLATES_DIR, 'files', 'test', 'hello_simple')
     self.assertEqual(res[1], tmpl_dir)
     assert res[2](), 'Template up to date?'
     assert len(fc.requests)
     self.assertEqual(fc.requests[0]['path'], 'salt://hello_simple')
示例#6
0
def test_file_client_kwarg(minion_opts, mock_file_client):
    """
    A file client can be passed to SaltCacheLoader overriding the any
    cached file client
    """
    loader = SaltCacheLoader(minion_opts, _file_client=mock_file_client)
    assert loader._file_client is mock_file_client
示例#7
0
文件: jinja_test.py 项目: rrada/salt
 def test_mockclient(self):
     """
     A MockFileClient is used that records all file requests normally sent
     to the master.
     """
     loader = SaltCacheLoader({"cachedir": TEMPLATES_DIR}, "test")
     fc = MockFileClient(loader)
     res = loader.get_source(None, "hello_simple")
     assert len(res) == 3
     # res[0] on Windows is unicode and use os.linesep so it works cross OS
     self.assertEqual(str(res[0]), "world" + os.linesep)
     tmpl_dir = os.path.join(TEMPLATES_DIR, "files", "test", "hello_simple")
     self.assertEqual(res[1], tmpl_dir)
     assert res[2](), "Template up to date?"
     assert len(fc.requests)
     self.assertEqual(fc.requests[0]["path"], "salt://hello_simple")
示例#8
0
 def get_test_saltenv(self):
     '''
     Setup a simple jinja test environment
     '''
     loader = SaltCacheLoader(self.opts, 'test')
     fc = MockFileClient(loader)
     jinja = Environment(loader=loader)
     return fc, jinja
示例#9
0
文件: jinja_test.py 项目: vonion/salt
 def get_test_saltenv(self):
     '''
     Setup a simple jinja test environment
     '''
     loader = SaltCacheLoader({'cachedir': TEMPLATES_DIR}, 'test')
     fc = MockFileClient(loader)
     jinja = Environment(loader=loader)
     return fc, jinja
示例#10
0
 def run_command(opts=None, saltenv="base", **kwargs):
     """
     Now that we instantiate the client in the __init__, we need to mock it
     """
     if opts is None:
         opts = minion_opts
     loader = SaltCacheLoader(opts, saltenv, _file_client=mock_file_client)
     # Create a mock file client and attach it to the loader
     return loader
示例#11
0
def test_cache_loader_shutdown(minion_opts, mock_file_client):
    """
    The shudown method can be called without raising an exception when the
    file_client does not have a destroy method
    """
    assert not hasattr(mock_file_client, "destroy")
    loader = SaltCacheLoader(minion_opts, _file_client=mock_file_client)
    assert loader._file_client is mock_file_client
    # Shutdown method should not raise any exceptions
    loader.shutdown()
示例#12
0
 def get_loader(self, opts=None, saltenv='base'):
     '''
     Now that we instantiate the client in the __init__, we need to mock it
     '''
     if opts is None:
         opts = self.opts
     with patch.object(SaltCacheLoader, 'file_client', Mock()):
         loader = SaltCacheLoader(opts, saltenv)
     # Create a mock file client and attach it to the loader
     MockFileClient(loader)
     return loader
示例#13
0
 def test_searchpath(self):
     '''
     The searchpath is based on the cachedir option and the env parameter
     '''
     loader = SaltCacheLoader({'cachedir': '/tmp'}, env='test')
     assert loader.searchpath == '/tmp/files/test'