Skip to content

Commit

Permalink
Facebook Marketing #5190 - add unit tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
vitaliizazmic committed Oct 22, 2021
1 parent 9f0c2f2 commit 400de40
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,12 @@ def serialize(value, exclude_fields: List = None) -> str:
"""Simplify comparison of nested dicts/lists"""
if isinstance(value, Mapping):
# If value is Mapping, some fields can be excluded
if exclude_fields:
for field in exclude_fields:
try:
dpath.util.delete(value, field)
except dpath.exceptions.PathNotFound:
pass
exclude_fields = exclude_fields or []
for field in exclude_fields:
try:
dpath.util.delete(value, field)
except dpath.exceptions.PathNotFound:
pass
return DictWithHash(value)
if isinstance(value, List):
return sorted([serialize(v) for v in value])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
# Copyright (c) 2021 Airbyte, Inc., all rights reserved.
#

from functools import partial

import pytest
from source_acceptance_test.utils.compare import serialize

Expand Down Expand Up @@ -86,3 +88,14 @@ def test_compare_two_records(not_sorted_data, sorted_data):
"""Test that compare two records with equals, not sorted data."""
output_diff = set(map(serialize, sorted_data)) - set(map(serialize, not_sorted_data))
assert not output_diff


def test_exclude_fields(sorted_data):
""""""
ignored_fields = [
"organization_id",
]
serializer = partial(serialize, exclude_fields=ignored_fields)
output = map(serializer, sorted_data)
for item in output:
assert "organization_id" not in item

0 comments on commit 400de40

Please sign in to comment.