wbcore 2.2.1__py2.py3-none-any.whl → 2.2.4__py2.py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- wbcore/contrib/agenda/locale/de/LC_MESSAGES/django.po +113 -0
- wbcore/contrib/agenda/static/agenda/markdown/documentation/building.md +11 -0
- wbcore/contrib/agenda/static/agenda/markdown/documentation/conferenceroom.md +20 -0
- wbcore/contrib/authentication/fixtures/authentication.json +62 -0
- wbcore/contrib/authentication/locale/de/LC_MESSAGES/django.po +610 -0
- wbcore/contrib/authentication/templates/activate_confirm.html +12 -0
- wbcore/contrib/authentication/templates/base.html +135 -0
- wbcore/contrib/authentication/templates/email_base_template.html +335 -0
- wbcore/contrib/authentication/templates/password_reset_done.html +13 -0
- wbcore/contrib/authentication/templates/password_reset_email.html +11 -0
- wbcore/contrib/authentication/templates/password_reset_email_html.html +43 -0
- wbcore/contrib/authentication/templates/password_reset_form.html +23 -0
- wbcore/contrib/authentication/templates/password_reset_sent.html +11 -0
- wbcore/contrib/authentication/templates/reset_password.html +15 -0
- wbcore/contrib/authentication/templates/user_registration_email.html +37 -0
- wbcore/contrib/color/admin.py +28 -0
- wbcore/contrib/color/apps.py +5 -0
- wbcore/contrib/color/enums.py +17 -0
- wbcore/contrib/color/factories.py +10 -0
- wbcore/contrib/color/fields.py +29 -0
- wbcore/contrib/color/forms.py +13 -0
- wbcore/contrib/color/models.py +62 -0
- wbcore/contrib/color/tests/conftest.py +10 -0
- wbcore/contrib/color/tests/test_color_models.py +61 -0
- wbcore/contrib/color/tests/test_fields.py +25 -0
- wbcore/contrib/currency/fixtures/currency.yaml +1014 -0
- wbcore/contrib/currency/fixtures/currency_fx_rate.yaml +73585 -0
- wbcore/contrib/directory/fixtures/directory.json +3924 -0
- wbcore/contrib/directory/locale/de/LC_MESSAGES/django.po +1686 -0
- wbcore/contrib/directory/static/directory/markdown/documentation/address.md +38 -0
- wbcore/contrib/directory/static/directory/markdown/documentation/banking.md +54 -0
- wbcore/contrib/directory/static/directory/markdown/documentation/bankingentry.md +38 -0
- wbcore/contrib/directory/static/directory/markdown/documentation/clientmanagerrelationship.md +42 -0
- wbcore/contrib/directory/static/directory/markdown/documentation/company.md +52 -0
- wbcore/contrib/directory/static/directory/markdown/documentation/companytype.md +2 -0
- wbcore/contrib/directory/static/directory/markdown/documentation/customerstatus.md +2 -0
- wbcore/contrib/directory/static/directory/markdown/documentation/email.md +20 -0
- wbcore/contrib/directory/static/directory/markdown/documentation/employeecompany.md +34 -0
- wbcore/contrib/directory/static/directory/markdown/documentation/employerperson.md +43 -0
- wbcore/contrib/directory/static/directory/markdown/documentation/person.md +61 -0
- wbcore/contrib/directory/static/directory/markdown/documentation/position.md +2 -0
- wbcore/contrib/directory/static/directory/markdown/documentation/relationshiptype.md +2 -0
- wbcore/contrib/directory/static/directory/markdown/documentation/socialmedia.md +23 -0
- wbcore/contrib/directory/static/directory/markdown/documentation/specialization.md +2 -0
- wbcore/contrib/directory/static/directory/markdown/documentation/systememployee.md +31 -0
- wbcore/contrib/directory/static/directory/markdown/documentation/telephone.md +23 -0
- wbcore/contrib/directory/static/directory/markdown/documentation/telephonesearch.md +26 -0
- wbcore/contrib/directory/static/directory/markdown/documentation/userisclient.md +14 -0
- wbcore/contrib/directory/static/directory/markdown/documentation/userismanager.md +28 -0
- wbcore/contrib/directory/static/directory/markdown/documentation/website.md +20 -0
- wbcore/contrib/documents/fixtures/docments.json +135 -0
- wbcore/contrib/documents/locale/de/LC_MESSAGES/django.po +272 -0
- wbcore/contrib/documents/static/documents/markdown/documentation/document_types.md +21 -0
- wbcore/contrib/documents/static/documents/markdown/documentation/documents.md +18 -0
- wbcore/contrib/documents/static/documents/markdown/documentation/shareablelink.md +28 -0
- wbcore/contrib/documents/static/documents/markdown/documentation/shareablelinkaccess.md +20 -0
- wbcore/contrib/documents/tests/conftest.py +30 -0
- wbcore/contrib/documents/tests/test_models.py +144 -0
- wbcore/contrib/example_app/fixtures/example_app.json +7425 -0
- wbcore/contrib/example_app/tests/test_models/test_event.py +87 -0
- wbcore/contrib/example_app/tests/test_models/test_match.py +210 -0
- wbcore/contrib/example_app/tests/test_models/test_others.py +159 -0
- wbcore/contrib/example_app/tests/test_serializers/test_league_serializer.py +34 -0
- wbcore/contrib/example_app/tests/test_serializers/test_match_serializer.py +134 -0
- wbcore/contrib/example_app/tests/test_serializers/test_role_serializer.py +13 -0
- wbcore/contrib/example_app/tests/test_serializers/test_sport_serializer.py +14 -0
- wbcore/contrib/example_app/tests/test_serializers/test_stadium_serializer.py +14 -0
- wbcore/contrib/example_app/tests/test_serializers/test_team_result_serializer.py +30 -0
- wbcore/contrib/example_app/tests/test_serializers/test_team_serializer.py +70 -0
- wbcore/contrib/example_app/tests/test_viewsets/test_event_viewset.py +162 -0
- wbcore/contrib/example_app/tests/test_viewsets/test_league_viewset.py +84 -0
- wbcore/contrib/example_app/tests/test_viewsets/test_match_viewset.py +65 -0
- wbcore/contrib/example_app/tests/test_viewsets/test_person_viewset.py +166 -0
- wbcore/contrib/example_app/tests/test_viewsets/test_role_viewset.py +75 -0
- wbcore/contrib/example_app/tests/test_viewsets/test_sport_viewset.py +75 -0
- wbcore/contrib/example_app/tests/test_viewsets/test_stadium_viewset.py +75 -0
- wbcore/contrib/example_app/tests/test_viewsets/test_team_viewset.py +92 -0
- wbcore/contrib/example_app/tests/test_viewsets/test_teamresult_viewset.py +58 -0
- wbcore/contrib/example_app/tests/test_viewsets/test_utils_viewsets.py +124 -0
- wbcore/contrib/geography/fixtures/geography.json +13454 -0
- wbcore/contrib/geography/static/geography/markdown/documentation/geography.md +16 -0
- wbcore/contrib/guardian/apps.py +6 -0
- wbcore/contrib/guardian/configurations.py +3 -0
- wbcore/contrib/guardian/filters.py +21 -0
- wbcore/contrib/guardian/tasks.py +10 -0
- wbcore/contrib/guardian/urls.py +12 -0
- wbcore/contrib/guardian/utils.py +124 -0
- wbcore/contrib/io/fixtures/io.json +145 -0
- wbcore/contrib/io/locale/de/LC_MESSAGES/django.po +52 -0
- wbcore/contrib/notifications/locale/de/LC_MESSAGES/django.po +60 -0
- wbcore/contrib/notifications/static/notifications/service-worker.js +1 -0
- wbcore/contrib/notifications/templates/notifications/notification_template.html +43 -0
- wbcore/contrib/notifications/viewsets/configs/notification_types.py +27 -0
- wbcore/contrib/notifications/viewsets/configs/notifications.py +85 -0
- wbcore/contrib/workflow/fixtures/workflow.json +612 -0
- wbcore/contrib/workflow/locale/de/LC_MESSAGES/django.po +1289 -0
- wbcore/contrib/workflow/static/workflow/markdown/documentation/assignedprocessstep.md +33 -0
- wbcore/contrib/workflow/static/workflow/markdown/documentation/condition.md +24 -0
- wbcore/contrib/workflow/static/workflow/markdown/documentation/decisionstep.md +30 -0
- wbcore/contrib/workflow/static/workflow/markdown/documentation/emailstep.md +45 -0
- wbcore/contrib/workflow/static/workflow/markdown/documentation/finishstep.md +33 -0
- wbcore/contrib/workflow/static/workflow/markdown/documentation/joinstep.md +33 -0
- wbcore/contrib/workflow/static/workflow/markdown/documentation/process.md +33 -0
- wbcore/contrib/workflow/static/workflow/markdown/documentation/processstep.md +51 -0
- wbcore/contrib/workflow/static/workflow/markdown/documentation/scriptstep.md +33 -0
- wbcore/contrib/workflow/static/workflow/markdown/documentation/splitstep.md +30 -0
- wbcore/contrib/workflow/static/workflow/markdown/documentation/startstep.md +27 -0
- wbcore/contrib/workflow/static/workflow/markdown/documentation/transition.md +27 -0
- wbcore/contrib/workflow/static/workflow/markdown/documentation/userstep.md +42 -0
- wbcore/contrib/workflow/static/workflow/markdown/documentation/workflow.md +32 -0
- wbcore/contrib/workflow/templates/Test_Templates.txt +25 -0
- wbcore/contrib/workflow/tests/test_models/step/test_decision_step.py +79 -0
- wbcore/contrib/workflow/tests/test_models/step/test_email_step.py +45 -0
- wbcore/contrib/workflow/tests/test_models/step/test_finish_step.py +105 -0
- wbcore/contrib/workflow/tests/test_models/step/test_join_step.py +127 -0
- wbcore/contrib/workflow/tests/test_models/step/test_script_step.py +24 -0
- wbcore/contrib/workflow/tests/test_models/step/test_split_step.py +49 -0
- wbcore/contrib/workflow/tests/test_models/step/test_step.py +621 -0
- wbcore/contrib/workflow/tests/test_models/step/test_user_step.py +225 -0
- wbcore/contrib/workflow/tests/test_models/test_condition.py +103 -0
- wbcore/contrib/workflow/tests/test_models/test_data.py +134 -0
- wbcore/contrib/workflow/tests/test_models/test_process.py +98 -0
- wbcore/contrib/workflow/tests/test_models/test_transition.py +128 -0
- wbcore/contrib/workflow/tests/test_models/test_workflow.py +358 -0
- wbcore/locale/de/LC_MESSAGES/django.po +667 -0
- wbcore/templates/errors/404.html +134 -0
- wbcore/templates/errors/500.html +138 -0
- wbcore/templates/errors/503.html +132 -0
- wbcore/templates/errors/custom.html +132 -0
- wbcore/templates/forms.py +0 -0
- wbcore/templates/notifications/email_template.html +43 -0
- wbcore/templates/wbcore/admin/change_list.html +8 -0
- wbcore/templates/wbcore/admin/csv_form.html +15 -0
- wbcore/templates/wbcore/dynamic_color_array.html +29 -0
- wbcore/templates/wbcore/email_base_template.html +335 -0
- wbcore/templates/wbcore/email_notification_template.html +10 -0
- wbcore/templates/wbcore/frontend.html +51 -0
- wbcore/test/e2e_helpers_methods/e2e_checks.py +121 -0
- wbcore/test/e2e_helpers_methods/e2e_helper_methods.py +395 -0
- wbcore/tests/test_permissions/test_backend.py +29 -0
- {wbcore-2.2.1.dist-info → wbcore-2.2.4.dist-info}/METADATA +1 -1
- {wbcore-2.2.1.dist-info → wbcore-2.2.4.dist-info}/RECORD +143 -3
- {wbcore-2.2.1.dist-info → wbcore-2.2.4.dist-info}/WHEEL +0 -0
|
@@ -0,0 +1,395 @@
|
|
|
1
|
+
from pytest_django.live_server_helper import LiveServer
|
|
2
|
+
from selenium.common.exceptions import TimeoutException
|
|
3
|
+
from selenium.webdriver.common.action_chains import ActionChains
|
|
4
|
+
from selenium.webdriver.common.by import By
|
|
5
|
+
from selenium.webdriver.remote.webdriver import WebDriver
|
|
6
|
+
from selenium.webdriver.remote.webelement import WebElement
|
|
7
|
+
from selenium.webdriver.support import expected_conditions as EC
|
|
8
|
+
from selenium.webdriver.support.wait import WebDriverWait
|
|
9
|
+
from wbcore import serializers as wb_serializers
|
|
10
|
+
|
|
11
|
+
WAIT_TIME_SEC = 30
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def login(driver: WebDriver, user_mail: str | None, user_password: str | None):
|
|
15
|
+
"""Automatically logs in a user into the workbench.
|
|
16
|
+
|
|
17
|
+
Args:
|
|
18
|
+
driver (WebDriver): Selenium webdriver.
|
|
19
|
+
user_mail (str | None): The users email.
|
|
20
|
+
user_password (str | None): The users password
|
|
21
|
+
"""
|
|
22
|
+
write_text(driver, "//input[@placeholder='E-Mail']", user_mail)
|
|
23
|
+
write_text(driver, "//input[@placeholder='Password']", user_password)
|
|
24
|
+
click_element_by_path(driver, "//button[@label='Login']")
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def set_up(driver: WebDriver, server: LiveServer, user_mail: str, user_password: str):
|
|
28
|
+
"""Used for setting up the test environment and needs to be called before executing the test logic.
|
|
29
|
+
|
|
30
|
+
Args:
|
|
31
|
+
driver (WebDriver): Selenium webdriver.
|
|
32
|
+
server (LiveServer): Live server.
|
|
33
|
+
user_mail (str): The email of the user used for authentication.
|
|
34
|
+
user_password (str): The password of the user used for authentication.
|
|
35
|
+
"""
|
|
36
|
+
driver.get(server.url)
|
|
37
|
+
driver.set_window_size(1920, 1080)
|
|
38
|
+
login(driver, user_mail, user_password)
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def open_menu_item(driver: WebDriver, *menu_items, perform_mouse_move=False):
|
|
42
|
+
"""Automatically opens a menu item of the CRM.
|
|
43
|
+
|
|
44
|
+
Args:
|
|
45
|
+
driver (WebDriver): The Selenium webdriver.
|
|
46
|
+
*menu_items: The path to the menu item you want to open (e.g. for Person you would have to insert "CRM", "Persons" to get to the person list.)
|
|
47
|
+
perform_mouse_move (bool, optional): Should the mouse move after opening the correct menu item. This can be helpful, when the navigation bar block certain things. When moving the mouse away from the navigation bar, the bar will collapse. Defaults to False.
|
|
48
|
+
"""
|
|
49
|
+
actions = ActionChains(driver, 1000)
|
|
50
|
+
ele = find_element(driver, "//div[@title='Navigation']")
|
|
51
|
+
actions.move_to_element(ele).perform()
|
|
52
|
+
|
|
53
|
+
for menu_item in menu_items:
|
|
54
|
+
click_element_by_path(driver, f"//div[@title='{menu_item}']")
|
|
55
|
+
|
|
56
|
+
if perform_mouse_move:
|
|
57
|
+
window_width = (driver.get_window_size().get("width")) / 1.75
|
|
58
|
+
actions.move_by_offset(window_width, 0).perform()
|
|
59
|
+
actions.click()
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
def open_create_instance(driver: WebDriver, *menu_items: str, create_instance_title: str):
|
|
63
|
+
"""Opens a create instance widget
|
|
64
|
+
|
|
65
|
+
Args:
|
|
66
|
+
driver (WebDriver): The Selenium webdriver.
|
|
67
|
+
*menu_items: The path to the menu item you want to open (e.g. for Person you would have to insert "CRM", "Persons" to get to the person list.)
|
|
68
|
+
create_instance_title (str): The title of the create instance button (e.g. Create Activity)
|
|
69
|
+
"""
|
|
70
|
+
actions = ActionChains(driver, 1000)
|
|
71
|
+
open_menu_item(driver, *menu_items)
|
|
72
|
+
click_element_by_path(driver, f"//span[@title='{create_instance_title}']")
|
|
73
|
+
window_width = (driver.get_window_size().get("width")) / 2
|
|
74
|
+
actions.move_by_offset(window_width, 0).perform()
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
def write_text(driver: WebDriver, xpath: str, text: str) -> WebElement:
|
|
78
|
+
"""Writes a given text into an element. Requires the element to be writable.
|
|
79
|
+
|
|
80
|
+
Args:
|
|
81
|
+
driver (WebDriver): Selenium webdriver.
|
|
82
|
+
xpath (str): The xpath leading to the element.
|
|
83
|
+
text (str): The desired text.
|
|
84
|
+
|
|
85
|
+
Returns:
|
|
86
|
+
WebElement: The element in which it was written.
|
|
87
|
+
"""
|
|
88
|
+
element = find_element(driver, xpath)
|
|
89
|
+
element.send_keys(text)
|
|
90
|
+
|
|
91
|
+
return element
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
def approve_form(driver: WebDriver, element: WebElement):
|
|
95
|
+
click_button_by_label(driver, "Approve")
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
# ====================================================================================================================================== #
|
|
99
|
+
# ========================================================== FINDING ELEMENTS ========================================================== #
|
|
100
|
+
# ====================================================================================================================================== #
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
def find_element(driver: WebDriver, xpath: str, wait_sec=WAIT_TIME_SEC) -> WebElement | None:
|
|
104
|
+
"""Find a single web element on the current page.
|
|
105
|
+
|
|
106
|
+
Args:
|
|
107
|
+
driver (WebDriver): Selenium webdriver.
|
|
108
|
+
xpath (str): The xpath used to look up the element.
|
|
109
|
+
wait_sec (int): the seconds the driver waits for the element to be visible.
|
|
110
|
+
|
|
111
|
+
Returns:
|
|
112
|
+
WebElement: The found element.
|
|
113
|
+
"""
|
|
114
|
+
try:
|
|
115
|
+
return WebDriverWait(driver, wait_sec).until(lambda x: x.find_element(By.XPATH, xpath))
|
|
116
|
+
except TimeoutException:
|
|
117
|
+
return None
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
def find_element_by_text(driver: WebDriver, text: str, wait_sec=WAIT_TIME_SEC) -> WebElement | None:
|
|
121
|
+
"""Find a web element based on a string.
|
|
122
|
+
|
|
123
|
+
Args:
|
|
124
|
+
driver (WebDriver): Selenium webdriver.
|
|
125
|
+
text (str): The text that appears in the element we are searching
|
|
126
|
+
|
|
127
|
+
Returns:
|
|
128
|
+
WebElement: The found element.
|
|
129
|
+
"""
|
|
130
|
+
try:
|
|
131
|
+
xpath: str = f"//*[contains(text(), '{text}')]//parent::div"
|
|
132
|
+
return WebDriverWait(driver, wait_sec).until(lambda x: x.find_element(By.XPATH, xpath))
|
|
133
|
+
except TimeoutException:
|
|
134
|
+
return None
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
# ====================================================================================================================================== #
|
|
138
|
+
# ========================================================= CLICKING ELEMENTS ========================================================== #
|
|
139
|
+
# ====================================================================================================================================== #
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
def click_element(driver: WebDriver, element: WebElement) -> None:
|
|
143
|
+
"""Click a given web element.
|
|
144
|
+
|
|
145
|
+
Args:
|
|
146
|
+
driver (WebDriver): Selenium webdriver.
|
|
147
|
+
xpath (str): The element that needs clicking.
|
|
148
|
+
"""
|
|
149
|
+
element.click()
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
def click_element_by_path(driver: WebDriver, xpath: str, wait_sec=WAIT_TIME_SEC) -> None:
|
|
153
|
+
"""Click on the item corresponding to the xpath.
|
|
154
|
+
|
|
155
|
+
Args:
|
|
156
|
+
driver (WebDriver): Selenium webdriver.
|
|
157
|
+
xpath (str): The xpath leading to the element.
|
|
158
|
+
"""
|
|
159
|
+
try:
|
|
160
|
+
WebDriverWait(driver, wait_sec).until(EC.presence_of_element_located((By.XPATH, xpath))).click()
|
|
161
|
+
except TimeoutException:
|
|
162
|
+
return []
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
def click_button_by_label(driver: WebDriver, label: str):
|
|
166
|
+
"""Clicks a button according to its label.
|
|
167
|
+
|
|
168
|
+
Args:
|
|
169
|
+
driver (WebDriver): Selenium webdriver.
|
|
170
|
+
label (str): The button label.
|
|
171
|
+
"""
|
|
172
|
+
click_element_by_path(driver, f"//button[@label='{label}']")
|
|
173
|
+
|
|
174
|
+
|
|
175
|
+
def click_new_button(driver: WebDriver):
|
|
176
|
+
"""Clicks the new button on the current page.
|
|
177
|
+
|
|
178
|
+
Args:
|
|
179
|
+
driver (WebDriver): Selenium webdriver.
|
|
180
|
+
"""
|
|
181
|
+
click_element_by_path(driver, "//button[contains(@class, 'new-button')]")
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+
def click_cancel_on_button(driver: WebDriver, button_label: str):
|
|
185
|
+
"""Clicks the cancel symbol on the button with the specified label.
|
|
186
|
+
|
|
187
|
+
Args:
|
|
188
|
+
driver (WebDriver): Selenium webdriver.
|
|
189
|
+
label (str): The button label.
|
|
190
|
+
"""
|
|
191
|
+
click_element_by_path(driver, f"//td[@title='{button_label}']//parent::tr//div//span[.='cancel']")
|
|
192
|
+
|
|
193
|
+
|
|
194
|
+
def click_close_all_widgets(driver: WebDriver):
|
|
195
|
+
"""Clicks the close all widgets button.
|
|
196
|
+
|
|
197
|
+
Args:
|
|
198
|
+
driver (WebDriver): Selenium webdriver.
|
|
199
|
+
"""
|
|
200
|
+
click_element_by_path(driver, "//button[@title='Close all widgets']")
|
|
201
|
+
|
|
202
|
+
|
|
203
|
+
# ====================================================================================================================================== #
|
|
204
|
+
# ========================================================= HANDLE FORM FIELDS ========================================================= #
|
|
205
|
+
# ====================================================================================================================================== #
|
|
206
|
+
|
|
207
|
+
|
|
208
|
+
def edit_form_fields(driver: WebDriver, serializer: wb_serializers, changes: dict[str]):
|
|
209
|
+
"""A method to edit the fields in a form.
|
|
210
|
+
|
|
211
|
+
Args:
|
|
212
|
+
driver (WebDriver): The Selenium webdriver.
|
|
213
|
+
serializer (wb_serializers): The serializer that matches the model of the form.
|
|
214
|
+
changes (dict[str]): A dict containing the changes. The dict keys should have the names of the corresponding fields (e.g. {"last_name": "Hotzenplotz"}).
|
|
215
|
+
"""
|
|
216
|
+
field_list = list(changes.keys())
|
|
217
|
+
for field in field_list:
|
|
218
|
+
if not changes.get(field):
|
|
219
|
+
continue
|
|
220
|
+
if type(serializer.fields[field]) is wb_serializers.CharField:
|
|
221
|
+
find_element(
|
|
222
|
+
driver, f"//label[contains(text(), '{serializer.fields[field].label}')]//parent::div//input"
|
|
223
|
+
).clear()
|
|
224
|
+
write_text(
|
|
225
|
+
driver,
|
|
226
|
+
f"//label[contains(text(), '{serializer.fields[field].label}')]//parent::div//input",
|
|
227
|
+
changes[field],
|
|
228
|
+
)
|
|
229
|
+
elif type(serializer.fields[field]) is wb_serializers.ChoiceField:
|
|
230
|
+
click_element_by_path(
|
|
231
|
+
driver,
|
|
232
|
+
f"//label[contains(text(), '{serializer.fields[field].label}')]//parent::div//span[text()='expand_more']",
|
|
233
|
+
)
|
|
234
|
+
click_element_by_path(driver, f"//div[contains(text(),'{changes[field]}')]")
|
|
235
|
+
elif type(serializer.fields[field]) is wb_serializers.PrimaryKeyRelatedField:
|
|
236
|
+
click_element_by_path(
|
|
237
|
+
driver,
|
|
238
|
+
f"//label[contains(text(), '{serializer.fields[field].label}')]//parent::div//span[text()='expand_more']",
|
|
239
|
+
)
|
|
240
|
+
click_element_by_path(driver, f"//li[contains(text(),'{changes[field]}')]")
|
|
241
|
+
|
|
242
|
+
|
|
243
|
+
def fill_out_form_fields(driver: WebDriver, serializer: wb_serializers, field_list: list[str], entity):
|
|
244
|
+
"""A method to fill out the fields in a form.
|
|
245
|
+
|
|
246
|
+
Args:
|
|
247
|
+
driver (WebDriver): The Selenium webdriver.
|
|
248
|
+
serializer (wb_serializers): The serializer that matches the model of the form.
|
|
249
|
+
field_list (list[str]): A list of the field names to be changed.
|
|
250
|
+
entity (_type_): An entity on which the changes to the form are based. The entity should be created via the corresponding factory. (The entity should be created by using the Factory build method: e.g. PersonFactory.build())
|
|
251
|
+
"""
|
|
252
|
+
for field in field_list:
|
|
253
|
+
if type(serializer.fields[field]) in [wb_serializers.CharField, wb_serializers.IntegerField]:
|
|
254
|
+
write_text(
|
|
255
|
+
driver,
|
|
256
|
+
f"//label[contains(text(), '{serializer.fields[field].label}')]//parent::div//input",
|
|
257
|
+
getattr(entity, field),
|
|
258
|
+
)
|
|
259
|
+
elif type(serializer.fields[field]) is wb_serializers.ChoiceField:
|
|
260
|
+
click_element_by_path(
|
|
261
|
+
driver,
|
|
262
|
+
f"//label[contains(text(), '{serializer.fields[field].label}')]//parent::div//span[text()='expand_more']",
|
|
263
|
+
)
|
|
264
|
+
click_element_by_path(driver, f"//div[contains(text(), '{getattr(entity, field)}')]")
|
|
265
|
+
elif type(serializer.fields[field]) is wb_serializers.PrimaryKeyRelatedField:
|
|
266
|
+
click_element_by_path(
|
|
267
|
+
driver,
|
|
268
|
+
f"//label[contains(text(), '{serializer.fields[field].label}')]//parent::div//span[text()='expand_more']",
|
|
269
|
+
)
|
|
270
|
+
click_element_by_path(driver, f"//li[contains(text(), '{getattr(entity, field)}')]")
|
|
271
|
+
elif type(serializer.fields[field]) is wb_serializers.BooleanField:
|
|
272
|
+
click_element_by_path(
|
|
273
|
+
driver,
|
|
274
|
+
f"//label[contains(text(), '{serializer.fields[field].label}')]//parent::div//div//span[text()='{'Yes' if {getattr(entity, field)} else 'No'}']",
|
|
275
|
+
)
|
|
276
|
+
|
|
277
|
+
|
|
278
|
+
# ====================================================================================================================================== #
|
|
279
|
+
# ======================================================== HANDLE LIST INSTANCES ======================================================= #
|
|
280
|
+
# ====================================================================================================================================== #
|
|
281
|
+
|
|
282
|
+
|
|
283
|
+
def edit_list_instance(
|
|
284
|
+
driver: WebDriver,
|
|
285
|
+
actions,
|
|
286
|
+
list_name: str,
|
|
287
|
+
serializer: wb_serializers.ModelSerializer,
|
|
288
|
+
new_inputs: dict,
|
|
289
|
+
):
|
|
290
|
+
"""Edits a list instance.
|
|
291
|
+
|
|
292
|
+
Args:
|
|
293
|
+
driver (WebDriver): The Selenium webdriver.
|
|
294
|
+
actions (_type_): The selenium action chains.
|
|
295
|
+
list_name (str): The name of the list (e.g.: Persons)
|
|
296
|
+
serializer (wb_serializers.ModelSerializer): The model serializer that matches the lists model.
|
|
297
|
+
new_inputs (dict): A dict containing changes. The dict keys should have the names of the corresponding fields (e.g. {"last_name": "Hotzenplotz"}).
|
|
298
|
+
"""
|
|
299
|
+
list_element = find_element(driver, f"//div[text()='{list_name}']")
|
|
300
|
+
actions.double_click(list_element).perform()
|
|
301
|
+
if unlock_button := find_element(driver, "//button[@label='Unlock']"):
|
|
302
|
+
click_element(driver, unlock_button)
|
|
303
|
+
edit_form_fields(driver, serializer, new_inputs)
|
|
304
|
+
click_element_by_path(driver, "//button[@label='Save and close']")
|
|
305
|
+
|
|
306
|
+
|
|
307
|
+
def delete_list_entry(driver: WebDriver, actions: ActionChains, title: str):
|
|
308
|
+
"""Deletes a list entry. Requires that you are already in the correct list view.
|
|
309
|
+
|
|
310
|
+
Args:
|
|
311
|
+
driver (WebDriver): The Selenium webdriver.
|
|
312
|
+
actions (ActionChains): The selenium action chains.
|
|
313
|
+
title (str): The title of the list element that shall be deleted.
|
|
314
|
+
"""
|
|
315
|
+
list_element = find_element(driver, f"//div[text()='{title}']")
|
|
316
|
+
actions.context_click(list_element).perform()
|
|
317
|
+
click_element_by_path(driver, "//span[text()='Delete instance']")
|
|
318
|
+
click_element_by_path(driver, "//button[@label='Confirm']")
|
|
319
|
+
|
|
320
|
+
|
|
321
|
+
# ====================================================================================================================================== #
|
|
322
|
+
# =========================================================== HANDLE FILTERS =========================================================== #
|
|
323
|
+
# ====================================================================================================================================== #
|
|
324
|
+
|
|
325
|
+
|
|
326
|
+
def navigate_to_filter(driver: WebDriver, *menu_items):
|
|
327
|
+
"""Navigates to a specified list instance and opens the filter menu there.
|
|
328
|
+
|
|
329
|
+
Args:
|
|
330
|
+
driver (WebDriver): Selenium webdriver
|
|
331
|
+
menu_item (str): The menu in which the filters should be open. You need to specify the whole path to the menu. E.g. ["CRM", "Persons"] to get to the CRMs persons menu.
|
|
332
|
+
"""
|
|
333
|
+
actions = ActionChains(driver, 1000)
|
|
334
|
+
open_menu_item(driver, *menu_items)
|
|
335
|
+
# we need to move the mouse away from the side bar, so that the side bar closes.
|
|
336
|
+
window_width = (driver.get_window_size().get("width")) / 2
|
|
337
|
+
window_height = (driver.get_window_size().get("height")) / 2
|
|
338
|
+
actions.move_by_offset(window_width, window_height).perform()
|
|
339
|
+
|
|
340
|
+
filter_menu_btn = find_element(driver, "//button[@data-testid='control-bar-toggle-button']")
|
|
341
|
+
click_element(driver, filter_menu_btn)
|
|
342
|
+
|
|
343
|
+
|
|
344
|
+
def select_filter(driver: WebDriver, label: str, option: str):
|
|
345
|
+
"""Select a filter from the filter menu a filter by the corresponding label.
|
|
346
|
+
|
|
347
|
+
Args:
|
|
348
|
+
driver (WebDriver): Selenium webdriver
|
|
349
|
+
label (str): The filter label. (e.g. "Status" for the status - filter )
|
|
350
|
+
option (str): The filter choice. (e.g. the "Planned" choice for the status filter)
|
|
351
|
+
"""
|
|
352
|
+
no_activity_choices = find_element(
|
|
353
|
+
driver, f"//label[text()='{label}']/parent::div//parent::div/button[contains(span, 'expand_more')]"
|
|
354
|
+
)
|
|
355
|
+
click_element(driver, no_activity_choices)
|
|
356
|
+
click_element_by_path(driver, f"//li//div[text()='{option}']")
|
|
357
|
+
click_element_by_path(driver, "//button[@label='Apply']")
|
|
358
|
+
|
|
359
|
+
|
|
360
|
+
def select_async_filter(driver: WebDriver, label: str, option: str):
|
|
361
|
+
"""Select a async filter from the filter menu a filter by the corresponding label.
|
|
362
|
+
|
|
363
|
+
Args:
|
|
364
|
+
driver (WebDriver): Selenium webdriver
|
|
365
|
+
label (str): The filter label. (e.g. "Status" for the status - filter )
|
|
366
|
+
option (str): The filter choice. (e.g. the "Planned" choice for the status filter)
|
|
367
|
+
"""
|
|
368
|
+
no_activity_choices = find_element(
|
|
369
|
+
driver, f"//label[text()='{label}']/parent::div//parent::span[contains(text(), 'expand_more')]"
|
|
370
|
+
)
|
|
371
|
+
click_element(driver, no_activity_choices)
|
|
372
|
+
click_element_by_path(driver, f"//li[@title='{option}']")
|
|
373
|
+
click_element_by_path(driver, "//button[@label='Apply']")
|
|
374
|
+
|
|
375
|
+
|
|
376
|
+
def select_column_filter(driver: WebDriver, label: str, option: str):
|
|
377
|
+
"""Select a filter from a list column by the corresponding label.
|
|
378
|
+
|
|
379
|
+
Args:
|
|
380
|
+
driver (WebDriver): Selenium webdriver
|
|
381
|
+
label (str): The filter label. (e.g. "Status" for the status - filter )
|
|
382
|
+
option (str): The filter choice. (e.g. the "Planned" choice for the status filter)
|
|
383
|
+
"""
|
|
384
|
+
click_element_by_path(
|
|
385
|
+
driver,
|
|
386
|
+
f"//div[contains(@class, 'ag-cell-label-container') and ./div/span/text()='{label}']//span[contains(@class, 'ag-header-cell-menu-button')]",
|
|
387
|
+
)
|
|
388
|
+
click_element_by_path(
|
|
389
|
+
driver, "//div[@class='ag-tabs-header ag-menu-header']//span[contains(@class, 'ag-icon-filter')]"
|
|
390
|
+
)
|
|
391
|
+
click_element_by_path(
|
|
392
|
+
driver,
|
|
393
|
+
f"//div[contains(@class, 'ag-virtual-list-container')]//div[contains(@class, 'ag-virtual-list-item') and ./div/div/div/text()='{option}']//input",
|
|
394
|
+
)
|
|
395
|
+
click_element_by_path(driver, "//button[@type='submit']")
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import pytest
|
|
2
|
+
from django.contrib.auth import get_user_model
|
|
3
|
+
from django.contrib.auth.models import Permission
|
|
4
|
+
from django.contrib.contenttypes.models import ContentType
|
|
5
|
+
from faker import Faker
|
|
6
|
+
from wbcore.permissions.shortcuts import get_internal_users
|
|
7
|
+
|
|
8
|
+
User = get_user_model()
|
|
9
|
+
|
|
10
|
+
fake = Faker()
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def create_internal_user():
|
|
14
|
+
from wbcore.permissions.registry import user_registry
|
|
15
|
+
|
|
16
|
+
user = User.objects.create(is_active=True, username=fake.user_name(), email=fake.email())
|
|
17
|
+
permission = Permission.objects.get_or_create(
|
|
18
|
+
content_type=ContentType.objects.get_for_model(User), codename="is_internal_user"
|
|
19
|
+
)[0]
|
|
20
|
+
user.user_permissions.add(permission)
|
|
21
|
+
user_registry.reset_cache()
|
|
22
|
+
return user
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
@pytest.mark.django_db
|
|
26
|
+
class TestBackend:
|
|
27
|
+
def test_get_internal_users(self):
|
|
28
|
+
user = create_internal_user()
|
|
29
|
+
assert set(get_internal_users()) == {user}
|