Skip to content

Commit

Permalink
fix Py2 incompatible issue with match and dict comparison
Browse files Browse the repository at this point in the history
  • Loading branch information
wjo1212 committed Dec 18, 2018
1 parent 1bff48e commit 982347f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
2 changes: 1 addition & 1 deletion aliyun/log/etl_core/transform/condition_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def __init__(self, cond, pass_meta=None, restore_meta=None):
self.check_list.append(ck)

DEFAULT_META_KEYS = set( ("__time__", "__topic__", "__source__") )
tag_meta_check = get_re_full_match(r"__tag__:.+")
tag_meta_check = staticmethod(get_re_full_match(r"__tag__:.+"))

def is_meta_key(self, k):
return k in self.DEFAULT_META_KEYS or self.tag_meta_check(k)
Expand Down
11 changes: 7 additions & 4 deletions tests/etl_test/test_case.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
t = transform


def _j(v):
return str(json.dumps(json.loads(v)))


def test_condition():
event = {'k1': '123', 'k2': 'abc', 'k3': "abc123"}

Expand Down Expand Up @@ -590,8 +594,7 @@ def test_split_filter():

d1 = {'i': '1', 'data': _get_file_content('json_data/CVE-2013-0169.json')}
jmes = 'cve.affects.vendor.vendor_data[*].product.product_data[]'
# print(t(("data", SPLIT(jmes=jmes, output='data')))(d1))
assert t(("data", SPLIT(jmes=jmes, output='data')))(d1) == [{'i': '1', 'data': '{"product_name": "openssl", "version": {"version_data": [{"version_value": "*"}, {"version_value": "0.9.8"}, {"version_value": "0.9.8a"}, {"version_value": "0.9.8b"}, {"version_value": "0.9.8c"}, {"version_value": "0.9.8d"}, {"version_value": "0.9.8f"}, {"version_value": "0.9.8g"}]}}'}, {'i': '1', 'data': '{"product_name": "openjdk", "version": {"version_data": [{"version_value": "-"}, {"version_value": "1.6.0"}, {"version_value": "1.7.0"}]}}'}, {'i': '1', 'data': '{"product_name": "polarssl", "version": {"version_data": [{"version_value": "0.10.0"}, {"version_value": "0.10.1"}, {"version_value": "0.11.0"}]}}'}]
assert t(("data", SPLIT(jmes=jmes, output='data')))(d1) == [{'i': '1', 'data': _j('{"product_name": "openssl", "version": {"version_data": [{"version_value": "*"}, {"version_value": "0.9.8"}, {"version_value": "0.9.8a"}, {"version_value": "0.9.8b"}, {"version_value": "0.9.8c"}, {"version_value": "0.9.8d"}, {"version_value": "0.9.8f"}, {"version_value": "0.9.8g"}]}}')}, {'i': '1', 'data': _j('{"product_name": "openjdk", "version": {"version_data": [{"version_value": "-"}, {"version_value": "1.6.0"}, {"version_value": "1.7.0"}]}}')}, {'i': '1', 'data': _j('{"product_name": "polarssl", "version": {"version_data": [{"version_value": "0.10.0"}, {"version_value": "0.10.1"}, {"version_value": "0.11.0"}]}}')}]


def test_json_filter():
Expand Down Expand Up @@ -774,12 +777,12 @@ def test_json_mixed():
# jmes - expand
d1 = {'i': '1', 'data': _get_file_content('json_data/simple_data.json')}
jmes = 'cve.CVE_data_meta'
assert t( ("data", JSON(jmes=jmes, output='data', expand=True)) )(d1) == {'i': '1', 'data': '{"ASSIGNER": "cve@mitre.org", "ID": "CVE-2013-0169"}', 'ASSIGNER': 'cve@mitre.org', 'ID': 'CVE-2013-0169'}
assert t( ("data", JSON(jmes=jmes, output='data', expand=True)) )(d1) == {'i': '1', 'data': _j('{"ASSIGNER": "cve@mitre.org", "ID": "CVE-2013-0169"}'), 'ASSIGNER': 'cve@mitre.org', 'ID': 'CVE-2013-0169'}

# jmes filter with output - no expand
d1 = {'data': _get_file_content('json_data/CVE-2013-0169.json')}
jmes = 'cve.affects.vendor.vendor_data[2].product'
assert t( ("data", JSON(jmes=jmes, output='data')) )(d1) == {'data': '{"product_data": [{"product_name": "polarssl", "version": {"version_data": [{"version_value": "0.10.0"}, {"version_value": "0.10.1"}, {"version_value": "0.11.0"}]}}]}'}
assert t( ("data", JSON(jmes=jmes, output='data')) )(d1) == {'data': _j('{"product_data": [{"product_name": "polarssl", "version": {"version_data": [{"version_value": "0.10.0"}, {"version_value": "0.10.1"}, {"version_value": "0.11.0"}]}}]}')}

# jmes filter with expand and options
d1 = {'data': _get_file_content('json_data/CVE-2013-0169.json')}
Expand Down

0 comments on commit 982347f

Please sign in to comment.