def setUp(self): """Setup test suite.""" self.subcommand = Workspace() self.subcommand_str = "workspace" super(TestSubcommandWorkspace, self).setUp() config_data = { "workspaces": { "yoda": { "path": "/yoda", "repositories": { "yoda": "/project/yoda" } } } } self.config.update(config_data)
def setUp(self): """Setup test suite.""" self.parser = argparse.ArgumentParser(prog="yoda_test") self.subparser = self.parser.add_subparsers(dest="subcommand_test") self.sandbox = Sandbox() self.sandbox.mkdir("tmp") self.sandbox.mkdir("tmp/repo-name") config_data = { "workspaces": { "yoda": { "path": "/yoda", "repositories": { "yoda": "/project/yoda" } } } } conf = Config(self.sandbox.path + "/config") conf.update(config_data) self.workspace = Workspace() self.workspace.setup( "workspace", conf, self.subparser)
class TestSubcommandWorkspace(SubcommandTestHelper): """Workspace subcommand test suite.""" def setUp(self): """Setup test suite.""" self.subcommand = Workspace() self.subcommand_str = "workspace" super(TestSubcommandWorkspace, self).setUp() config_data = { "workspaces": { "yoda": { "path": "/yoda", "repositories": { "yoda": "/project/yoda" } } } } self.config.update(config_data) def test_parse_add(self): """Test workspace add parsing.""" self.assert_subcommand_parsing( ["workspace", "add", "foo", "/tmp/foo"], { "subcommand": "workspace", "workspace_subcommand": "add", "name": "foo", "path": "/tmp/foo"}) def test_parse_remove(self): """Test workspace remove parsing.""" self.assert_subcommand_parsing(["workspace", "remove", "foo"], { "subcommand": "workspace", "workspace_subcommand": "remove", "name": "foo"}) def test_parse_list(self): """Test workspace list parsing.""" self.assert_subcommand_parsing(["workspace", "list"], { "subcommand": "workspace", "workspace_subcommand": "list"}) def test_exec_add(self): """Test workspace add execution.""" ws = Mock() ws.add = Mock() args = Mock() args.workspace_subcommand = "add" args.name = "foo" args.path = "/foo" self.subcommand.ws = ws self.subcommand.execute(args) ws.add.assert_called_with("foo", "/foo") def test_exec_add_call_slashes2dash(self): """ Test workspace add execution call slashes2dash function for name argument. """ args = Mock() args.workspace_subcommand = "add" args.name = "foo" args.path = "/foo" self.subcommand.ws = Mock() with patch("yoda.subcommand.workspace.slashes2dash") as s2d: self.subcommand.execute(args) s2d.assert_called_once_with("foo") def test_exec_remove(self): """Test workspace remove execution.""" ws = Mock() ws.remove = Mock() args = Mock() args.workspace_subcommand = "remove" args.name = "foo" self.subcommand.ws = ws self.subcommand.execute(args) ws.remove.assert_called_with("foo") def test_exec_remove_call_slashes2dash(self): """ Test workspace remove execution call slashes2dash function for name argument. """ args = Mock() args.workspace_subcommand = "remove" args.name = "bar" self.subcommand.ws = Mock() with patch("yoda.subcommand.workspace.slashes2dash") as s2d: self.subcommand.execute(args) s2d.assert_called_once_with("bar") def test_exec_list(self): """Test workspace list execution.""" ws_list = { "yoda": { "path": "/project/yoda", "repositories": { "yoda": "/project/yoda/src" } }, "test": { "path": "/project/test" } } ws = Mock() ws.list = Mock(return_value=ws_list) args = Mock() args.workspace_subcommand = "list" self.subcommand.ws = ws self.subcommand.execute(args) ws.list.assert_called_with() def test_exec_without_command(self): """Test workspace without subcommand.""" ws = Mock() args = Mock() args.workspace_subcommand = None self.subcommand.ws = ws self.assertIsNone(self.subcommand.execute(args)) def test_exec_with_wrong_command(self): """Test workspace without subcommand.""" ws = Mock() args = Mock() args.workspace_subcommand = "test" self.subcommand.ws = ws self.assertIsNone(self.subcommand.execute(args)) def test_load_workspaces_subcommands(self): """Test workspaces subcommands.""" ws = Mock() ws.list = Mock(return_value={"foo": {"path": "/foo", "repositories": {}}}) subcmd = Mock() subcmd.commands = {} self.subcommand.ws = ws self.subcommand.load_workspaces_subcommands(subcmd) self.assertTrue("foo" in subcmd.commands) self.assertIsInstance(subcmd.commands["foo"], WorkspaceSubcommands)
class TestSubcommandWorkspace(unittest.TestCase): """Workspace subcommand test suite.""" sandbox = None parser = None subparser = None workspace = None def setUp(self): """Setup test suite.""" self.parser = argparse.ArgumentParser(prog="yoda_test") self.subparser = self.parser.add_subparsers(dest="subcommand_test") self.sandbox = Sandbox() self.sandbox.mkdir("tmp") self.sandbox.mkdir("tmp/repo-name") config_data = { "workspaces": { "yoda": { "path": "/yoda", "repositories": { "yoda": "/project/yoda" } } } } conf = Config(self.sandbox.path + "/config") conf.update(config_data) self.workspace = Workspace() self.workspace.setup( "workspace", conf, self.subparser) def tearDown(self): """Tear down test suite.""" self.sandbox.destroy() self.parser = None self.workspace = None def test_parse_add(self): """Test workspace add parsing.""" self.workspace.parse() args = self.parser.parse_args(["workspace", "add", "foo", "/tmp/foo"]) self.assertEqual("workspace", args.subcommand_test) self.assertEqual("add", args.workspace_subcommand) self.assertEqual("foo", args.name) self.assertEqual("/tmp/foo", args.path) def test_parse_remove(self): """Test workspace remove parsing.""" self.workspace.parse() args = self.parser.parse_args(["workspace", "remove", "foo"]) self.assertEqual("workspace", args.subcommand_test) self.assertEqual("remove", args.workspace_subcommand) self.assertEqual("foo", args.name) def test_parse_list(self): """Test workspace list parsing.""" self.workspace.parse() args = self.parser.parse_args(["workspace", "list"]) self.assertEqual("workspace", args.subcommand_test) self.assertEqual("list", args.workspace_subcommand) def test_exec_add(self): """Test workspace add execution.""" ws = Mock() ws.add = Mock() args = Mock() args.workspace_subcommand = "add" args.name = "foo" args.path = "/foo" self.workspace.ws = ws self.workspace.execute(args) ws.add.assert_called_with("foo", "/foo") def test_exec_remove(self): """Test workspace remove execution.""" ws = Mock() ws.remove = Mock() args = Mock() args.workspace_subcommand = "remove" args.name = "foo" self.workspace.ws = ws self.workspace.execute(args) ws.remove.assert_called_with("foo") def test_exec_list(self): """Test workspace list execution.""" ws_list = { "yoda": { "path": "/project/yoda", "repositories": { "yoda": "/project/yoda/src" } }, "test": { "path": "/project/test" } } ws = Mock() ws.list = Mock(return_value=ws_list) args = Mock() args.workspace_subcommand = "list" self.workspace.ws = ws self.workspace.execute(args) ws.list.assert_called_with() def test_exec_without_command(self): """Test workspace without subcommand.""" ws = Mock() args = Mock() args.workspace_subcommand = None self.workspace.ws = ws self.assertIsNone(self.workspace.execute(args)) def test_exec_with_wrong_command(self): """Test workspace without subcommand.""" ws = Mock() args = Mock() args.workspace_subcommand = "test" self.workspace.ws = ws self.assertIsNone(self.workspace.execute(args)) def test_load_workspaces_subcommands(self): """Test workspaces subcommands.""" ws = Mock() ws.list = Mock(return_value={"foo": {"path": "/foo", "repositories": {}}}) subcmd = Mock() subcmd.commands = {} self.workspace.ws = ws self.workspace.load_workspaces_subcommands(subcmd) self.assertTrue("foo" in subcmd.commands) self.assertIsInstance(subcmd.commands["foo"], WorkspaceSubcommands)