fix bug 643 750. Allow project update to change name 37/7637/1
authortierno <alfonso.tiernosepulveda@telefonica.com>
Mon, 10 Jun 2019 15:53:27 +0000 (15:53 +0000)
committertierno <alfonso.tiernosepulveda@telefonica.com>
Mon, 10 Jun 2019 15:53:27 +0000 (15:53 +0000)
Change-Id: I87913f113ca59fb311f11bdbd8e0cb20e09c2aca
Signed-off-by: tierno <alfonso.tiernosepulveda@telefonica.com>
osmclient/scripts/osm.py
osmclient/sol005/project.py
osmclient/sol005/user.py

index dd01b84..97c1942 100755 (executable)
@@ -2315,6 +2315,33 @@ def project_show(ctx, name):
     print(table)
 
 
+@cli.command(name='project-update')
+@click.argument('project')
+@click.option('--name',
+              prompt=True,
+              help='new name for the project')
+
+@click.pass_context
+def project_update(ctx, project, name):
+    """
+    Update a project name
+
+    :param ctx:
+    :param project: id or name of the project to modify
+    :param name:  new name for the project
+    :return:
+    """
+
+    project_changes = {}
+    project_changes['name'] = name
+
+    try:
+        check_client_version(ctx.obj, ctx.command.name)
+        ctx.obj.project.update(project, project_changes)
+    except ClientException as inst:
+        print(inst.message)
+
+
 ####################
 # User mgmt operations
 ####################
index 5c5786c..a66d84b 100644 (file)
@@ -58,21 +58,23 @@ class Project(object):
                     msg = resp
             raise ClientException("failed to create project {} - {}".format(name, msg))
 
-    def update(self, name, project):
+    def update(self, project, project_changes):
         """Updates an OSM project identified by name
         """
-        proj = self.get(name)
-        http_code, resp = self._http.put_cmd(endpoint='{}/{}'.format(self._apiBase,proj['_id']),
-                                             postfields_dict=project)
-        #print('HTTP CODE: {}'.format(http_code))
-        #print('RESP: {}'.format(resp))
-        if http_code in (200, 201, 202, 204):
+        proj = self.get(project)
+        http_code, resp = self._http.put_cmd(endpoint='{}/{}'.format(self._apiBase, proj['_id']),
+                                             postfields_dict=project_changes)
+        # print('HTTP CODE: {}'.format(http_code))
+        # print('RESP: {}'.format(resp))
+        if http_code in (200, 201, 202):
             if resp:
                 resp = json.loads(resp)
             if not resp or 'id' not in resp:
                 raise ClientException('unexpected response from server - {}'.format(
                                       resp))
             print(resp['id'])
+        elif http_code == 204:
+            print("Updated")
         else:
             msg = ""
             if resp:
@@ -80,7 +82,7 @@ class Project(object):
                     msg = json.loads(resp)
                 except ValueError:
                     msg = resp
-            raise ClientException("failed to update project {} - {}".format(name, msg))
+            raise ClientException("failed to update project {} - {}".format(project, msg))
 
     def delete(self, name, force=False):
         """Deletes an OSM project identified by name
index eca4edb..6604c93 100644 (file)
@@ -149,7 +149,7 @@ class User(object):
                                       resp))
             print(resp['id'])
         elif http_code == 204:
-            pass
+            print('Updated')
         else:
             msg = ""
             if resp: