-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconftest.py
68 lines (57 loc) · 2.99 KB
/
conftest.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# SPDX-License-Identifier: AGPL-3.0-only
# SPDX-FileCopyrightText: 2024 Univention GmbH
import logging
import random
import pytest
logger = logging.getLogger(__name__)
def pytest_addoption(parser):
# Portal tests options
parser.addoption("--portal-base-url", help="Base URL of the univention portal")
parser.addoption("--admin-username", default="Administrator", help="Portal admin login username")
parser.addoption("--admin-password", default="univention", help="Portal admin login password")
parser.addoption("--email-test-api-username", default="user", help="Username to access the email test API.")
parser.addoption("--email-test-api-password", default="univention", help="Password to access the email test API.")
parser.addoption("--email-test-api-base-url", default="", help="Base URL to reach the email test API (Maildev).")
parser.addoption(
"--portal-central-navigation-secret",
default="univention",
help="Shared secret with portal-server for central navigation",
)
# BFP tests options
parser.addoption("--keycloak-base-url", help="Base URL of Keycloak")
parser.addoption("--kc-admin-username", default="admin", help="Keycloak admin login username")
parser.addoption("--kc-admin-password", default="univention", help="Keycloak admin login password")
parser.addoption("--num-device-block", type=int, default=5, help="Number of failed logins for device block")
parser.addoption("--num-ip-block", type=int, default=7, help="Number of failed logins for IP block")
parser.addoption("--release-duration", type=int, default=1, help="Blocks are released after this many minutes")
parser.addoption("--realm", default="master", help="Realm to attempt logins at")
parser.addoption("--randomly-seed", help="Seed to use for randomization.")
@pytest.fixture(scope="session")
def base_seed(pytestconfig) -> int:
"""
Interim solution to randomize the integrated Faker.
Long term we aim to go for ``pytest-randomly``.
"""
base_seed = pytestconfig.getoption("--randomly-seed")
if not base_seed:
base_seed = random.randint(1000, 9999)
print("base seed: ", base_seed)
return base_seed
@pytest.fixture(scope="function", autouse=True)
def faker_seed(base_seed, request):
"""
Generates unique but deterministic seeds for every test function.
Based on a root seed and the test function name.
When faker is used in a fixture that is used by multiple test functions.
Each function expects different faker data.
This is essential to avoid cross-contamination between tests
because of test objects like LDAP users or groups.
At the same time, the faker seed needs to stay deterministic.
"""
test_function_name = request.node.name
if hasattr(request, "param"):
seed = f"{base_seed}-{test_function_name}-{request.param}"
else:
seed = f"{base_seed}-{test_function_name}"
logger.info("Generated faker seed unique to the test function is: %s", seed)
return seed