Skip to content

Commit dd751b0

Browse files
authored
Merge pull request 3scale-qe#938 from mastastny/test-ui-policy-list-complete
2 parents 772225c + aad00ef commit dd751b0

File tree

3 files changed

+108
-17
lines changed

3 files changed

+108
-17
lines changed

testsuite/tests/ui/policies/test_policies.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,23 @@
11
"""Rewrite of spec/ui_specs/policies_spec.rb"""
22

3-
import pytest
3+
from collections import Counter
44

5+
import pytest
56
from testsuite.ui.views.admin.product.integration.configuration import ProductConfigurationView
67
from testsuite.ui.views.admin.product.integration.policies import ProductPoliciesView, Policies
78

89
pytestmark = pytest.mark.usefixtures("login")
910

1011

12+
@pytest.fixture()
13+
def policy_list():
14+
"""generate list of all policies"""
15+
policies = [policy.value for policy in list(Policies)]
16+
policies.remove("3scale APIcast") # default policy is not in the policy registry
17+
policies.remove("fapi")
18+
return policies
19+
20+
1121
def test_add_policy(navigator, policy_service):
1222
"""
1323
Test:
@@ -158,3 +168,13 @@ def test_edit_policy_widgets(navigator, policy_service, api_client, policy_appli
158168

159169
response = api_client(app=policy_application).get("/hello")
160170
assert response.json()["path"] == "/get"
171+
172+
173+
@pytest.mark.issue("https://issues.redhat.com/browse/THREESCALE-11620")
174+
def test_policy_list(navigator, policy_service, policy_list):
175+
"""Test:
176+
- Create service via API
177+
- Navigate to Policies page and check, that policy registry displays all policies from policy_list"""
178+
policies_page = navigator.navigate(ProductPoliciesView, product=policy_service)
179+
registry_policies = policies_page.policy_section.registry_items
180+
assert Counter(policy_list) == Counter(registry_policies)

testsuite/ui/views/admin/product/integration/policies.py

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,50 @@ class Policies(enum.Enum):
1616
"""Policies enum"""
1717

1818
THREESCALE_APICAST = "3scale APIcast"
19-
ECHO = "Echo"
19+
2020
THREESCALE_REFERRER = "3scale Referrer"
21+
THREESCALE_AUTH_CACHING = "3scale Auth Caching"
22+
HTTP_STATUS_CODE_OVERWRITE = "HTTP Status Code Overwrite"
23+
CAMEL_SERVICE = "Camel Service"
24+
# tbd
25+
# CONDITIONAL_POLICY = "Conditional Policy [Tech preview]"
26+
CONTENT_CACHING = "Content caching"
27+
PROXY_SERVICE = "Proxy Service"
28+
CORS_REQUEST_HANDLING = "CORS Request Handling"
29+
CUSTOM_METRICS = "Custom Metrics"
30+
ANONYMOUS_ACCESS = "Anonymous Access"
31+
RATE_LIMITS_HEADERS = "Rate Limits Headers"
32+
ECHO = "Echo"
33+
EDGE_LIMITING = "Edge Limiting"
34+
HTTP2_ENDPOINT = "HTTP2 Endpoint"
35+
RETRY = "Retry"
36+
ROUTING = "Routing"
37+
SOAP = "SOAP"
38+
RH_SSO_KEYCLOAK_ROLE_CHECK = "RH-SSO/Keycloak Role Check"
39+
LIQUID_CONTEXT_DEBUG = "Liquid Context Debug"
40+
LOGGING = "Logging"
41+
MAINTENANCE_MODE = "Maintenance Mode"
42+
OAUTH_TWO_TOKEN_INTROSPECTION = "OAuth 2.0 Token Introspection"
43+
UPSTREAM = "Upstream"
44+
UPSTREAM_CONNECTION = "Upstream Connection"
45+
NGINX_FILTER = "Nginx Filter"
46+
UPSTREAM_MUTUAL_TLS = "Upstream Mutual TLS"
2147
URL_REWRITING = "URL Rewriting"
48+
WEBSOCKET = "Websocket"
49+
TLS_CLIENT_CERTIFICATE_VALIDATION = "TLS Client Certificate Validation"
50+
TLS_TERMINATION = "TLS Termination"
51+
RESPONSE_REQUEST_CONTENT_LIMITS = "Response/Request content limits"
52+
OAUTH_TWO_MUTUAL_TLS_CLIENT_AUTHENTICATION = "OAuth 2.0 Mutual TLS Client Authentication"
53+
HEADER_MODIFICATION = "Header Modification"
54+
JWT_CLAIM_CHECK = "JWT Claim Check"
55+
IP_CHECK = "IP Check"
56+
THREESCALE_BATCHER = "3scale Batcher"
57+
ON_FAIL = "On fail"
58+
REQUEST_UNBUFFERED = "Request Unbuffered"
59+
FAPI = "fapi"
60+
URL_REWRITING_WITH_CAPTURES = "URL Rewriting with Captures"
61+
THE_FINANCIAL_GRADE_API = "The Financial-grade API (FAPI)"
62+
JWT_PARSER = "JWT Parser"
2263

2364

2465
class EchoPolicyView(View):

testsuite/ui/widgets/__init__.py

Lines changed: 45 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
from selenium.webdriver.common.by import By
66
from widgetastic.exceptions import NoSuchElementException
77
from widgetastic.utils import ParametrizedLocator
8-
from widgetastic.widget import GenericLocatorWidget, Widget
8+
from widgetastic.widget import GenericLocatorWidget, Widget, View
99
from widgetastic.widget import TextInput
1010
from widgetastic.xpath import quote
11-
from widgetastic_patternfly4 import Select
11+
from widgetastic_patternfly4 import Select, Modal
1212

1313
from testsuite.ui.exception import ItemNotPresentException
1414

@@ -254,36 +254,44 @@ def is_checked(self):
254254
return self.__element__().get_attribute("checked") == "true"
255255

256256

257-
class PolicySection(Widget):
257+
class PolicySection(View):
258258
"""Widget representing Policies table section"""
259259

260260
ROOT = "//div[@class='PoliciesWidget']/section"
261261
POLICY_LIST = ".//ul/li"
262262
REGISTRY_ITEMS_LOCATOR = "//ul/li/article/h3"
263263
REGISTRY_ITEM_LOCATOR = "//ul/li/article/h3[text()='{}']"
264264
CHAIN_ITEMS_LOCATOR = ".//ul/li//article/h3"
265-
CHAIN_ITEM_LOCATOR = "//ul/li//article/h3[text()='{}']"
266-
ADD_POLICY_LOC = ".//button[normalize-space(.)='Add policy']"
265+
CHAIN_ITEM_LOCATOR = ".//ul/li//article/h3[text()='{}']"
266+
ADD_POLICY_LOCATOR = ".//button[normalize-space(.)='Add policy']"
267+
add_policy_modal = Modal(locator="//div[contains(@class, 'pf-c-modal-box')]")
267268

269+
# pylint: disable=super-init-not-called, non-parent-init-called
268270
def __init__(self, parent=None, logger=None):
269271
Widget.__init__(self, parent, logger=logger)
270272

271273
@property
272274
def items(self):
273-
"""Returns a list of all policy registry items as strings."""
275+
"""Returns a list of all policy registry items from policy chain as strings."""
274276
return [self.browser.text(el) for el in self.browser.elements(self.CHAIN_ITEMS_LOCATOR, parent=self)]
275277

276278
@property
277279
def registry_items(self):
278280
"""Returns a list of all policy registry items as strings."""
279-
return [self.browser.text(el) for el in self.browser.elements(self.REGISTRY_ITEMS_LOCATOR)]
281+
displayed = self.add_policy_modal.is_displayed
282+
if not displayed:
283+
self.open_policy_registry()
284+
result = [self.browser.text(el) for el in self.browser.elements(self.REGISTRY_ITEMS_LOCATOR)]
285+
if not displayed:
286+
self.close_policy_registry()
287+
return result
280288

281289
@property
282290
def is_policy_registry_displayed(self):
283291
"""Check if policy registry list is displayed.
284292
:return: True if displayed, False otherwise.
285293
"""
286-
return self.browser.is_displayed(self.ADD_POLICY_LOC)
294+
return self.add_policy_modal.is_displayed
287295

288296
@property
289297
def first_policy(self):
@@ -297,15 +305,15 @@ def add_policy(self, policy_name):
297305
"""Opens the Policy registry list and adds a policy by its name.
298306
:param policy_name: Name of the policy to be added
299307
"""
300-
self.browser.click(self.ADD_POLICY_LOC, parent=self)
308+
self.browser.click(self.ADD_POLICY_LOCATOR, parent=self)
301309
self.add_item(policy_name)
302310

303311
def edit_policy(self, policy_name):
304312
"""
305313
:param policy_name:
306314
"""
307315
if self.has_item(policy_name):
308-
self.item_select(policy_name)
316+
self.browser.click(self.item_element(policy_name))
309317
else:
310318
raise ItemNotPresentException("Item {!r} not found.".format(policy_name))
311319

@@ -323,7 +331,7 @@ def drag_and_drop_policy(self, source, destination):
323331
ac.perform()
324332

325333
def has_item(self, item):
326-
"""Returns whether the items exists.
334+
"""Returns whether the items exist in policy chain.
327335
:param
328336
item: item name
329337
:return:
@@ -333,31 +341,53 @@ def has_item(self, item):
333341

334342
# pylint: disable=raise-missing-from
335343
def item_element(self, item):
336-
"""Returns a WebElement for given item name.
344+
"""Returns a WebElement for given item name from policy chain.
337345
:return WebElement
338346
"""
339347
try:
340348
return self.browser.element(self.CHAIN_ITEM_LOCATOR.format(item), parent=self)
341349
except NoSuchElementException:
342350
raise ItemNotPresentException("Item {!r} not found.".format(item))
343351

352+
# pylint: disable=raise-missing-from
353+
def registry_item_element(self, item):
354+
"""Returns a WebElement for given item name from policy registry.
355+
:return WebElement
356+
"""
357+
if not self.add_policy_modal.is_displayed:
358+
self.open_policy_registry()
359+
try:
360+
return self.browser.element(self.REGISTRY_ITEM_LOCATOR.format(item), parent=self)
361+
except NoSuchElementException:
362+
raise ItemNotPresentException("Item {!r} not found.".format(item))
363+
344364
# pylint: disable=raise-missing-from
345365
def add_item(self, item):
346366
"""Add policy from policy registry"""
347367
self.logger.info("Selecting %r", item)
348368
if item not in self.registry_items:
349369
raise ItemNotPresentException('Item "{item}" of policy is not present'.format(item=item))
350-
self.browser.click(self.item_element(item))
370+
self.browser.click(self.registry_item_element(item))
351371

352372
def item_select(self, item):
353-
"""Opens the Policy registry and selects the desired policy.
373+
"""Opens the policy registry and selects the desired policy.
354374
:param
355375
item: Item to be selected
356376
"""
357377
self.logger.info("Selecting %r", item)
358378
if not self.has_item(item):
359379
raise ItemNotPresentException('Item "{item}" of policy is not present'.format(item=item))
360-
self.browser.click(self.item_element(item))
380+
self.browser.click(self.registry_item_element(item))
381+
382+
def open_policy_registry(self):
383+
"""Opens the policy registry if not already opened"""
384+
if not self.is_policy_registry_displayed:
385+
self.browser.click(self.ADD_POLICY_LOCATOR, parent=self)
386+
387+
def close_policy_registry(self):
388+
"""Closes the policy registry if not already closed"""
389+
if self.is_policy_registry_displayed:
390+
self.add_policy_modal.close()
361391

362392

363393
class APIDocsSelect(Select):

0 commit comments

Comments
 (0)