Skip to content

Commit a3385e8

Browse files
committed
nextcloud_tests.py: Fix config checks for NC32
1 parent 5b4d0ce commit a3385e8

File tree

1 file changed

+96
-59
lines changed

1 file changed

+96
-59
lines changed

tests/nextcloud_tests.py

Lines changed: 96 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -182,65 +182,10 @@ def test_nextcloud(IP: str, nc_port: str, driver: WebDriver, skip_release_check:
182182
test.new("settings config")
183183
wait = WebDriverWait(driver, 60 * wait_multiplier * 3)
184184
try:
185-
wait.until(VisibilityOfElementLocatedByAnyLocator([(By.CSS_SELECTOR, "#security-warning-state-ok"),
186-
(By.CSS_SELECTOR, "#security-warning-state-warning"),
187-
(By.CSS_SELECTOR, "#security-warning-state-error"),
188-
(By.CSS_SELECTOR, "#security-warning-state-failure")]))
189-
190-
element_ok = driver.find_element(By.ID, "security-warning-state-ok")
191-
element_warn = driver.find_element(By.ID, "security-warning-state-warning")
192-
193-
if element_warn.is_displayed():
194-
195-
warnings = driver.find_elements(By.CSS_SELECTOR, "#postsetupchecks > .warnings > li")
196-
for warning in warnings:
197-
if re.match(r'.*Server has no maintenance window start time configured.*', warning.text) \
198-
or re.match(r'.*Server has no maintenance window start time configured.*', warning.text):
199-
continue
200-
elif re.match(r'.*Could not check for JavaScript support.*', warning.text):
201-
continue
202-
# TODO: Solve redis error logs at the source
203-
elif re.match(r'.*\d+ errors? in the logs since.*', warning.text):
204-
continue
205-
else:
206-
raise ConfigTestFailure(f"WARN: {warning.text}")
207-
208-
if driver.find_element(By.CSS_SELECTOR, "#postsetupchecks > .errors").is_displayed():
209-
try:
210-
first_error = driver.find_element(By.CSS_SELECTOR, "#postsetupchecks > .errors > li")
211-
except NoSuchElementException:
212-
first_error = None
213-
raise ConfigTestFailure(f"ERROR: {first_error.text if first_error is not None else 'unexpected error'}")
214-
215-
infos = driver.find_elements(By.CSS_SELECTOR, "#postsetupchecks > .info > li")
216-
for info in infos:
217-
if re.match(r'.*Your installation has no default phone region set.*', info.text) \
218-
or re.match(r'The PHP module "imagick" is not enabled', info.text) \
219-
or re.match(r'The PHP module "imagick" in this instance has no SVG support.*', info.text) \
220-
or re.match(r'\d+ warning in the logs since.*', info.text):
221-
continue
222-
else:
223-
print(f'INFO: {info.text}')
224-
php_modules = info.find_elements(By.CSS_SELECTOR, "li")
225-
if len(php_modules) != 1:
226-
raise ConfigTestFailure(f"Could not find the list of php modules within the info message "
227-
f"'{infos[0].text}'")
228-
if php_modules[0].text != "imagick":
229-
raise ConfigTestFailure("The list of php_modules does not equal [imagick]")
230-
231-
elif not element_ok.is_displayed():
232-
errors = driver.find_elements(By.CSS_SELECTOR, "#postsetupchecks > .errors > li")
233-
for error in errors:
234-
print(f'ERROR: {error.text}')
235-
raise ConfigTestFailure("Neither the warnings nor the ok status is displayed "
236-
"(so there are probably errors or the page is broken)")
237-
238-
test.check(True)
239-
240-
except Exception as e:
241-
242-
print(driver.find_element(By.CSS_SELECTOR, "#security-warning").get_attribute("innerHTML"))
243-
test.check(e)
185+
driver.find_element(By.CSS_SELECTOR, "#security-warning.settings-section")
186+
settings_config_check(wait, test)
187+
except:
188+
settings_config_check_pre32(wait, test)
244189

245190
close_first_run_wizard(driver, wait_multiplier)
246191

@@ -321,6 +266,98 @@ def test_nextcloud(IP: str, nc_port: str, driver: WebDriver, skip_release_check:
321266
except Exception as e:
322267
test.check(e)
323268

269+
def settings_config_check_warnings(warnings):
270+
for warning in warnings:
271+
if re.match(r'.*Server has no maintenance window start time configured.*', warning.text) \
272+
or re.match(r'.*Server has no maintenance window start time configured.*', warning.text):
273+
continue
274+
elif re.match(r'.*Could not check for JavaScript support.*', warning.text):
275+
continue
276+
# TODO: Solve redis error logs at the source
277+
elif re.match(r'.*\d+ errors? in the logs since.*', warning.text):
278+
continue
279+
else:
280+
raise ConfigTestFailure(f"WARN: {warning.text}")
281+
282+
def settings_config_check_infos(infos):
283+
for info in infos:
284+
if re.match(r'.*Your installation has no default phone region set.*', info.text) \
285+
or re.match(r'The PHP module "imagick" is not enabled', info.text) \
286+
or re.match(r'The PHP module "imagick" in this instance has no SVG support.*', info.text) \
287+
or re.match(r'\d+ warnings? in the logs since.*', info.text):
288+
continue
289+
else:
290+
print(f'INFO: {info.text}')
291+
php_modules = info.find_elements(By.CSS_SELECTOR, "li")
292+
if len(php_modules) != 1:
293+
raise ConfigTestFailure(f"Could not find the list of php modules within the info message "
294+
f"'{infos[0].text}'")
295+
if php_modules[0].text != "imagick":
296+
raise ConfigTestFailure("The list of php_modules does not equal [imagick]")
297+
298+
299+
def settings_config_check_errors(errors):
300+
if len(errors) == 0:
301+
return
302+
for error in errors:
303+
print(f'ERROR: {error.text}')
304+
raise ConfigTestFailure("Neither the warnings nor the ok status is displayed "
305+
"(so there are probably errors or the page is broken)")
306+
307+
308+
def settings_config_check(wait, test):
309+
try:
310+
wait.until_not(VisibilityOfElementLocatedByAnyLocator([(By.CSS_SELECTOR, "#security-warning .loading-icon")]))
311+
warnings = driver.find_elements(By.CSS_SELECTOR, "#security-warning li.settings-setup-checks-item--warning .settings-setup-checks-item__description")
312+
settings_config_check_warnings(warnings)
313+
infos = driver.find_elements(By.CSS_SELECTOR, "#security-warning li.settings-setup-checks-item--info .settings-setup-checks-item__description")
314+
settings_config_check_infos(infos)
315+
errors = driver.find_elements(By.CSS_SELECTOR, "#security-warning li.settings-setup-checks-item--error .settings-setup-checks-item__description")
316+
settings_config_check_errors(errors)
317+
318+
test.check(True)
319+
except Exception as e:
320+
print(driver.find_element(By.CSS_SELECTOR, "#security-warning").get_attribute("innerHTML"))
321+
test.check(e)
322+
323+
324+
def settings_config_check_pre32(wait, test):
325+
try:
326+
wait.until(VisibilityOfElementLocatedByAnyLocator([(By.CSS_SELECTOR, "#security-warning-state-ok"),
327+
(By.CSS_SELECTOR, "#security-warning-state-warning"),
328+
(By.CSS_SELECTOR, "#security-warning-state-error"),
329+
(By.CSS_SELECTOR, "#security-warning-state-failure")]))
330+
331+
element_ok = driver.find_element(By.ID, "security-warning-state-ok")
332+
element_warn = driver.find_element(By.ID, "security-warning-state-warning")
333+
334+
if element_warn.is_displayed():
335+
336+
warnings = driver.find_elements(By.CSS_SELECTOR, "#postsetupchecks > .warnings > li")
337+
settings_config_check_warnings(warnings)
338+
339+
if driver.find_element(By.CSS_SELECTOR, "#postsetupchecks > .errors").is_displayed():
340+
try:
341+
first_error = driver.find_element(By.CSS_SELECTOR, "#postsetupchecks > .errors > li")
342+
except NoSuchElementException:
343+
first_error = None
344+
raise ConfigTestFailure(f"ERROR: {first_error.text if first_error is not None else 'unexpected error'}")
345+
346+
infos = driver.find_elements(By.CSS_SELECTOR, "#postsetupchecks > .info > li")
347+
settings_config_check_infos(infos)
348+
349+
350+
elif not element_ok.is_displayed():
351+
errors = driver.find_elements(By.CSS_SELECTOR, "#postsetupchecks > .errors > li")
352+
settings_config_check_errors(errors)
353+
354+
test.check(True)
355+
356+
except Exception as e:
357+
358+
print(driver.find_element(By.CSS_SELECTOR, "#security-warning").get_attribute("innerHTML"))
359+
test.check(e)
360+
324361

325362
if __name__ == "__main__":
326363
signal.signal(signal.SIGINT, signal_handler)

0 commit comments

Comments
 (0)