Skip to content

Commit

Permalink
[#2218] Mild improvement in test brittleness, using library for the f…
Browse files Browse the repository at this point in the history
…orm rather than grepping exact strings.
  • Loading branch information
David Read committed Jan 29, 2015
1 parent c7f62b6 commit 088638a
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions ckan/new_tests/controllers/test_package.py
Expand Up @@ -167,10 +167,10 @@ def test_dataset_edit_org_dropdown_visible_to_normal_user_with_orgs_available(se
)

# organization dropdown available in create page.
assert 'id="field-organizations"' in response
form = response.forms['dataset-edit']
assert 'owner_org' in form.fields

# create dataset
form = response.forms['dataset-edit']
form['name'] = u'my-dataset'
form['owner_org'] = org['id']
response = submit_and_follow(app, form, env, 'save')
Expand All @@ -188,9 +188,11 @@ def test_dataset_edit_org_dropdown_visible_to_normal_user_with_orgs_available(se
id=pkg.id)
pkg_edit_response = app.get(url=url, extra_environ=env)
# A field with the correct id is in the response
assert 'id="field-organizations"' in pkg_edit_response
form = pkg_edit_response.forms['dataset-edit']
assert 'owner_org' in form.fields
# The organization id is in the response in a value attribute
assert 'value="{0}"'.format(org['id']) in pkg_edit_response
owner_org_options = [value for (value, _) in form['owner_org'].options]
assert org['id'] in owner_org_options

def test_dataset_edit_org_dropdown_normal_user_can_remove_org(self):
'''
Expand Down Expand Up @@ -255,11 +257,11 @@ def test_dataset_edit_org_dropdown_not_visible_to_normal_user_with_no_orgs_avail
extra_environ=env,
)

# organization dropdown available in create page.
assert 'id="field-organizations"' not in response
# organization dropdown not in create page.
form = response.forms['dataset-edit']
assert 'owner_org' not in form.fields

# create dataset
form = response.forms['dataset-edit']
form['name'] = u'my-dataset'
response = submit_and_follow(app, form, env, 'save')

Expand All @@ -276,7 +278,8 @@ def test_dataset_edit_org_dropdown_not_visible_to_normal_user_with_no_orgs_avail
id=model.Package.by_name(u'my-dataset').id)
pkg_edit_response = app.get(url=url, extra_environ=env)
# A field with the correct id is in the response
assert 'id="field-organizations"' not in pkg_edit_response
form = pkg_edit_response.forms['dataset-edit']
assert 'owner_org' not in form.fields
# The organization id is in the response in a value attribute
assert 'value="{0}"'.format(org['id']) not in pkg_edit_response

Expand Down

0 comments on commit 088638a

Please sign in to comment.