Пример #1
0
    def create_user(login, password=None, name=None, roles=None):
        """
        Creates a new Pulp user and adds it to specified to roles.

        @param login: login name / unique identifier for the user
        @type  login: str

        @param password: password for login credentials
        @type  password: str

        @param name: user's full name
        @type  name: str

        @param roles: list of roles user will belong to
        @type  roles: list

        @raise DuplicateResource: if there is already a user with the requested login
        @raise InvalidValue: if any of the fields are unacceptable
        """

        existing_user = get_collection('users').find_one({'login': login})
        if existing_user is not None:
            raise DuplicateResource(login)

        invalid_values = []

        if login is None or _USER_LOGIN_REGEX.match(login) is None:
            invalid_values.append('login')
        if invalid_type(name, basestring):
            invalid_values.append('name')
        if invalid_type(roles, list):
            invalid_values.append('roles')

        if invalid_values:
            raise InvalidValue(invalid_values)

        # Use the login for name of the user if one was not specified
        name = name or login
        roles = roles or None

        # Creation
        create_me = model.User(login=login, name=name, roles=roles)
        create_me.set_password(password)
        create_me.save()

        # Grant permissions
        permission_manager = factory.permission_manager()
        permission_manager.grant_automatic_permissions_for_user(
            create_me.login)

        # Retrieve the user to return the SON object
        created = get_collection('users').find_one({'login': login})
        created.pop('password')

        return created
Пример #2
0
    def test_import_uploaded_unit(self, mock_repo_qs, mock_rebuild):
        importer_controller.set_importer('repo-u', 'mock-importer', {})

        key = {'key': 'value'}
        metadata = {'k1': 'v1'}
        timestamp_pre_upload = dateutils.now_utc_datetime_with_tzinfo()

        mock_repo = mock_repo_qs.get_repo_or_missing_resource.return_value
        importer_return_report = {
            'success_flag': True,
            'summary': '',
            'details': {}
        }
        mock_plugins.MOCK_IMPORTER.upload_unit.return_value = importer_return_report

        upload_id = self.upload_manager.initialize_upload()
        file_path = self.upload_manager._upload_file_path(upload_id)

        fake_user = model.User('import-user', '')
        manager_factory.principal_manager().set_principal(principal=fake_user)

        response = self.upload_manager.import_uploaded_unit(
            'repo-u', 'mock-type', key, metadata, upload_id)

        # import_uploaded_unit() should have returned our importer_return_report
        self.assertTrue(response is importer_return_report)

        call_args = mock_plugins.MOCK_IMPORTER.upload_unit.call_args[0]
        self.assertTrue(call_args[0] is mock_repo.to_transfer_repo())
        self.assertEqual(call_args[1], 'mock-type')
        self.assertEqual(call_args[2], key)
        self.assertEqual(call_args[3], metadata)
        self.assertEqual(call_args[4], file_path)

        conduit = call_args[5]
        self.assertTrue(isinstance(conduit, UploadConduit))
        self.assertEqual(call_args[5].repo_id, 'repo-u')

        # It is now platform's responsibility to update plugin content unit counts
        self.assertTrue(mock_rebuild.called,
                        "rebuild_content_unit_counts must be called")

        # Make sure that the last_unit_added timestamp was updated
        self.assertTrue(mock_repo.last_unit_added > timestamp_pre_upload)

        # Clean up
        mock_plugins.MOCK_IMPORTER.upload_unit.return_value = None
        manager_factory.principal_manager().set_principal(principal=None)
Пример #3
0
def create_user(login, password=None, name=None, roles=None):
    """
    Creates a new Pulp user and adds it to specified to roles.

    :param login: login name / unique identifier for the user
    :type  login: str
    :param password: password for login credentials
    :type  password: str
    :param name: user's full name
    :type  name: str
    :param roles: list of roles user will belong to
    :type  roles: list

    :raise DuplicateResource: if there is already a user with the requested login
    :raise InvalidValue: if any of the fields are unacceptable
    """
    user = model.User(login=login, name=name, roles=roles)
    user.set_password(password)
    try:
        user.save()
    except NotUniqueError:
        raise pulp_exceptions.DuplicateResource(login)
    except ValidationError, e:
        raise pulp_exceptions.InvalidValue(e.to_dict().keys())
Пример #4
0
 def setUp(self):
     """
     Create a base User.
     """
     self.user = model.User(login='******', password='******')