Skip to content

Commit

Permalink
Tests: add a text identifier to each caldav server entry
Browse files Browse the repository at this point in the history
Probably not relevant for many, but I do have a tests/conf_private.py
filled up with various servers, so it would be nice to add "friendly"
names to identify them
  • Loading branch information
tobixen committed Nov 17, 2024
1 parent 0b4d9c9 commit b4d6f5b
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 18 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,13 @@ This project should more or less adhere to [Semantic Versioning](https://semver.

### Changed

* Test framework has been refactored a bit. Code for setting up and rigging down xandikos/radicale servers have been moved from `tests/test_caldav.py` to `tests/conf.py`. This allows for:
#### Test framework

* Functional test framework has been refactored - code for setting up and rigging down xandikos/radicale servers have been moved from `tests/test_caldav.py` to `tests/conf.py`. This allows for:
* Adding code (including system calls or remote API calls) for Setting up and tearing down calendar servers in `conf_private.py`
* Creating a local xandikos or radicale server in the `tests.client`-method, which is also used in the `examples`-section.
* Allows offline testing of my upcoming `check_server_compatibility`-script
* Also added the possibility to tag test servers with a name

### Added

Expand Down
5 changes: 1 addition & 4 deletions tests/compatibility_issues.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
## * Consider how to get this into the documentation
incompatibility_description = {
'rate_limited':
"""Pause a bit between each request""",
"""It may be needed to pause a bit between each request when doing tests""",

'cleanup_calendar':
"""Remove everything on the calendar for every test""",
Expand Down Expand Up @@ -228,9 +228,6 @@

'text_search_is_exact_match_only',

## This one is fixed in master branch
'category_search_yields_nothing', ## https://github.com/jelmer/xandikos/pull/194

## scheduling is not supported
"no_scheduling",
]
Expand Down
15 changes: 13 additions & 2 deletions tests/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ def teardown_radicale(self):
caldav_servers.append(
{
"url": url,
"name": "LocalRadicale",
"username": "user1",
"password": "any-password-seems-to-work",
"backwards_compatibility_url": url + "user1",
Expand Down Expand Up @@ -218,6 +219,7 @@ def silly_request():
url = "http://%s:%i/" % (xandikos_host, xandikos_port)
caldav_servers.append(
{
"name": "LocalXandikos",
"url": url,
"backwards_compatibility_url": url + "sometestuser",
"incompatibilities": compatibility_issues.xandikos,
Expand All @@ -234,15 +236,24 @@ def silly_request():
)


def client(idx=None, setup=lambda conn: None, teardown=lambda conn: None, **kwargs):
def client(
idx=None, name=None, setup=lambda conn: None, teardown=lambda conn: None, **kwargs
):
## No parameters given - find the first server in caldav_servers list
if idx is None and not kwargs:
if idx is None and not kwargs and caldav_servers:
idx = 0
while idx < len(caldav_servers) and not caldav_servers[idx].get("enable", True):
idx += 1
if idx == len(caldav_servers):
return None
return client(idx=idx)
elif idx is not None and not kwargs and caldav_servers:
return client(**caldav_servers[idx])
elif name is not None and not kwargs and caldav_servers:
for s in caldav_servers:
if caldav_servers["name"] == s:
return s
return None
elif not kwargs:
return None
for bad_param in (
Expand Down
5 changes: 5 additions & 0 deletions tests/conf_private.py.EXAMPLE
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ from tests import compatibility_issues
## Define your primary caldav server here
caldav_servers = [
{
## A friendly identifiter for the server. Should be a CamelCase name
## Not needed, but may be nice if you have several servers to test towards.
## Should not affect test runs in any other way than improved verbosity.
'name': 'MyExampleServer'

## Set enable to False if you don't want to use a server
'enable': True,

Expand Down
25 changes: 14 additions & 11 deletions tests/test_caldav.py
Original file line number Diff line number Diff line change
Expand Up @@ -2836,23 +2836,26 @@ def testObjects(self):
# (maybe a custom nose test loader really would be the better option?)
# -- Tobias Brox <[email protected]>, 2013-10-10

## TODO: can we use @pytest.mark.parametrize to run the collection of tests
## above on each of the servers defined in caldav_servers?
## TODO: The better way is probably to use @pytest.mark.parametrize
## -- Tobias Brox <[email protected]>, 2024-11-15

_servernames = set()
for _caldav_server in caldav_servers:
# create a unique identifier out of the server domain name
_parsed_url = urlparse(_caldav_server["url"])
_servername = _parsed_url.hostname.replace(".", "_").replace("-", "_") + str(
_parsed_url.port or ""
)
while _servername in _servernames:
_servername = _servername + "_"
_servernames.add(_servername)
if "name" in _caldav_server:
_servername = _caldav_server["name"]
else:
# create a unique identifier out of the server domain name
_parsed_url = urlparse(_caldav_server["url"])
_servername = _parsed_url.hostname.replace(".", "_").replace("-", "_") + str(
_parsed_url.port or ""
)
while _servername in _servernames:
_servername = _servername + "_"
_servername = _servername.capitalize()
_servernames.add(_servername)

# create a classname and a class
_classname = "TestForServer_" + _servername
_classname = "TestForServer" + _servername

# inject the new class into this namespace
vars()[_classname] = type(
Expand Down

0 comments on commit b4d6f5b

Please sign in to comment.