Blob Blame Raw
From 9b2c92ad7a58eefffffcdf35e564993d196b9966 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Lubom=C3=ADr=20Sedl=C3=A1=C5=99?= <lsedlar@redhat.com>
Date: Thu, 18 May 2017 15:02:33 +0200
Subject: [PATCH 3/3] Allow explicit namespaces with slashes
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

COPR uses module names in the form of user/project/package, so their
namespaces contain multiple slashes.

Signed-off-by: Lubomír Sedlář <lsedlar@redhat.com>
---
 pyrpkg/cli.py     |  8 +-------
 tests/test_cli.py | 29 +++++++++++++++++++++++++++++
 2 files changed, 30 insertions(+), 7 deletions(-)

diff --git a/pyrpkg/cli.py b/pyrpkg/cli.py
index 856883a..34512a9 100644
--- a/pyrpkg/cli.py
+++ b/pyrpkg/cli.py
@@ -146,13 +146,7 @@ class cliClient(object):
                 self._cmd.ns_module_name = 'rpms/%s' % self.args.module_name
             else:
                 self._cmd.ns_module_name = self.args.module_name
-                try:
-                    _, self._cmd.module_name = self.args.module_name.split('/')
-                    # Exactly one slash, let's continue on
-                except ValueError:
-                    # Too many segments, report an error
-                    self.parser.error('Argument to --module-name can contain '
-                                      'at most one / character')
+                _, self._cmd.module_name = self.args.module_name.rsplit('/', 1)
         self._cmd.password = self.args.password
         self._cmd.runas = self.args.runas
         self._cmd.debug = self.args.debug
diff --git a/tests/test_cli.py b/tests/test_cli.py
index 29b1e2e..126b59b 100644
--- a/tests/test_cli.py
+++ b/tests/test_cli.py
@@ -68,6 +68,35 @@ class CliTestCase(CommandTestCase):
             map(lambda cmd: self.run_cmd(cmd, cwd=repo_path), cmds)
 
 
+class TestModuleNameOption(CliTestCase):
+
+    def get_cmd(self, module_name):
+        cmd = ['rpkg', '--path', self.cloned_repo_path, '--module-name', module_name, 'verrel']
+        with patch('sys.argv', new=cmd):
+            cli = self.new_cli()
+        return cli.cmd
+
+    def test_just_module_name(self):
+        cmd = self.get_cmd('foo')
+        self.assertEqual(cmd._module_name, 'foo')
+        self.assertEqual(cmd._ns_module_name, 'rpms/foo')
+
+    def test_explicit_default(self):
+        cmd = self.get_cmd('rpms/foo')
+        self.assertEqual(cmd._module_name, 'foo')
+        self.assertEqual(cmd._ns_module_name, 'rpms/foo')
+
+    def test_with_namespace(self):
+        cmd = self.get_cmd('container/foo')
+        self.assertEqual(cmd._module_name, 'foo')
+        self.assertEqual(cmd._ns_module_name, 'container/foo')
+
+    def test_with_nested_namespace(self):
+        cmd = self.get_cmd('user/project/foo')
+        self.assertEqual(cmd._module_name, 'foo')
+        self.assertEqual(cmd._ns_module_name, 'user/project/foo')
+
+
 class TestClog(CliTestCase):
 
     def setUp(self):
-- 
2.9.4