Пример #1
0
 def get(self, request):
     """Gets a role."""
     self.check_xsrf_token(self.request_state)
     role = user_model.Role.get_by_name(request.name)
     return user_messages.Role(name=role.name,
                               permissions=role.permissions,
                               associated_group=role.associated_group)
  def testRole(self):
    role = user_messages.Role(
        name='FAKE-ROLE-NAME',
        permissions=['FAKE-PERMISSION-1', 'FAKE-PERMISSION-2'],
        associated_group='FAKE-ASSOCIATED-GROUP')

    self.assertEqual(role.name, 'FAKE-ROLE-NAME')
    self.assertEqual(role.associated_group, 'FAKE-ASSOCIATED-GROUP')
    self.assertListEqual(
        role.permissions, ['FAKE-PERMISSION-1', 'FAKE-PERMISSION-2'])
Пример #3
0
    def test_create(self):
        new_role = user_messages.Role(
            name='test',
            permissions=['get', 'put'],
            associated_group=loanertest.TECHNICAL_ADMIN_EMAIL)

        self.service.create(new_role)

        created_role = user_model.Role.get_by_name('test')
        self.assertEqual(new_role.name, created_role.name)
        self.assertCountEqual(new_role.permissions, created_role.permissions)
Пример #4
0
def build_role_message_from_model(role):
    """Builds a role ProtoRPC message.

  Args:
    role: user_model.Role, the role for a user.

  Returns:
    A role_messages.Role message with the respective properties.
  """
    return user_messages.Role(name=role.name,
                              permissions=role.permissions,
                              associated_group=role.associated_group)
Пример #5
0
    def test_build_role_message_from_model(self):
        """Test the construction of a role message from a role entity."""
        test_role = user_model.Role(
            key=ndb.Key(user_model.Role, 'test_role'),
            permissions=['get', 'put'],
            associated_group=loanertest.TECHNICAL_ADMIN_EMAIL).put().get()

        expected_message = user_messages.Role(
            name='test_role',
            permissions=['get', 'put'],
            associated_group=loanertest.TECHNICAL_ADMIN_EMAIL)

        actual_message = api_utils.build_role_message_from_model(test_role)

        self.assertEqual(actual_message, expected_message)
Пример #6
0
    def test_update(self):
        created_role = user_model.Role.create(
            name='test',
            role_permissions=['get', 'put'],
            associated_group=loanertest.TECHNICAL_ADMIN_EMAIL)
        update_message = user_messages.Role(
            name='test',
            permissions=['get', 'create'],
            associated_group=loanertest.TECHNICAL_ADMIN_EMAIL)

        self.service.update(update_message)

        retrieved_role = user_model.Role.get_by_name('test')
        self.assertCountEqual(update_message.permissions,
                              retrieved_role.permissions)
        self.assertEqual(created_role.associated_group,
                         retrieved_role.associated_group)
 def testListRoleResponse(self):
   role_1 = user_messages.Role(name='FAKE-ROLE-NAME-1')
   role_2 = user_messages.Role(name='FAKE-ROLE-NAME-2')
   list_role_resp = user_messages.ListRoleResponse(roles=[role_1, role_2])
   self.assertListEqual(list_role_resp.roles, [role_1, role_2])