Skip to content

Commit

Permalink
rename fixture module_viewer_user
Browse files Browse the repository at this point in the history
  • Loading branch information
jameerpathan111 committed Oct 20, 2020
1 parent 2d6b468 commit 4059518
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 35 deletions.
2 changes: 1 addition & 1 deletion pytest_fixtures/user_fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@


@pytest.fixture(scope='module')
def module_viewer_user(module_org, default_location):
def default_viewer_role(module_org, default_location):
"""Custom user with viewer role for tests validating visibility of entities or fields created
by some other user. Created only when accessed, unlike `module_user`.
"""
Expand Down
6 changes: 3 additions & 3 deletions tests/foreman/cli/test_oscap.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def test_positive_list_default_content_with_admin(self):

@tier1
def test_negative_list_default_content_with_viewer_role(
self, scap_content, module_viewer_user
self, scap_content, default_viewer_role
):
"""List the default scap content by user with viewer role
Expand All @@ -117,11 +117,11 @@ def test_negative_list_default_content_with_viewer_role(
:CaseImportance: Critical
"""
result = Scapcontent.with_user(
module_viewer_user.login, module_viewer_user.password
default_viewer_role.login, default_viewer_role.password
).list()
assert len(result) == 0
with pytest.raises(CLIReturnCodeError):
Scapcontent.with_user(module_viewer_user.login, module_viewer_user.password).info(
Scapcontent.with_user(default_viewer_role.login, default_viewer_role.password).info(
{'title': scap_content['title']}
)

Expand Down
22 changes: 0 additions & 22 deletions tests/foreman/ui/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,28 +71,6 @@ def module_user(request, module_org, module_loc):
LOGGER.warning('Unable to delete session user: %s', str(err))


@fixture(scope='module')
def module_viewer_user(module_org):
"""Custom user with viewer role for tests validating visibility of entities or fields created
by some other user. Created only when accessed, unlike `module_user`.
"""
viewer_role = nailgun.entities.Role().search(query={'search': 'name="Viewer"'})[0]
default_loc_id = (
nailgun.entities.Location().search(query={'search': 'name="{}"'.format(DEFAULT_LOC)})[0].id
)
custom_password = gen_string('alphanumeric')
custom_user = nailgun.entities.User(
admin=False,
default_organization=module_org,
location=[default_loc_id],
organization=[module_org],
role=[viewer_role],
password=custom_password,
).create()
custom_user.password = custom_password
return custom_user


@fixture()
def test_name(request):
"""Returns current test full name, prefixed by module name and test class
Expand Down
14 changes: 7 additions & 7 deletions tests/foreman/ui/test_bookmarks.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ def test_positive_end_to_end(session, random_entity):


@tier2
def test_positive_create_bookmark_public(session, random_entity, module_viewer_user, test_name):
def test_positive_create_bookmark_public(session, random_entity, default_viewer_role, test_name):
"""Create and check visibility of the (non)public bookmarks
:id: 93139529-7690-429b-83fe-3dcbac4f91dc
Expand Down Expand Up @@ -153,14 +153,14 @@ def test_positive_create_bookmark_public(session, random_entity, module_viewer_u
{'name': name, 'query': gen_string('alphanumeric'), 'public': name == public_name}
)
assert session.bookmark.search(name)[0]['Name'] == name
with Session(test_name, module_viewer_user.login, module_viewer_user.password) as session:
with Session(test_name, default_viewer_role.login, default_viewer_role.password) as session:
assert session.bookmark.search(public_name)[0]['Name'] == public_name
assert not session.bookmark.search(nonpublic_name)


@tier2
def test_positive_update_bookmark_public(
session, random_entity, module_viewer_user, module_user, test_name
session, random_entity, default_viewer_role, module_user, test_name
):
"""Update and save a bookmark public state
Expand Down Expand Up @@ -209,22 +209,22 @@ def test_positive_update_bookmark_public(
cfg, name=name, controller=random_entity['controller'], public=name == public_name
).create()
with Session(
test_name, module_viewer_user.login, module_viewer_user.password
test_name, default_viewer_role.login, default_viewer_role.password
) as non_admin_session:
assert non_admin_session.bookmark.search(public_name)[0]['Name'] == public_name
assert not non_admin_session.bookmark.search(nonpublic_name)
with session:
session.bookmark.update(public_name, {'public': False})
session.bookmark.update(nonpublic_name, {'public': True})
with Session(
test_name, module_viewer_user.login, module_viewer_user.password
test_name, default_viewer_role.login, default_viewer_role.password
) as non_admin_session:
assert non_admin_session.bookmark.search(nonpublic_name)[0]['Name'] == nonpublic_name
assert not non_admin_session.bookmark.search(public_name)


@tier2
def test_negative_delete_bookmark(random_entity, module_viewer_user, test_name):
def test_negative_delete_bookmark(random_entity, default_viewer_role, test_name):
"""Simple removal of a bookmark query without permissions
:id: 1a94bf2b-bcc6-4663-b70d-e13244a0783b
Expand All @@ -247,7 +247,7 @@ def test_negative_delete_bookmark(random_entity, module_viewer_user, test_name):
"""
bookmark = entities.Bookmark(controller=random_entity['controller'], public=True).create()
with Session(
test_name, module_viewer_user.login, module_viewer_user.password
test_name, default_viewer_role.login, default_viewer_role.password
) as non_admin_session:
assert non_admin_session.bookmark.search(bookmark.name)[0]['Name'] == bookmark.name
with raises(NoSuchElementException):
Expand Down
4 changes: 2 additions & 2 deletions tests/foreman/ui/test_contenthost.py
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,7 @@ def test_actions_katello_host_package_update_timeout(session, vm):


@tier3
def test_positive_search_errata_non_admin(session, vm, module_org, test_name, module_viewer_user):
def test_positive_search_errata_non_admin(session, vm, module_org, test_name, default_viewer_role):
"""Search for host's errata by non-admin user with enough permissions
:id: 5b8887d2-987f-4bce-86a1-8f65ca7e1195
Expand All @@ -511,7 +511,7 @@ def test_positive_search_errata_non_admin(session, vm, module_org, test_name, mo
"""
vm.run('yum install -y {0}'.format(FAKE_1_CUSTOM_PACKAGE))
with Session(
test_name, user=module_viewer_user.login, password=module_viewer_user.password
test_name, user=default_viewer_role.login, password=default_viewer_role.password
) as session:
chost = session.contenthost.read(vm.hostname, widget_names='errata')
assert FAKE_2_ERRATA_ID in {errata['Id'] for errata in chost['errata']['table']}
Expand Down

0 comments on commit 4059518

Please sign in to comment.