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
 def test_delete_global_template_as_superuser_saves(self):
     mock_request = create_mock_request(user=self.superuser1)
     template_api.delete(self.fixture.global_template, request=mock_request)
 def test_delete_other_users_template_as_superuser_saves(self):
     mock_request = create_mock_request(user=self.superuser1)
     template_api.delete(self.fixture.user2_template, request=mock_request)
 def test_delete_other_users_template_as_staff_raises_access_control_error(
         self):
     mock_request = create_mock_request(user=self.staff_user1)
     with self.assertRaises(AccessControlError):
         template_api.delete(self.fixture.user2_template,
                             request=mock_request)
 def test_delete_own_template_as_staff_saves(self):
     mock_request = create_mock_request(user=self.staff_user1)
     template_api.delete(self.fixture.user1_template, request=mock_request)
 def test_delete_global_template_as_user_raises_access_control_error(self):
     mock_request = create_mock_request(user=self.user1)
     with self.assertRaises(AccessControlError):
         template_api.delete(self.fixture.global_template,
                             request=mock_request)