Skip to content

Commit

Permalink
[#3046] add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
k-nut authored and Knut Hühne committed Jun 6, 2016
1 parent 48ffbf5 commit ff93ffb
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions ckan/tests/controllers/test_package.py
Expand Up @@ -8,6 +8,7 @@
assert_true,
)

from mock import patch
from routes import url_for

import ckan.model as model
Expand Down Expand Up @@ -40,6 +41,43 @@ def test_form_renders(self):
env, response = _get_package_new_page(app)
assert_true('dataset-edit' in response.forms)

@helpers.change_config('ckan.auth.create_unowned_dataset', 'false')
def test_needs_organization_but_no_organizations_has_button(self,):
''' Scenario: The settings say every dataset needs an organization
but there are no organizations. If the user is allowed to create an
organization they should be prompted to do so when they try to create
a new dataset'''
app = self._get_test_app()
sysadmin = factories.Sysadmin()

env = {'REMOTE_USER': sysadmin['name'].encode('ascii')}
response = app.get(
url=url_for(controller='package', action='new'),
extra_environ=env
)
assert 'dataset-edit' not in response.forms
assert url_for(controller='organization', action='new') in response

@patch('ckan.logic.auth.create.organization_create',
return_value={'success': False})
@helpers.change_config('ckan.auth.create_unowned_dataset', 'false')
def test_needs_organization_but_no_organizations_no_button(self, *args):
''' Scenario: The settings say every dataset needs an organization
but there are no organizations. If the user is not allowed to create an
organization they should be told to ask the admin but no link should be
presented'''
app = self._get_test_app()
sysadmin = factories.Sysadmin()

env = {'REMOTE_USER': sysadmin['name'].encode('ascii')}
response = app.get(
url=url_for(controller='package', action='new'),
extra_environ=env
)
assert 'dataset-edit' not in response.forms
assert url_for(controller='organization', action='new') not in response
assert 'Ask a system administrator' in response

def test_name_required(self):
app = self._get_test_app()
env, response = _get_package_new_page(app)
Expand Down

0 comments on commit ff93ffb

Please sign in to comment.