Assert that a zone is present (that did exist) """ with patch.object(MockDnsModule, 'create_zone') as create_patch: result = libcloud_dns.zone_present('test.com', 'master', 'test1') self.assertTrue(result) self.assertFalse(create_patch.called) def test_zone_absent(self): """ Assert that a zone that did exist is absent """ with patch.object(MockDnsModule, 'delete_zone') as create_patch: result = libcloud_dns.zone_absent('test.com', 'test1') self.assertTrue(result) self.assertTrue(create_patch.called) create_patch.assert_called_with('zone1', 'test1') def test_zone_already_absent(self): """ Assert that a zone that did not exist is absent """ with patch.object(MockDnsModule, 'delete_zone') as create_patch: result = libcloud_dns.zone_absent('testing.com', 'test1') self.assertTrue(result) self.assertFalse(create_patch.called) if __name__ == '__main__': from unit import run_tests run_tests(LibcloudDnsModuleTestCase)
from salttesting.helpers import ensure_in_syspath ensure_in_syspath('../../') class ExtendTestCase(TestCase): def setUp(self): self.out = None def tearDown(self): if self.out is not None: if os.path.exists(self.out): shutil.rmtree(self.out, True) def test_run(self): out = salt.utils.extend.run('test', 'test', 'this description', '.', False) self.out = out year = date.today().strftime('%Y') self.assertTrue(os.path.exists(out)) self.assertFalse(os.path.exists(os.path.join(out, 'template.yml'))) self.assertTrue(os.path.exists(os.path.join(out, 'directory'))) self.assertTrue( os.path.exists(os.path.join(out, 'directory', 'test.py'))) with fopen(os.path.join(out, 'directory', 'test.py'), 'r') as test_f: self.assertEqual(test_f.read(), year) if __name__ == '__main__': from unit import run_tests run_tests(ExtendTestCase, needs_daemon=False)
with patch('salt.config.check_driver_dependencies', return_value=False): v = gce.__virtual__() self.assertEqual(v, False) def test_fail_virtual_deps_missing_config(self): with patch('salt.config.check_driver_dependencies', return_value=True): with patch('salt.config.is_provider_configured', return_value=False): v = gce.__virtual__() self.assertEqual(v, False) def test_import(self): """ Test that the module picks up installed deps """ with patch('salt.config.check_driver_dependencies', return_value=True) as p: get_deps = gce.get_dependencies() self.assertEqual(get_deps, True) if LooseVersion(mock.__version__) >= LooseVersion('2.0.0'): p.assert_called_once() def test_provider_matches(self): """ Test that the first configured instance of a gce driver is matched """ p = gce.get_configured_provider() self.assertNotEqual(p, None) if __name__ == '__main__': from unit import run_tests run_tests(GCETestCase, needs_daemon=False)
''' # Import Python libs from __future__ import absolute_import # Import Salt Testing Libs from salttesting import TestCase # Import Salt Libs import salt.cloud.libcloudfuncs as libcloud # Import Salt Testing Libs from salttesting.helpers import ensure_in_syspath ensure_in_syspath('../../') class LibcloudTestCase(TestCase): def test_node_state_libcloud_020(self): state = libcloud.node_state(2) self.assertEqual('TERMINATED', state) def test_node_state_libcloud_100(self): state = libcloud.node_state('terminated') self.assertEqual('TERMINATED', state) if __name__ == '__main__': from unit import run_tests run_tests(LibcloudTestCase, needs_daemon=False)
""" Assert that a zone is present (that did exist) """ with patch.object(MockDnsModule, 'create_zone') as create_patch: result = libcloud_dns.zone_present('test.com', 'master', 'test1') self.assertTrue(result) self.assertFalse(create_patch.called) def test_zone_absent(self): """ Assert that a zone that did exist is absent """ with patch.object(MockDnsModule, 'delete_zone') as create_patch: result = libcloud_dns.zone_absent('test.com', 'test1') self.assertTrue(result) self.assertTrue(create_patch.called) create_patch.assert_called_with('zone1', 'test1') def test_zone_already_absent(self): """ Assert that a zone that did not exist is absent """ with patch.object(MockDnsModule, 'delete_zone') as create_patch: result = libcloud_dns.zone_absent('testing.com', 'test1') self.assertTrue(result) self.assertFalse(create_patch.called) if __name__ == '__main__': from unit import run_tests run_tests(LibcloudDnsModuleTestCase)
def session_store(status, req): # Postexec function for storing an authentication token in DATA. global DATA; if (status): DATA['Auth-Token'] = req.json()['session']['token']; else: print("[ERROR] Session store failed." + "Can't continue testing."); sys.exit(1); def session_use(): # Preexec function for using an authentication token from DATA. global DATA; return { 'headers_request': DATA }; if __name__ == '__main__': queues = [ q for q in listdir(UPATH) if isfile(join(UPATH, q)) if not q[0] == '.' ]; queues = sorted(queues, key=lambda x: x.split('_')[0]); for q in queues: print("[INFO] Loading '" + q + "'."); mod = importlib.import_module( 'units.' + splitext(q)[0] ); mod.setup(HOST, session_use, session_store); unit.run_tests(mod.tests);
self.assertEqual(v, False) def test_fail_virtual_deps_missing_config(self): with patch('salt.config.check_driver_dependencies', return_value=True): with patch('salt.config.is_provider_configured', return_value=False): v = gce.__virtual__() self.assertEqual(v, False) def test_import(self): """ Test that the module picks up installed deps """ with patch('salt.config.check_driver_dependencies', return_value=True) as p: get_deps = gce.get_dependencies() self.assertEqual(get_deps, True) p.assert_called_once() def test_provider_matches(self): """ Test that the first configured instance of a gce driver is matched """ p = gce.get_configured_provider() self.assertNotEqual(p, None) if __name__ == '__main__': from unit import run_tests run_tests(GCETestCase, needs_daemon=False)
self.setup_loader() self.loader.set_result(servicenow, "config.option", get_config) def test_module_creation(self): client = servicenow._get_client() self.assertFalse(client is None) def test_non_structured_query(self): result = servicenow.non_structured_query("tests", "role=web") self.assertFalse(result is None) self.assertEqual(result[0]["query_size"], 8) self.assertEqual(result[0]["query_value"], "role=web") def test_non_structured_query_kwarg(self): result = servicenow.non_structured_query("tests", role="web") self.assertFalse(result is None) self.assertEqual(result[0]["query_size"], 8) self.assertEqual(result[0]["query_value"], "role=web") def test_non_structured_query_kwarg_multi(self): result = servicenow.non_structured_query("tests", role="web", type="computer") self.assertFalse(result is None) self.assertEqual(result[0]["query_size"], 22) if __name__ == "__main__": from unit import run_tests run_tests(ServiceNowModuleTestCase)
import salt.utils class ExtendTestCase(TestCase): def setUp(self): self.starting_dir = os.getcwd() os.chdir(integration.CODE_DIR) self.out = None def tearDown(self): if self.out is not None: if os.path.exists(self.out): shutil.rmtree(self.out, True) os.chdir(self.starting_dir) @patch('sys.exit', MagicMock) def test_run(self): out = salt.utils.extend.run('test', 'test', 'this description', integration.CODE_DIR, False) self.out = out year = date.today().strftime('%Y') self.assertTrue(os.path.exists(out)) self.assertFalse(os.path.exists(os.path.join(out, 'template.yml'))) self.assertTrue(os.path.exists(os.path.join(out, 'directory'))) self.assertTrue(os.path.exists(os.path.join(out, 'directory', 'test.py'))) with salt.utils.fopen(os.path.join(out, 'directory', 'test.py'), 'r') as test_f: self.assertEqual(test_f.read(), year) if __name__ == '__main__': from unit import run_tests run_tests(ExtendTestCase, needs_daemon=False)
@skipIf(NO_MOCK, NO_MOCK_REASON) @patch('servicenow_rest.api.Client', MockServiceNowClient) class ServiceNowModuleTestCase(ModuleTestCase): def setUp(self): hasDependency('servicenow_rest') servicenow.Client = MockServiceNowClient def get_config(service): if service == SERVICE_NAME: return { 'instance_name': 'test', 'username': '******', 'password': '******' } else: raise KeyError("service name invalid") self.setup_loader() self.loader.set_result(servicenow, 'config.option', get_config) def test_module_creation(self): client = servicenow._get_client() self.assertFalse(client is None) if __name__ == '__main__': from unit import run_tests run_tests(ServiceNowModuleTestCase)