def test_collect_volumes_ssh_auth_socket(self, os_environ_mock: Mock): ssh_auth_path = 'DUMMY' env = {'SSH_AUTH_SOCK': ssh_auth_path} os_environ_mock.__getitem__.side_effect = env.__getitem__ os_environ_mock.__iter__.side_effect = env.__iter__ os_environ_mock.__contains__.side_effect = env.__contains__ cmd = module.Command({}) expected = OrderedDict({ # Source code also has to be mounted in: ProjectStub.SRC_FOLDER: { 'bind': CONTAINER_SRC_PATH, 'mode': 'rw' }, # SSH_AUTH_SOCK: ssh_auth_path: { 'bind': ssh_auth_path, 'mode': 'rw' } }) # The project contains NO services matching the defined roles cmd.parent_doc = ProjectStub({}, set_parent_to_self=True) actual = cmd.collect_volumes() self.assertEqual(expected, actual) self.assertIsInstance(actual, OrderedDict)
def setUp(self): self.fix_with_volumes = module.Command({ "additional_volumes": { "one": { "host": "~/hometest", "container": "/vol1", "mode": "rw" }, "two": { "host": "./reltest1", "container": "/vol2", "mode": "rw" }, "three": { "host": "reltest2", "container": "/vol3", "mode": "rw" }, "four": { "host": "reltestc", "container": "reltest_container", "mode": "rw" }, "five": { "host": "/absolute_with_ro", "container": "/vol4", "mode": "ro" }, "six": { "host": "/absolute_no_mode", "container": "/vol5" } }, "config_from_roles": ["A", "B"] })
def test_volume_path(self, meta_folder_mock: Mock, os_makedirs_mock: Mock): cmd = module.Command({'$name': 'hello_world'}) cmd.parent_doc = ProjectStub({}, set_parent_to_self=True) expected_path = os.path.join('META', 'cmd_data', 'hello_world') self.assertEqual(expected_path, cmd.volume_path()) meta_folder_mock.assert_called_once_with(ProjectStub.FOLDER) os_makedirs_mock.assert_called_once_with(expected_path, exist_ok=True)
def test_collect_environment(self, *args, **kwargs): cmd = module.Command({'environment': {'FROM_ENV': 'FROM_ENV'}}) expected = { 'ENV': 'VALUE1', 'FROM_ENV': 'FROM_ENV', 'COLUMNS': '10', 'LINES': '20' } self.assertEqual(expected, cmd.collect_environment())
def test_resolve_alias_something_to_alias(self): # hello world command hello_world_command = YamlConfigDocumentStub({'hello': 'world'}) # The command we want to test cmd = module.Command({'aliases': 'hello_world'}) # The parent app of the command we want to test, that contains both commands cmd.parent_doc = YamlConfigDocumentStub({ 'commands': { 'hello_world': hello_world_command, 'our_test': cmd } }) # Make the mocked command's resolve_alias return itself. setattr(hello_world_command, 'resolve_alias', MagicMock(return_value=hello_world_command)) # Assert that we get the hello world command self.assertEqual(hello_world_command, cmd.resolve_alias()) # Make sure resolve_alias was actually called on our mocked command hello_world_command.resolve_alias.assert_called_once()
def test_header(self): cmd = module.Command({}) self.assertEqual(module.HEADER, cmd.header())
def test_home_path(self): cmd = module.Command({}) self.assertEqual(CONTAINER_HOME_PATH, cmd.home_path())
def test_resolve_alias_nothing_to_alias(self): cmd = module.Command({}) self.assertEqual(cmd, cmd.resolve_alias())
def test_get_project_no_parent(self): cmd = module.Command({}) with self.assertRaises(IndexError): cmd.get_project()
def test_get_project(self): cmd = module.Command({}) project = ProjectStub({}, set_parent_to_self=True) cmd.parent_doc = project self.assertEqual(project, cmd.get_project())