Skip to content

Commit

Permalink
Allow expect_return_code to be a list of integers
Browse files Browse the repository at this point in the history
  • Loading branch information
Salamandar committed Jan 11, 2025
1 parent 2e9a5bf commit c8a1cf6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ For each curl test, you may define the following properties:
- `logged_on_sso`: `true` or `false` wether the test is performed being logged in on the SSO or not (default: `false`)
- `expect_title`: some text expected to be found in the HTML page's `<title>` (none/ignored by default)
- `expect_content`: some text expected to be found in the HTTP payload
- `expect_return_code`: integer, the expected HTTP return code (default `200`)
- `expect_return_code`: integer or list of integers, the expected HTTP return code (default `200`)
- `auto_test_assets`: wether or not to test the first CSS and first JS asset found on the HTML page (default `false` except when the app provides no curl test and use the default mode)
- `base_url`: defaults to the app's install URL (`$domain$path`). Can be changed to something like `https://__DOMAIN__` combined with `path` set to for example `/.well-known/foobar`, useful to test URLs which may be on a different domain or always at the domain root even when the app is on a subpath (such as well-known endpoints)

Expand Down
11 changes: 9 additions & 2 deletions lib/curl_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,13 @@ def test(
base_tag = html.find("base")
base = base_tag.get("href", "") if base_tag else ""

def code_was_expected(code: int) -> bool:
if isinstance(expect_return_code, int):
return code == expect_return_code
if isinstance(expect_return_code, list):
return code in expect_return_code
raise ValueError("expect_return_code should be list or int")

errors = []
if expect_effective_url is None and "/yunohost/sso" in effective_url:
errors.append(
Expand All @@ -191,7 +198,7 @@ def test(
errors.append(
f"Ended up on URL '{effective_url}', but was expecting '{expect_effective_url}'"
)
if expect_return_code and code != expect_return_code:
if not code_was_expected(code):
errors.append(f"Got return code {code}, but was expecting {expect_return_code}")
if expect_title is None and "Welcome to nginx" in title:
errors.append("The request ended up on the default nginx page?")
Expand All @@ -206,7 +213,7 @@ def test(

assets = []
# Auto-check assets - though skip this if we have an unexpected return code for the main page, because there's very likely no asset to find
if auto_test_assets and code == expect_return_code:
if auto_test_assets and code_was_expected(code):
assets_to_check = []
stylesheets = html.find_all("link", rel="stylesheet", href=True)
stylesheets = [
Expand Down

0 comments on commit c8a1cf6

Please sign in to comment.