Sergey Vilgelm | bab9e94 | 2018-10-11 14:04:48 -0500 | [diff] [blame] | 1 | --- |
| 2 | features: |
| 3 | - | |
| 4 | In order to test the list actions which doesn't have its own policy, |
| 5 | implemented the ``override_role_and_validate_list`` function. |
| 6 | The function has two modes: |
| 7 | |
| 8 | * Validating the number of the resources in a ``ResponseBody`` before |
| 9 | calling the ``override_role`` and after. |
| 10 | |
| 11 | .. code-block:: python |
| 12 | |
| 13 | # make sure at least one resource is available |
| 14 | self.ntp_client.create_policy_dscp_marking_rule() |
| 15 | # the list of resources available for a user with admin role |
| 16 | admin_resources = self.ntp_client.list_dscp_marking_rules( |
| 17 | policy_id=self.policy_id)["dscp_marking_rules"] |
| 18 | with self.rbac_utils.override_role_and_validate_list( |
| 19 | self, admin_resources=admin_resources) as ctx: |
| 20 | # the list of resources available for a user with member role |
| 21 | ctx.resources = self.ntp_client.list_dscp_marking_rules( |
| 22 | policy_id=self.policy_id)["dscp_marking_rules"] |
| 23 | |
| 24 | * Validating that a resource, created before ``override_role``, is not |
| 25 | present in a ``ResponseBody``. |
| 26 | |
| 27 | .. code-block:: python |
| 28 | |
| 29 | # the resource created by a user with admin role |
| 30 | admin_resource_id = ( |
| 31 | self.ntp_client.create_dscp_marking_rule() |
| 32 | ["dscp_marking_rule"]["id']) |
| 33 | with self.rbac_utils.override_role_and_validate_list( |
| 34 | self, admin_resource_id=admin_resource_id) as ctx: |
| 35 | # the list of resources available for a user wirh member role |
| 36 | ctx.resources = self.ntp_client.list_dscp_marking_rules( |
| 37 | policy_id=self.policy_id)["dscp_marking_rules"] |