Skip to content

Commit

Permalink
🐛 SAT: Update DictWithHash class in test_sequential_reads (#5738)
Browse files Browse the repository at this point in the history
* add total_ordering to DictWithHash

* add unit_test for serialize

* bump version to 0.1.17
  • Loading branch information
annalvova05 authored Sep 3, 2021
1 parent 086bdcd commit 7f18cec
Show file tree
Hide file tree
Showing 4 changed files with 113 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Changelog

## 0.1.17
Fix serialize function for acceptance-tests: https://github.com/airbytehq/airbyte/pull/5738

## 0.1.16
Fix for flake8-ckeck for acceptance-tests: https://github.com/airbytehq/airbyte/pull/5785

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ COPY setup.py ./
COPY pytest.ini ./
RUN pip install .

LABEL io.airbyte.version=0.1.16
LABEL io.airbyte.version=0.1.17
LABEL io.airbyte.name=airbyte/source-acceptance-test

ENTRYPOINT ["python", "-m", "pytest", "-p", "source_acceptance_test.plugin"]
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#


import functools
import json
from typing import List, Mapping, Optional

Expand Down Expand Up @@ -70,6 +71,7 @@ def diff_dicts(left, right, use_markup) -> Optional[List[str]]:
return ["equals failed"] + [color_off + line for line in icdiff_lines]


@functools.total_ordering
class DictWithHash(dict):

_hash: str = None
Expand All @@ -82,6 +84,9 @@ def __hash__(self):
def __lt__(self, other):
return hash(self) < hash(other)

def __eq__(self, other):
return hash(self) == hash(other)


def serialize(value) -> str:
"""Simplify comparison of nested dicts/lists"""
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
#
# MIT License
#
# Copyright (c) 2020 Airbyte
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
#

import pytest
from source_acceptance_test.utils.compare import serialize


@pytest.fixture(name="not_sorted_data")
def not_sorted_data_fixture():
return [{
"date_created": "0001-01-01T00:00:00",
"date_updated": "0001-01-01T00:00:00",
"editable": False,
"id": "superuser",
"name": "Super User",
"organization_id": "orga_ya3w9oMjeLtWe7zFGZr63Dz8ruBbjybG0EIUdUXaESi",
"permissions": [
"bulk_edit",
"delete_own_opportunities",
"export",
"manage_group_numbers",
"manage_email_sequences",
"delete_leads",
"call_coach_listen",
"call_coach_barge",
"manage_others_tasks",
"manage_others_activities",
"delete_own_tasks",
"manage_customizations",
"manage_team_smart_views",
"bulk_delete",
"manage_team_email_templates",
"bulk_email",
"merge_leads",
"calling",
"bulk_sequence_subscriptions",
"bulk_import",
"delete_own_activities",
"manage_others_opportunities"
]
}]


@pytest.fixture(name="sorted_data")
def sorted_data_fixture():
return [{
"date_created": "0001-01-01T00:00:00",
"date_updated": "0001-01-01T00:00:00",
"editable": False,
"id": "superuser",
"name": "Super User",
"organization_id": "orga_ya3w9oMjeLtWe7zFGZr63Dz8ruBbjybG0EIUdUXaESi",
"permissions": [
"bulk_delete",
"bulk_edit",
"bulk_email",
"bulk_import",
"bulk_sequence_subscriptions",
"call_coach_barge",
"call_coach_listen",
"calling",
"delete_leads",
"delete_own_activities",
"delete_own_opportunities",
"delete_own_tasks",
"export",
"manage_customizations",
"manage_email_sequences",
"manage_group_numbers",
"manage_others_activities",
"manage_others_opportunities",
"manage_others_tasks",
"manage_team_email_templates",
"manage_team_smart_views",
"merge_leads"
]
}]


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

0 comments on commit 7f18cec

Please sign in to comment.