|
2 | 2 |
|
3 | 3 | import pytest |
4 | 4 |
|
5 | | -from testsuite.ui.views.admin.audience.billing import BillingSettingsView, BillingView |
| 5 | +from testsuite.ui.views.admin.audience.account import AccountsView |
| 6 | +from testsuite.ui.views.admin.audience.billing import ( |
| 7 | + BillingSettingsView, |
| 8 | + BillingView, |
| 9 | +) |
6 | 10 | from testsuite.ui.views.admin.audience.developer_portal import ( |
7 | 11 | ActiveDocsView, |
8 | 12 | CMSNewPageView, |
9 | 13 | CMSNewSectionView, |
10 | 14 | DeveloperPortalContentView, |
11 | 15 | ) |
| 16 | +from testsuite.ui.views.admin.backend.analytics import BackendTrafficView |
12 | 17 | from testsuite.ui.views.admin.foundation import AccessDeniedView |
13 | 18 |
|
14 | | -PERMISSION_DICT = [ |
15 | | - pytest.param("portal", DeveloperPortalContentView), |
16 | | - pytest.param("portal", DeveloperPortalContentView), |
17 | | - pytest.param("portal", CMSNewPageView), |
18 | | - pytest.param("portal", CMSNewSectionView), |
19 | | - pytest.param("finance", BillingView), |
20 | | - pytest.param( |
21 | | - "finance", |
22 | | - BillingSettingsView, |
23 | | - marks=[pytest.mark.xfail, pytest.mark.issue("https://issues.redhat.com/browse/THREESCALE-10995")], |
24 | | - ), |
25 | | - pytest.param("plans", ActiveDocsView), |
26 | | -] |
27 | | - |
28 | | - |
29 | | -@pytest.fixture() |
30 | | -def all_page_objects(): |
31 | | - """Returns all page objects from permissions tuple filtered of views with same permission""" |
32 | | - |
33 | | - def _all_page_objects(except_permission, current_view): |
| 19 | +PERMISSIONS = ["portal", "finance", "settings", "partners", "monitoring", "plans", "policy_registry"] |
34 | 20 |
|
35 | | - all_views = [ |
36 | | - view |
37 | | - for perm, view in [param.values for param in PERMISSION_DICT] |
38 | | - if perm != except_permission or view == current_view |
39 | | - ] |
40 | | - |
41 | | - return all_views |
42 | | - |
43 | | - return _all_page_objects |
| 21 | +VIEWS = [ |
| 22 | + ("portal", DeveloperPortalContentView), |
| 23 | + ("portal", CMSNewPageView), |
| 24 | + ("portal", CMSNewSectionView), |
| 25 | + ("finance", BillingView), |
| 26 | + ("finance", BillingSettingsView), |
| 27 | + ("plans", ActiveDocsView), |
| 28 | + ("monitoring", BackendTrafficView), |
| 29 | + ("partners", AccountsView), |
| 30 | +] |
44 | 31 |
|
45 | 32 |
|
46 | 33 | # pylint: disable=too-many-arguments |
47 | | -@pytest.mark.parametrize("permission, page_view", PERMISSION_DICT) |
| 34 | +@pytest.mark.parametrize("user_permission", PERMISSIONS) |
| 35 | +@pytest.mark.parametrize("required_permission, page_view", VIEWS) |
48 | 36 | def test_member_user_permissions_per_section( |
| 37 | + account_password, |
49 | 38 | custom_admin_login, |
50 | 39 | navigator, |
51 | 40 | provider_member_user, |
52 | | - all_page_objects, |
53 | | - permission, |
| 41 | + backend_default, |
| 42 | + user_permission, |
| 43 | + required_permission, |
54 | 44 | page_view, |
55 | | - allowed_services=False, |
| 45 | + is_page_accessible, |
56 | 46 | ): |
57 | | - """Tests user permissions permission per permission section""" |
58 | | - member_user = provider_member_user(allowed_sections=permission, allowed_services=allowed_services) |
59 | | - custom_admin_login(member_user.entity_name, "123456") |
60 | | - |
61 | | - page_objects = all_page_objects(permission, page_view) |
| 47 | + """ |
| 48 | + Tests user permissions permission per permission section |
| 49 | + - Creates a member user with a specific permission |
| 50 | + - Logs in as that member user |
| 51 | + - Attempts to access a specific UI page |
| 52 | + - If users permission matches page's required permission -> allowed |
| 53 | + - Else, access denied |
| 54 | + """ |
| 55 | + member_user = provider_member_user(allowed_sections=[user_permission], allowed_services=None) |
| 56 | + custom_admin_login(member_user.entity_name, account_password) |
62 | 57 |
|
63 | | - for pg_obj in page_objects: |
64 | | - # Dynamically import the view class |
65 | | - view_module = __import__(pg_obj.__module__, fromlist=[pg_obj.__name__]) |
66 | | - page_class = getattr(view_module, pg_obj.__name__) |
67 | | - page = navigator.open(page_class, wait_displayed=False) |
| 58 | + if page_view == BackendTrafficView: |
| 59 | + page = navigator.open(page_view, backend=backend_default, wait_displayed=False) |
| 60 | + else: |
| 61 | + page = navigator.open(page_view, wait_displayed=False) |
68 | 62 |
|
69 | | - if pg_obj == page_view: |
70 | | - assert ( |
71 | | - page.is_displayed |
72 | | - ), f"{pg_obj.__name__} should be displayed for permissions {permission} and services {allowed_services}" |
73 | | - else: |
74 | | - assert AccessDeniedView(navigator.browser.root_browser).is_displayed, ( |
75 | | - f"{pg_obj.__name__}" |
76 | | - f" should not be displayed for permissions {permission} and services {allowed_services}" |
77 | | - ) |
| 63 | + if user_permission == required_permission: |
| 64 | + assert is_page_accessible(page), f"A user with {user_permission} should be able to access {page_view}" |
| 65 | + else: |
| 66 | + access_denied_view = AccessDeniedView(navigator.browser.root_browser) |
| 67 | + assert ( |
| 68 | + access_denied_view.is_displayed |
| 69 | + ), f"A user with {user_permission} should not be able to access {page_view}" |
0 commit comments