Skip to content

Commit 108a10f

Browse files
committed
work in progress
1 parent 6878921 commit 108a10f

2 files changed

Lines changed: 43 additions & 32 deletions

File tree

caldav/compatibility_hints.py

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ class FeatureSet:
7777
},
7878
}
7979

80-
def __init__(self, feature_set):
80+
def __init__(self, feature_set_dict):
8181
"""
8282
TODO: describe the feature_set better.
8383
@@ -104,18 +104,21 @@ def __init__(self, feature_set):
104104
## (anyways, that is an internal design decision that may be
105105
## changed ... but we need test code in place)
106106
self._server_features = {}
107-
self.copyFeatureSet(feature_set)
107+
self.copyFeatureSet(feature_set_dict)
108108

109-
def _copyFeature(def_node, server_node, value):
109+
def _copyFeature(self, def_node, server_node, value):
110110
if isinstance(value, str) and not 'support' in server_node:
111111
server_node['support'] = value
112112
elif isinstance(value, dict):
113113
if value.get('features'):
114114
raise NotImplementedError("todo ... work in progress ... need to recursively process the feature set")
115115
server_node.update(value)
116116

117-
def copyFeatureSet(feature_set):
117+
def copyFeatureSet(self, feature_set):
118118
for feature in feature_set:
119+
## TODO: temp - should be removed
120+
if feature == 'old_flags':
121+
continue
119122
fpath = feature.split('.')
120123
def_tree = self.FEATURES
121124
server_tree = self._server_features
@@ -126,15 +129,33 @@ def copyFeatureSet(feature_set):
126129
if not step in server_tree:
127130
server_tree[step] = {}
128131
server_node = server_tree[step]
129-
if not 'features' in def_tree:
132+
if not 'features' in def_node:
130133
server_tree = None
131134
def_tree = None
132135
else:
133136
if not 'features' in server_node:
134137
server_node['features'] = {}
135138
server_tree = server_node['features']
136139
def_tree = def_node['features']
137-
self._copyFeature(def_node, server_node, feature_set[fpath])
140+
self._copyFeature(def_node, server_node, feature_set[feature])
141+
142+
def check_support(self, feature, return_type=bool):
143+
"""
144+
Work in progress
145+
146+
TODO: write a better docstring
147+
"""
148+
feature_info = self.find_feature(feature)
149+
support = self._server_features.get(feature, {'support': 'full'})
150+
if return_type == str:
151+
## TODO: consider type, be smarter about it
152+
return support.get('support', support.get('enable', support.get('behaviour')))
153+
elif return_type == dict:
154+
return support
155+
elif return_type == bool:
156+
## TODO: consider type, be smarter about it
157+
return support.get('support', 'full') == 'full' and not support.get('enable') and not support.get('behaviour')
158+
138159

139160
def find_feature(self, feature: str) -> dict:
140161
"""

tests/test_caldav.py

Lines changed: 16 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@
4040
from .conf import test_xandikos
4141
from .conf import xandikos_host
4242
from .conf import xandikos_port
43-
from caldav import compatibility_hints
43+
from caldav.compatibility_hints import FeatureSet
44+
from caldav.compatibility_hints import incompatibility_description ## TEMP - should be removed in the future
4445
from caldav.davclient import DAVClient
4546
from caldav.davclient import DAVResponse
4647
from caldav.davclient import get_davclient
@@ -666,49 +667,38 @@ def check_support(self, feature, return_type=bool):
666667
667668
TODO: write a better docstring
668669
"""
669-
feature_info = compatibility_hints.FEATURES.find_feature(feature)
670-
support = self.features.get(feature, {'support': 'full'})
671-
if return_type == str:
672-
## TODO: consider type, be smarter about it
673-
return support.get('support', support.get('enable', support.get('behaviour')))
674-
elif return_type == dict:
675-
return support
676-
elif return_type == bool:
677-
## TODO: consider type, be smarter about it
678-
return support.get('support', 'full') == 'full' and not support.get('enable') and not support.get('behaviour')
679-
670+
return self.features.check_support(feature, return_type)
671+
680672
def check_compatibility_flag(self, flag):
681673
## yield an assertion error if checking for the wrong thig
682-
assert flag in compatibility_hints.incompatibility_description
683-
return flag in self.features['old_flags']
674+
assert flag in incompatibility_description
675+
return flag in self.old_features
684676

685677
def skip_on_compatibility_flag(self, flag):
686678
if self.check_compatibility_flag(flag):
687-
msg = compatibility_hints.incompatibility_description[flag]
679+
msg = incompatibility_description[flag]
688680
pytest.skip("Test skipped due to server incompatibility issue: " + msg)
689681

690682
def skip_unless_support(self, feature):
691683
if self.check_support(feature):
692-
msg = compatibility_hints.FEATURES.find_feature(feature).get('description', feature)
684+
msg = self.features.find_feature(feature).get('description', feature)
693685
pytest.skip("Test skipped due to server incompatibility issue: " + msg)
694686

695687
def setup_method(self):
696688
logging.debug("############## test setup")
697-
self.features = {}
698689
self.cleanup_regime = self.server_params.get("cleanup", "light")
699690
self.calendars_used = []
700691

701-
self.features = self.server_params.get("features", {})
692+
features = self.server_params.get("features", {})
693+
694+
## Temp thing
695+
self.old_features = features.get('old_flags', [])
696+
697+
self.features = FeatureSet(self.server_params.get("features", {}))
702698

703699
## verify that all old flags are valid
704-
for flag in self.features.get('old_flags'):
705-
assert flag in compatibility_hints.incompatibility_description
706-
707-
## verify that all new compatibility info is valid (TODO: should validate better)
708-
for feature in self.server_params.get('features', []):
709-
if feature == 'old_flags':
710-
continue
711-
compatibility_hints.FEATURES.find_feature(feature)
700+
for flag in self.old_features:
701+
assert flag in incompatibility_description
712702

713703
if self.check_compatibility_flag("unique_calendar_ids"):
714704
self.testcal_id = "testcalendar-" + str(uuid.uuid4())

0 commit comments

Comments
 (0)