begin to cleanup explorer test case

Signed-off-by: Nico Schottelius <nico@brief.schottelius.org>
This commit is contained in:
Nico Schottelius 2012-11-01 18:21:56 +01:00
parent f264cf9f6c
commit 5ec586f764
2 changed files with 29 additions and 15 deletions

View file

@ -28,9 +28,13 @@ cdist_base_path = os.path.abspath(
cdist_exec_path = os.path.join(cdist_base_path, "scripts/cdist") cdist_exec_path = os.path.join(cdist_base_path, "scripts/cdist")
global_fixtures_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), "fixtures"))
class CdistTestCase(unittest.TestCase): class CdistTestCase(unittest.TestCase):
remote_exec = os.path.join(global_fixtures_dir, "remote", "exec")
remote_copy = os.path.join(global_fixtures_dir, "remote", "copy")
def mkdtemp(self, **kwargs): def mkdtemp(self, **kwargs):
return tempfile.mkdtemp(prefix='tmp.cdist.test.', **kwargs) return tempfile.mkdtemp(prefix='tmp.cdist.test.', **kwargs)

View file

@ -1,7 +1,7 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# #
# 2010-2011 Steven Armstrong (steven-cdist at armstrong.cc) # 2010-2011 Steven Armstrong (steven-cdist at armstrong.cc)
# 2011 Nico Schottelius (nico-cdist at schottelius.org) # 2011-2012 Nico Schottelius (nico-cdist at schottelius.org)
# #
# This file is part of cdist. # This file is part of cdist.
# #
@ -35,35 +35,45 @@ from cdist.core import explorer
import os.path as op import os.path as op
my_dir = op.abspath(op.dirname(__file__)) my_dir = op.abspath(op.dirname(__file__))
fixtures = op.join(my_dir, 'fixtures') fixtures = op.join(my_dir, 'fixtures')
local_base_path = fixtures conf_dir = op.join(fixtures, "conf")
class ExplorerClassTestCase(test.CdistTestCase): class ExplorerClassTestCase(test.CdistTestCase):
def setUp(self): def setUp(self):
self.target_host = 'localhost' self.target_host = 'localhost'
self.local_base_path = local_base_path self.temp_dir = self.mkdtemp()
self.out_path = self.mkdtemp() self.out_path = os.path.join(self.temp_dir, "out")
self.local = local.Local(self.target_host, self.local_base_path, self.out_path) self.remote_base_path = os.path.join(self.temp_dir, "remote")
self.local = local.Local(
target_host=self.target_host,
out_path=self.out_path,
exec_path=test.cdist_exec_path,
add_conf_dirs=[conf_dir])
self.local.create_files_dirs() self.local.create_files_dirs()
self.remote_base_path = self.mkdtemp() self.remote = remote.Remote(
self.user = getpass.getuser() self.target_host,
remote_exec = "ssh -o User=%s -q" % self.user self.remote_base_path,
remote_copy = "scp -o User=%s -q" % self.user self.remote_exec,
self.remote = remote.Remote(self.target_host, self.remote_base_path, remote_exec, remote_copy) self.remote_copy)
self.explorer = explorer.Explorer(self.target_host, self.local, self.remote) self.explorer = explorer.Explorer(
self.target_host,
self.local,
self.remote)
self.log = logging.getLogger(self.target_host) self.log = logging.getLogger(self.target_host)
def tearDown(self): def tearDown(self):
shutil.rmtree(self.out_path) shutil.rmtree(self.temp_dir)
shutil.rmtree(self.remote_base_path)
def test_list_global_explorer_names(self): def test_list_global_explorer_names(self):
expected = ['foobar', 'global'] names = self.explorer.list_global_explorer_names()
self.assertEqual(self.explorer.list_global_explorer_names(), expected) self.assertIn("foobar", names)
self.assertIn("global", names)
def test_transfer_global_explorers(self): def test_transfer_global_explorers(self):
self.explorer.transfer_global_explorers() self.explorer.transfer_global_explorers()