deltafi 2.0rc1713530263087__tar.gz → 2.0rc1714076410617__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of deltafi might be problematic. Click here for more details.

Files changed (27) hide show
  1. {deltafi-2.0rc1713530263087 → deltafi-2.0rc1714076410617}/PKG-INFO +1 -1
  2. deltafi-2.0rc1714076410617/deltafi/test_kit/compare_helpers.py +288 -0
  3. {deltafi-2.0rc1713530263087 → deltafi-2.0rc1714076410617}/pyproject.toml +1 -1
  4. deltafi-2.0rc1713530263087/deltafi/test_kit/compare_helpers.py +0 -50
  5. {deltafi-2.0rc1713530263087 → deltafi-2.0rc1714076410617}/README.md +0 -0
  6. {deltafi-2.0rc1713530263087 → deltafi-2.0rc1714076410617}/deltafi/__init__.py +0 -0
  7. {deltafi-2.0rc1713530263087 → deltafi-2.0rc1714076410617}/deltafi/action.py +0 -0
  8. {deltafi-2.0rc1713530263087 → deltafi-2.0rc1714076410617}/deltafi/actioneventqueue.py +0 -0
  9. {deltafi-2.0rc1713530263087 → deltafi-2.0rc1714076410617}/deltafi/actiontype.py +0 -0
  10. {deltafi-2.0rc1713530263087 → deltafi-2.0rc1714076410617}/deltafi/domain.py +0 -0
  11. {deltafi-2.0rc1713530263087 → deltafi-2.0rc1714076410617}/deltafi/exception.py +0 -0
  12. {deltafi-2.0rc1713530263087 → deltafi-2.0rc1714076410617}/deltafi/genericmodel.py +0 -0
  13. {deltafi-2.0rc1713530263087 → deltafi-2.0rc1714076410617}/deltafi/input.py +0 -0
  14. {deltafi-2.0rc1713530263087 → deltafi-2.0rc1714076410617}/deltafi/logger.py +0 -0
  15. {deltafi-2.0rc1713530263087 → deltafi-2.0rc1714076410617}/deltafi/metric.py +0 -0
  16. {deltafi-2.0rc1713530263087 → deltafi-2.0rc1714076410617}/deltafi/plugin.py +0 -0
  17. {deltafi-2.0rc1713530263087 → deltafi-2.0rc1714076410617}/deltafi/result.py +0 -0
  18. {deltafi-2.0rc1713530263087 → deltafi-2.0rc1714076410617}/deltafi/storage.py +0 -0
  19. {deltafi-2.0rc1713530263087 → deltafi-2.0rc1714076410617}/deltafi/test_kit/__init__.py +0 -0
  20. {deltafi-2.0rc1713530263087 → deltafi-2.0rc1714076410617}/deltafi/test_kit/assertions.py +0 -0
  21. {deltafi-2.0rc1713530263087 → deltafi-2.0rc1714076410617}/deltafi/test_kit/constants.py +0 -0
  22. {deltafi-2.0rc1713530263087 → deltafi-2.0rc1714076410617}/deltafi/test_kit/domain.py +0 -0
  23. {deltafi-2.0rc1713530263087 → deltafi-2.0rc1714076410617}/deltafi/test_kit/egress.py +0 -0
  24. {deltafi-2.0rc1713530263087 → deltafi-2.0rc1714076410617}/deltafi/test_kit/enrich.py +0 -0
  25. {deltafi-2.0rc1713530263087 → deltafi-2.0rc1714076410617}/deltafi/test_kit/framework.py +0 -0
  26. {deltafi-2.0rc1713530263087 → deltafi-2.0rc1714076410617}/deltafi/test_kit/transform.py +0 -0
  27. {deltafi-2.0rc1713530263087 → deltafi-2.0rc1714076410617}/deltafi/test_kit/validate.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: deltafi
3
- Version: 2.0rc1713530263087
3
+ Version: 2.0rc1714076410617
4
4
  Summary: SDK for DeltaFi plugins and actions
5
5
  License: Apache License, Version 2.0
6
6
  Keywords: deltafi
@@ -0,0 +1,288 @@
1
+ #
2
+ # DeltaFi - Data transformation and enrichment platform
3
+ #
4
+ # Copyright 2021-2023 DeltaFi Contributors <deltafi@deltafi.org>
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+
19
+ import json
20
+ import re
21
+ from abc import ABC
22
+ from abc import abstractmethod
23
+ from itertools import repeat
24
+
25
+ from deepdiff import DeepDiff, DeepSearch
26
+
27
+ from .assertions import *
28
+
29
+
30
+ class CompareHelper(ABC):
31
+ @abstractmethod
32
+ def compare(self, expected: str, actual: str, label: str):
33
+ pass
34
+
35
+
36
+ class GenericCompareHelper(CompareHelper):
37
+ def compare(self, expected: str, actual: str, label: str):
38
+ assert_equal_with_label(expected, actual, label)
39
+
40
+
41
+ class JsonCompareHelper(CompareHelper):
42
+ """Provides helper functions for comparing JSON/dict objects.
43
+
44
+ Are these two JSON/dict objects equivalent?
45
+ - compare(...)
46
+
47
+ Are these two lists equivalent?
48
+ - compare_lists(...)
49
+
50
+ Is this list a subset/superset of that list?
51
+ - compare_lists_subset(...)
52
+ - compare_lists_superset(...)
53
+
54
+ Select a list of values from an existing list and put them into a new list to facilitate list comparisons:
55
+ - create_list_from_list_using_filter_regex(...)
56
+
57
+ Is this value found (or not) in this JSON/dict object?
58
+ - is_found(...)
59
+ - is_not_found(...)
60
+ """
61
+
62
+ def __init__(self, regex_exclusion_list=None, ignore_order=True):
63
+ """Creates and configures a JsonCompareHelper object. If the optional 'ignore_order' is true, then the order of
64
+ data is ignored when checking else order is enforced. The optional 'regex_exclusion_list' excludes
65
+ paths within the object from comparison; if empty or not provided, then no excludes are applied."""
66
+ if regex_exclusion_list is None:
67
+ regex_exclusion_list = []
68
+ self.excludes = regex_exclusion_list
69
+ self.ignore_order = ignore_order
70
+
71
+ def __perform_find(self, obj: object, item):
72
+ """Returns a dict of matches of the 'item' in the object 'obj'. The returned dict is empty if there are no
73
+ matches. Excludes path determined by the constructor."""
74
+ return DeepSearch(obj, item, verbose_level=2, exclude_regex_paths=self.excludes)
75
+
76
+ def is_not_found(self, obj: object, item):
77
+ """Returns None if there are no occurrences of 'item' in object 'obj' else returns a ValueError. The argument
78
+ 'item' may be a scalar or a list. Excludes path and failure on ordering of elements are determined by
79
+ the constructor."""
80
+
81
+ all_matches = []
82
+
83
+ if isinstance(item, list):
84
+ for value in item:
85
+ matches = self.__perform_find(obj, value)
86
+ if len(matches) > 0:
87
+ all_matches.append(matches)
88
+ else:
89
+ matches = self.__perform_find(obj, item)
90
+ if len(matches) > 0:
91
+ all_matches.append(matches)
92
+
93
+ if len(all_matches) > 0:
94
+ raise ValueError(f"{all_matches}")
95
+
96
+ assert len(all_matches) == 0
97
+
98
+ def is_found(self, obj: object, item):
99
+ """Returns None if there are no occurrences of 'item' in object 'obj' else returns a ValueError. The argument
100
+ 'item' may be a scalar or a list. Excludes path and failure on ordering of elements are determined by
101
+ the constructor."""
102
+
103
+ all_matches = []
104
+
105
+ if isinstance(item, list):
106
+ for value in item:
107
+ matches = self.__perform_find(obj, value)
108
+ if len(matches) > 0:
109
+ all_matches.append(matches)
110
+ else:
111
+ matches = self.__perform_find(obj, item)
112
+ if len(matches) > 0:
113
+ all_matches.append(matches)
114
+
115
+ if len(all_matches) == 0:
116
+ raise ValueError("No matches found for '" + str(item) + "'")
117
+
118
+ assert len(all_matches) > 0
119
+
120
+ def __perform_diff(self, expected, actual):
121
+ """Returns a dict with differences between 'expected' and 'actual'. The returned dict is empty if 'expected'
122
+ and 'actual' are equivalent. Both 'expected' and 'actual' must be dicts. Excludes path and failure on
123
+ ordering of elements are determined by the constructor. Elements must match number of repetitions."""
124
+ return DeepDiff(expected, actual, ignore_order=self.ignore_order, report_repetition=True,
125
+ exclude_regex_paths=self.excludes)
126
+
127
+ def __perform_diff_with_eval(self, expected, actual):
128
+ """Returns None if 'expected' and 'actual' are equivalent else returns a ValueError. Both 'expected' and
129
+ 'actual' must be dicts. Excludes path and failure on ordering of elements are determined by the
130
+ constructor. Elements must match number of repetitions."""
131
+
132
+ diffs = self.__perform_diff(expected, actual)
133
+
134
+ if len(diffs) > 0:
135
+ raise ValueError(f"{diffs}")
136
+
137
+ assert len(diffs) == 0
138
+
139
+ def compare(self, expected, actual, label: str):
140
+ """Returns None if 'expected' and 'actual' are equivalent else returns a ValueError. Both 'expected' and
141
+ 'actual' must be either dicts or strings that parse as JSON to dicts. Excludes path and failure on
142
+ ordering of elements are determined by the constructor. Elements must match number of repetitions."""
143
+
144
+ if isinstance(expected, str):
145
+ exp = json.loads(expected)
146
+ else:
147
+ exp = expected
148
+
149
+ if isinstance(actual, str):
150
+ act = json.loads(actual)
151
+ else:
152
+ act = actual
153
+
154
+ return self.__perform_diff_with_eval(exp, act)
155
+
156
+ def compare_lists(self, expected, actual: list, label: str):
157
+ """Returns None if 'actual' is equivalent to 'expected' else returns a ValueError.
158
+
159
+ The 'actual' argument must be a list. The 'expected' argument may be a list or a dict. If a list, then
160
+ 'expected' and 'actual' are compared against each other. If a dict, then 'actual' is equivalent if it
161
+ contains elements with the same repetitions as defined in the 'expected' dict with the key equal to the
162
+ element in 'actual' and the value equal to the number of repetitions.
163
+
164
+ Order of elements is ignored. Elements must match number of repetitions."""
165
+
166
+ expected_list = []
167
+
168
+ if isinstance(expected, dict):
169
+ for key, value in expected.items():
170
+ expected_list += list(repeat(key, value))
171
+ else:
172
+ expected_list = expected
173
+
174
+ return self.__perform_diff_with_eval({"json-compare-helper-internal-list": expected_list},
175
+ {"json-compare-helper-internal-list": actual})
176
+
177
+ @staticmethod
178
+ def compare_lists_subset(expected_subset, actual: list):
179
+ """Returns None if the 'actual' list contains at least 'expected_subset' else returns a ValueError. The
180
+ 'actual' list may contain 0 or more additional elements than defined in 'expected_subset'.
181
+
182
+ The 'actual' argument must be a list. The argument 'expected_subset' may be a list or a dict. In the
183
+ latter case, the key defines the item that must appear in 'actual' and the value defines the number of
184
+ repetitions.
185
+
186
+ Order of elements is ignored. Elements must match number of repetitions."""
187
+
188
+ expected_subset_map = {}
189
+
190
+ if isinstance(expected_subset, list):
191
+ for item in expected_subset:
192
+ value = expected_subset_map.get(item)
193
+ if value is None:
194
+ expected_subset_map[item] = 1
195
+ else:
196
+ expected_subset_map[item] = value + 1
197
+ else:
198
+ expected_subset_map = expected_subset
199
+
200
+ actual_map = {}
201
+
202
+ for item in actual:
203
+ value = actual_map.get(item)
204
+ if value is None:
205
+ actual_map[item] = 1
206
+ else:
207
+ actual_map[item] = value + 1
208
+
209
+ for key, value in expected_subset_map.items():
210
+ actual_value = actual_map.get(key)
211
+ if actual_value is None:
212
+ raise ValueError("Actual list did not contain element '" + str(key) + "'")
213
+ else:
214
+ if actual_value != value:
215
+ raise ValueError("Actual list had item '" + str(key) + "' with repetition " + str(actual_value)
216
+ + " but required repetition " + str(value))
217
+
218
+ return None
219
+
220
+ @staticmethod
221
+ def compare_lists_superset(expected_superset, actual: list):
222
+ """Returns None if the 'actual' list contains only elements that appear in 'expected_superset' else returns a
223
+ ValueError. The 'actual' list cannot contain more elements than are defined in 'expected_superset'; the
224
+ 'expected_superset' may define 0 or more values not contained in 'actual'.
225
+
226
+ The 'actual' argument must be a list. The argument 'expected_superset' may be a list or a dict. In the
227
+ latter case, the key defines the item that must appear in 'actual' and the value defines the number of
228
+ repetitions.
229
+
230
+ Order of elements is ignored. Elements must match number of repetitions."""
231
+
232
+ expected_superset_map = {}
233
+
234
+ if isinstance(expected_superset, list):
235
+ for item in expected_superset:
236
+ value = expected_superset_map.get(item)
237
+ if value is None:
238
+ expected_superset_map[item] = 1
239
+ else:
240
+ expected_superset_map[item] = value + 1
241
+ else:
242
+ expected_superset_map = expected_superset
243
+
244
+ actual_map = {}
245
+
246
+ for item in actual:
247
+ value = actual_map.get(item)
248
+ if value is None:
249
+ actual_map[item] = 1
250
+ else:
251
+ actual_map[item] = value + 1
252
+
253
+ for key, value in actual_map.items():
254
+ expected_value = expected_superset_map.get(key)
255
+ if expected_value is None:
256
+ raise ValueError("Actual list contained element '" + str(key)
257
+ + "' that did not appear in the expected superset")
258
+ else:
259
+ if expected_value != value:
260
+ raise ValueError("Actual list had item '" + str(key) + "' with repetition " + str(value)
261
+ + " but required repetition " + str(expected_value))
262
+
263
+ return None
264
+
265
+ @staticmethod
266
+ def create_list_from_list_using_filter_regex(regex, source_list: list):
267
+ """Creates and returns a list of those items in the 'source_list' matching the regex in the 'regex'. The
268
+ argument 'regex' may be a string or a compiled regex object.
269
+
270
+ For the 'regex', consider using anchors to explicitly match from the start (or end) of a string. For
271
+ example, a string such as "^malware--" will explicitly match from the start of a string."""
272
+
273
+ def search_funct(element):
274
+
275
+ if isinstance(regex, str):
276
+ # 'regex' is a string
277
+ match = re.search(regex, element)
278
+ else:
279
+ # assume 'regex' is a compiled regex pattern object
280
+ match = regex.match(element)
281
+
282
+ if match is None:
283
+ return False
284
+ else:
285
+ return True
286
+
287
+ return list(filter(search_funct, source_list))
288
+
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "deltafi"
3
- version = "2.0rc1713530263087"
3
+ version = "2.0rc1714076410617"
4
4
  description = "SDK for DeltaFi plugins and actions"
5
5
  authors = ["DeltaFi <deltafi@systolic.com>"]
6
6
  license = "Apache License, Version 2.0"
@@ -1,50 +0,0 @@
1
- #
2
- # DeltaFi - Data transformation and enrichment platform
3
- #
4
- # Copyright 2021-2023 DeltaFi Contributors <deltafi@deltafi.org>
5
- #
6
- # Licensed under the Apache License, Version 2.0 (the "License");
7
- # you may not use this file except in compliance with the License.
8
- # You may obtain a copy of the License at
9
- #
10
- # http://www.apache.org/licenses/LICENSE-2.0
11
- #
12
- # Unless required by applicable law or agreed to in writing, software
13
- # distributed under the License is distributed on an "AS IS" BASIS,
14
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
- # See the License for the specific language governing permissions and
16
- # limitations under the License.
17
- #
18
-
19
- import json
20
- from abc import ABC
21
- from abc import abstractmethod
22
- from typing import List
23
-
24
- from deepdiff import DeepDiff
25
-
26
- from .assertions import *
27
-
28
-
29
- class CompareHelper(ABC):
30
- @abstractmethod
31
- def compare(self, expected: str, actual: str, label: str):
32
- pass
33
-
34
-
35
- class GenericCompareHelper(CompareHelper):
36
- def compare(self, expected: str, actual: str, label: str):
37
- assert_equal_with_label(expected, actual, label)
38
-
39
-
40
- class JsonCompareHelper(CompareHelper):
41
- def __init__(self, regex_exclusion_list: List):
42
- self.excludes = regex_exclusion_list
43
-
44
- def compare(self, expected: str, actual: str, label: str):
45
- exp = json.loads(expected)
46
- act = json.loads(actual)
47
- diffs = DeepDiff(exp, act, exclude_regex_paths=self.excludes)
48
- if len(diffs) > 0:
49
- raise ValueError(f"{diffs}")
50
- assert len(diffs) == 0