Add subject assignments commands and the tests for them. 39/1739/1
authorasteroide <thomas.duval@orange.com>
Fri, 18 Sep 2015 10:21:47 +0000 (12:21 +0200)
committerasteroide <thomas.duval@orange.com>
Fri, 18 Sep 2015 10:21:47 +0000 (12:21 +0200)
Change-Id: I11312fa5413b02b505b853785bf7fbd4d27a806a

moonclient/moonclient/subject_assignments.py
moonclient/moonclient/tests/tests_subject_assignments.json [new file with mode: 0644]

index 0b3e605..8978def 100644 (file)
@@ -16,6 +16,16 @@ class SubjectAssignmentsList(Lister):
 
     def get_parser(self, prog_name):
         parser = super(SubjectAssignmentsList, self).get_parser(prog_name)
+        parser.add_argument(
+            'subject_id',
+            metavar='<subject-uuid>',
+            help='Subject UUID',
+        )
+        parser.add_argument(
+            'category_id',
+            metavar='<category-uuid>',
+            help='Category UUID',
+        )
         parser.add_argument(
             '--intraextension',
             metavar='<intraextension-uuid>',
@@ -23,16 +33,22 @@ class SubjectAssignmentsList(Lister):
         )
         return parser
 
+    def __get_scope_from_id(self, intraextension_id, category_id, scope_id):
+        data = self.app.get_url("/v3/OS-MOON/intra_extensions/{}/subject_scopes/{}".format(
+            intraextension_id, category_id),
+            authtoken=True)
+        if scope_id in data:
+            return data[scope_id]
+
     def take_action(self, parsed_args):
         if not parsed_args.intraextension:
             parsed_args.intraextension = self.app.intraextension
-        data = self.app.get_url("/v3/OS-MOON/intra_extensions/{}/subject_assignments".format(parsed_args.intraextension),
-                                authtoken=True)
-        if "subject_assignments" not in data:
-            raise Exception("Error in command {}: {}".format("SubjectAssignmentsList", data))
+        data = self.app.get_url("/v3/OS-MOON/intra_extensions/{}/subject_assignments/{}/{}".format(
+            parsed_args.intraextension, parsed_args.subject_id, parsed_args.category_id),
+            authtoken=True)
         return (
-            ("category", "value"),
-            ((_cat, str(_val)) for _cat, _val in data["subject_assignments"].items())
+            ("id", "name"),
+            ((_id, self.__get_scope_from_id(parsed_args.intraextension, parsed_args.category_id, _id)['name']) for _id in data)
         )
 
 
@@ -50,12 +66,12 @@ class SubjectAssignmentsAdd(Command):
         )
         parser.add_argument(
             'subject_category',
-            metavar='<subject_category>',
+            metavar='<subject_category-uuid>',
             help='Subject Category',
         )
         parser.add_argument(
             'subject_category_scope',
-            metavar='<subject_category_scope>',
+            metavar='<subject_category_scope-uuid>',
             help='Subject Category Scope',
         )
         parser.add_argument(
@@ -65,21 +81,26 @@ class SubjectAssignmentsAdd(Command):
         )
         return parser
 
+    def __get_scope_from_id(self, intraextension_id, category_id, scope_id):
+        data = self.app.get_url("/v3/OS-MOON/intra_extensions/{}/subject_scopes/{}".format(
+            intraextension_id, category_id),
+            authtoken=True)
+        if scope_id in data:
+            return data[scope_id]
+
     def take_action(self, parsed_args):
         if not parsed_args.intraextension:
             parsed_args.intraextension = self.app.intraextension
         data = self.app.get_url("/v3/OS-MOON/intra_extensions/{}/subject_assignments".format(parsed_args.intraextension),
                                 post_data={
                                     "subject_id": parsed_args.subject_id,
-                                    "subject_category": parsed_args.subject_category,
-                                    "subject_category_scope": parsed_args.subject_category_scope
+                                    "subject_category_id": parsed_args.subject_category,
+                                    "subject_scope_id": parsed_args.subject_category_scope
                                 },
                                 authtoken=True)
-        if "subject_assignments" not in data:
-            raise Exception("Error in command {}".format(data))
         return (
-            ("category", "value"),
-            ((_cat, str(_val)) for _cat, _val in data["subject_assignments"].items())
+            ("id", "name"),
+            ((_id, self.__get_scope_from_id(parsed_args.intraextension, parsed_args.category_id, _id)['name']) for _id in data)
         )
 
 
diff --git a/moonclient/moonclient/tests/tests_subject_assignments.json b/moonclient/moonclient/tests/tests_subject_assignments.json
new file mode 100644 (file)
index 0000000..3a9d93b
--- /dev/null
@@ -0,0 +1,366 @@
+{
+  "command_options": "-f value",
+  "tests_group": {
+    "authz": [
+      {
+        "name": "list tenant",
+        "command": "tenant list",
+        "result": "(?!alt_demo)",
+        "description": "Check if tenant alt_demo is used."
+      },
+      {
+        "name": "add tenant alt_demo",
+        "command": "tenant add alt_demo",
+        "result": "^$",
+        "description": "Add a new tenant",
+        "command_options": ""
+      },
+      {
+        "name": "check tenant alt_demo",
+        "command": "tenant list",
+        "result": "(?P<uuid>\\w+)\\s+alt_demo",
+        "description": "Check that tenant alt_demo has been correctly added"
+      },
+      {
+        "name": "create_intraextension_authz",
+        "command": "intraextension create --policy_model policy_authz authz_test",
+        "result": "IntraExtension created: (?P<uuid_authz>\\w+)",
+        "description": "Create an authz intra extension",
+        "command_options": ""
+      },
+      {
+        "name": "list_intraextension_authz",
+        "command": "intraextension list",
+        "result": "$uuid_authz",
+        "description": "Check the existence of that authz intra extension"
+      },
+      {
+        "name": "set_tenant_authz",
+        "command": "tenant set --authz $uuid_authz $uuid",
+        "result": "",
+        "description": "Connect the authz intra extension to the tenant alt_demo",
+        "command_options": ""
+      },
+      {
+        "name": "select_authz_ie",
+        "command": "intraextension select $uuid_authz",
+        "result": "Select $uuid_authz IntraExtension.",
+        "description": "Select the authz IntraExtension",
+        "command_options": ""
+      },
+      {
+        "name": "check_select_authz_ie",
+        "command": "intraextension show selected",
+        "result": "$uuid_authz",
+        "description": "Check the selected authz IntraExtension",
+        "command_options": "-c id -f value"
+      },
+      {
+        "name": "add_subject",
+        "command": "subject add alt_demo",
+        "result": "",
+        "description": "Add the new subject category alt_demo",
+        "command_options": ""
+      },
+      {
+        "name": "list_subject",
+        "command": "subject list",
+        "result": "(?P<uuid_subject>\\w+)\\s+alt_demo",
+        "description": "Check that alt_demo subject was added."
+      },
+      {
+        "name": "add_subject_category",
+        "command": "subject category add my_new_subject_category",
+        "result": "",
+        "description": "Add the new subject category my_new_subject_category",
+        "command_options": ""
+      },
+      {
+        "name": "list_subject_category",
+        "command": "subject category list",
+        "result": "(?P<uuid_subject_category>\\w+)\\s+my_new_subject_category",
+        "description": "Check that my_new_subject_category subject_category was added."
+      },
+      {
+        "name": "add_scope",
+        "command": "subject scope add $uuid_subject_category testers --description \"test engineers\"",
+        "result": "^$",
+        "description": "Add one scope to subject category role",
+        "command_options": ""
+      },
+      {
+        "name": "check_added_scope",
+        "command": "subject scope list $uuid_subject_category",
+        "result": "(?P<uuid_subject_scope>\\w+)\\s+testers\\s+test engineers",
+        "description": "Check added scope.",
+        "command_options": "-c id -c name -c description -f value"
+      },
+
+      {
+        "name": "add_assignment",
+        "command": "subject assignment add $uuid_subject $uuid_subject_category $uuid_subject_scope",
+        "result": "^$",
+        "description": "Add a new assignment",
+        "command_options": ""
+      },
+      {
+        "name": "check_added_assignment",
+        "command": "subject assignment list $uuid_subject $uuid_subject_category",
+        "result": "$uuid_subject_scope testers",
+        "description": "Check added assignment.",
+        "command_options": "-c id -c name -f value"
+      },
+
+      {
+        "name": "delete_assignment",
+        "command": "subject assignment delete $uuid_subject $uuid_subject_category $uuid_subject_scope",
+        "result": "^$",
+        "description": "Delete the added assignment",
+        "command_options": ""
+      },
+      {
+        "name": "check_deleted_assignment",
+        "command": "subject assignment list $uuid_subject $uuid_subject_category",
+        "result": "(?!$uuid_subject_scope)",
+        "description": "Check deleted assignment.",
+        "command_options": "-c id -f value"
+      },
+
+      {
+        "name": "delete_scope",
+        "command": "subject scope delete $uuid_subject_category $uuid_subject_scope",
+        "result": "^$",
+        "description": "Delete one scope from subject category role",
+        "command_options": ""
+      },
+      {
+        "name": "delete_subject_category",
+        "command": "subject category delete $uuid_subject_category",
+        "result": "^$",
+        "description": "Delete my_new_subject_category subject_category.",
+        "command_options": ""
+      },
+      {
+        "name": "list_subject_category",
+        "command": "subject category list",
+        "result": "(?!$uuid_subject_category)",
+        "description": "Check that my_new_subject_category subject_category was deleted."
+      },
+      {
+        "name": "delete_authz_intra_extension",
+        "command": "intraextension delete $uuid_authz",
+        "result": "",
+        "description": "Delete the authz intra extension",
+        "command_options": ""
+      },
+      {
+        "name": "delete_tenant",
+        "command": "tenant delete $uuid",
+        "result": "",
+        "description": "Delete the tenant alt_demo",
+        "command_options": ""
+      }
+    ],
+    "authz_and_admin": [
+      {
+        "name": "list tenant",
+        "command": "tenant list",
+        "result": "(?!alt_demo)",
+        "description": "Check if tenant alt_demo is used."
+      },
+      {
+        "name": "add tenant alt_demo",
+        "command": "tenant add alt_demo",
+        "result": "^$",
+        "description": "Add a new tenant",
+        "command_options": ""
+      },
+      {
+        "name": "check tenant alt_demo",
+        "command": "tenant list",
+        "result": "(?P<uuid>\\w+)\\s+alt_demo",
+        "description": "Check that tenant alt_demo has been correctly added"
+      },
+      {
+        "name": "create_intraextension_authz",
+        "command": "intraextension create --policy_model policy_authz authz_test",
+        "result": "IntraExtension created: (?P<uuid_authz>\\w+)",
+        "description": "Create an authz intra extension",
+        "command_options": ""
+      },
+      {
+        "name": "list_intraextension_authz",
+        "command": "intraextension list",
+        "result": "$uuid_authz",
+        "description": "Check the existence of that authz intra extension"
+      },
+      {
+        "name": "create_intraextension_admin",
+        "command": "intraextension create --policy_model policy_admin admin_test",
+        "result": "IntraExtension created: (?P<uuid_admin>\\w+)",
+        "description": "Create an admin intra extension",
+        "command_options": ""
+      },
+      {
+        "name": "list_intraextension_admin",
+        "command": "intraextension list",
+        "result": "$uuid_admin",
+        "description": "Check the existence of that admin intra extension"
+      },
+      {
+        "name": "set_tenant_authz",
+        "command": "tenant set --authz $uuid_authz $uuid",
+        "result": "",
+        "description": "Connect the authz intra extension to the tenant demo",
+        "command_options": ""
+      },
+      {
+        "name": "set_tenant_admin",
+        "command": "tenant set --admin $uuid_admin $uuid",
+        "result": "",
+        "description": "Connect the authz intra extension to the tenant alt_demo",
+        "command_options": ""
+      },
+      {
+        "name": "check tenant alt_demo and authz ie",
+        "command": "tenant list",
+        "result": "alt_demo $uuid_authz",
+        "description": "Check that authz intra extension has been correctly added to the tenant.",
+        "command_options": "-c name -c intra_authz_extension_id -f value"
+      },
+      {
+        "name": "check tenant alt_demo and admin ie",
+        "command": "tenant list",
+        "result": "$uuid_admin",
+        "description": "Check that admin intra extension has been correctly added to the tenant.",
+        "command_options": "-c intra_admin_extension_id -f value"
+      },
+      {
+        "name": "select_authz_ie",
+        "command": "intraextension select $uuid_authz",
+        "result": "Select $uuid_authz IntraExtension.",
+        "description": "Select the authz IntraExtension",
+        "command_options": ""
+      },
+      {
+        "name": "check_select_authz_ie",
+        "command": "intraextension show selected",
+        "result": "$uuid_authz",
+        "description": "Check the selected authz IntraExtension",
+        "command_options": "-c id -f value"
+      },
+      {
+        "name": "add_subject",
+        "command": "subject add alt_demo",
+        "result": "",
+        "description": "Add the new subject category alt_demo",
+        "command_options": ""
+      },
+      {
+        "name": "list_subject",
+        "command": "subject list",
+        "result": "(?P<uuid_subject>\\w+)\\s+alt_demo",
+        "description": "Check that alt_demo subject was added."
+      },
+      {
+        "name": "add_subject_category",
+        "command": "subject category add my_new_subject_category",
+        "result": "",
+        "description": "Add the new subject category my_new_subject_category",
+        "command_options": ""
+      },
+      {
+        "name": "list_subject_category",
+        "command": "subject category list",
+        "result": "(?P<uuid_subject_category>\\w+)\\s+my_new_subject_category",
+        "description": "Check that my_new_subject_category subject_category was added."
+      },
+      {
+        "name": "add_scope",
+        "command": "subject scope add $uuid_subject_category testers --description \"test engineers\"",
+        "result": "^$",
+        "description": "Add one scope to subject category role",
+        "command_options": ""
+      },
+      {
+        "name": "check_added_scope",
+        "command": "subject scope list $uuid_subject_category",
+        "result": "(?P<uuid_subject_scope>\\w+)\\s+testers\\s+test engineers",
+        "description": "Check added scope.",
+        "command_options": "-c id -c name -c description -f value"
+      },
+
+      {
+        "name": "add_assignment",
+        "command": "subject assignment add $uuid_subject $uuid_subject_category $uuid_subject_scope",
+        "result": "^$",
+        "description": "Add a new assignment",
+        "command_options": ""
+      },
+      {
+        "name": "check_added_assignment",
+        "command": "subject assignment list $uuid_subject $uuid_subject_category",
+        "result": "$uuid_subject_scope testers",
+        "description": "Check added assignment.",
+        "command_options": "-c id -c name -f value"
+      },
+
+      {
+        "name": "delete_assignment",
+        "command": "subject assignment delete $uuid_subject $uuid_subject_category $uuid_subject_scope",
+        "result": "^$",
+        "description": "Delete the added assignment",
+        "command_options": ""
+      },
+      {
+        "name": "check_deleted_assignment",
+        "command": "subject assignment list $uuid_subject $uuid_subject_category",
+        "result": "(?!$uuid_subject_scope)",
+        "description": "Check deleted assignment.",
+        "command_options": "-c id -f value"
+      },
+
+      {
+        "name": "delete_scope",
+        "command": "subject scope delete $uuid_subject_category $uuid_subject_scope",
+        "result": "^$",
+        "description": "Delete one scope from subject category role",
+        "command_options": ""
+      },
+      {
+        "name": "delete_subject_category",
+        "command": "subject category delete $uuid_subject_category",
+        "result": "^$",
+        "description": "Delete my_new_subject_category subject_category.",
+        "command_options": ""
+      },
+      {
+        "name": "list_subject_category",
+        "command": "subject category list",
+        "result": "(?!$uuid_subject_category)",
+        "description": "Check that my_new_subject_category subject_category was deleted."
+      },
+      {
+        "name": "delete_admin_intra_extension",
+        "command": "intraextension delete $uuid_admin",
+        "result": "",
+        "description": "Delete the admin intra extension",
+        "command_options": ""
+      },
+      {
+        "name": "delete_authz_intra_extension",
+        "command": "intraextension delete $uuid_authz",
+        "result": "",
+        "description": "Delete the authz intra extension",
+        "command_options": ""
+      },
+      {
+        "name": "delete_tenant",
+        "command": "tenant delete $uuid",
+        "result": "",
+        "description": "Delete the tenant alt_demo",
+        "command_options": ""
+      }
+    ]
+  }
+}
\ No newline at end of file