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 010a215
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 20 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
9 changes: 5 additions & 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,8 +228,10 @@

'text_search_is_exact_match_only',

## This one is fixed in master branch
'category_search_yields_nothing', ## https://github.com/jelmer/xandikos/pull/194
## This one is fixed - but still breaks our test code for python 3.7
## TODO: remove this when shredding support for python 3.7
## https://github.com/jelmer/xandikos/pull/194
'category_search_yields_nothing',

## scheduling is not supported
"no_scheduling",
Expand All @@ -240,7 +242,6 @@
## "weird" on radicale
"broken_expand",
"no_default_calendar",
"non_existing_calendar_found",

## freebusy is not supported yet, but on the long-term road map
"no_freebusy_rfc4791",
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
29 changes: 16 additions & 13 deletions tests/test_caldav.py
Original file line number Diff line number Diff line change
Expand Up @@ -848,7 +848,7 @@ def testProxy(self):

threadobj = threading.Thread(target=proxy_httpd.serve_forever)
conn_params = self.server_params.copy()
for special in ("setup", "teardown"):
for special in ("setup", "teardown", "name"):
if special in conn_params:
conn_params.pop(special)
try:
Expand Down Expand Up @@ -1688,7 +1688,7 @@ def testWrongPassword(self):
"Testing with wrong password skipped as calendar server does not require a password"
)
connect_params = self.server_params.copy()
for delme in ("url", "setup", "teardown", "name"):
for delme in ("setup", "teardown", "name"):
if delme in connect_params:
connect_params.pop(delme)
connect_params["password"] = (
Expand Down 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 010a215

Please sign in to comment.