Exemple #1
0
def insert(template_version_manager, template):
    """Add a version to a template version manager.

    Args:
        template_version_manager:
        template:

    Returns:

    """
    # save the template in database
    template_api.upsert(template)
    try:
        # insert the initial template in the version manager
        version_manager_api.insert_version(template_version_manager, template)
        # insert the version manager in database
        version_manager_api.upsert(template_version_manager)
        # get template display name
        display_name = get_latest_version_name(template_version_manager)
        # update saved template
        template_api.set_display_name(template, display_name)
        # return version manager
        return template_version_manager
    except Exception, e:
        template_api.delete(template)
        raise e
Exemple #2
0
def insert(type_version_manager, type_object, request, list_bucket_ids=None):
    """Add a version to a type version manager.

    Args:
        type_version_manager:
        type_object:
        request:
        list_bucket_ids:

    Returns:

    """
    # save the type in database
    type_api.upsert(type_object, request=request)
    try:
        # insert the initial template in the version manager
        version_manager_api.insert_version(
            type_version_manager, type_object, request=request
        )
        # insert the version manager in database
        version_manager_api.upsert(type_version_manager, request=request)
        # Add to the selected buckets
        bucket_api.add_type_to_buckets(type_version_manager, list_bucket_ids)
        # get type display name
        display_name = get_latest_version_name(type_version_manager)
        # update saved template
        template_api.set_display_name(type_object, display_name, request=request)
        # update saved type
        return type_version_manager
    except Exception as e:
        type_api.delete(type_object, request=request)
        raise e
    def test_version_manager_insert_first_version_sets_current(
            self, mock_save):
        # Arrange
        version_manager = _create_version_manager()
        version = _create_mock_object()
        mock_save.return_value = None

        # Act + Assert
        version_manager_api.insert_version(version_manager, version)

        self.assertEquals(version_manager.current, str(version.id))
Exemple #4
0
    def test_version_manager_insert_first_version_sets_current(
            self, mock_save):
        # Arrange
        mock_user = create_mock_user("1", is_superuser=True)
        mock_request = create_mock_request(mock_user)
        version_manager = _create_version_manager()
        version = _create_mock_object()
        mock_save.return_value = None

        # Act + Assert
        version_manager_api.insert_version(version_manager,
                                           version,
                                           request=mock_request)

        self.assertEquals(version_manager.current, str(version.id))