Skip to content

Commit

Permalink
8906 Add tests + update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
Zirochkaa committed Jan 28, 2022
1 parent a86b747 commit 7bf1860
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 0 deletions.
1 change: 1 addition & 0 deletions airbyte-integrations/connectors/source-delighted/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
TEST_REQUIREMENTS = [
"pytest~=6.1",
"source-acceptance-test",
"responses~=0.13.3",
]

setup(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,82 @@
# Copyright (c) 2021 Airbyte, Inc., all rights reserved.
#

import pytest
import responses
from airbyte_cdk.models import SyncMode
from source_delighted.source import Bounces, People, SourceDelighted, SurveyResponses, Unsubscribes


@pytest.fixture(scope="module")
def test_config():
return {
"api_key": "test_api_key",
"since": "1641289584",
}


@pytest.fixture(scope="module")
def state():
return {
"bounces": {"bounced_at": 1641455286},
"people": {"created_at": 1641455285},
"survey_responses": {"updated_at": 1641289816},
"unsubscribes": {"unsubscribed_at": 1641289584},
}


BOUNCES_RESPONSE = """
[
{"person_id": "1046789984", "email": "foo_test204@airbyte.io", "name": "Foo Test204", "bounced_at": 1641455286},
{"person_id": "1046789989", "email": "foo_test205@airbyte.io", "name": "Foo Test205", "bounced_at": 1641455286}
]
"""


PEOPLE_RESPONSE = """
[
{"id": "1046789989", "name": "Foo Test205", "email": "foo_test205@airbyte.io", "created_at": 1641455285, "last_sent_at": 1641455285, "last_responded_at": null, "next_survey_scheduled_at": null}
]
"""


SURVEY_RESPONSES_RESPONSE = """
[
{"id": "210554887", "person": "1042205953", "survey_type": "nps", "score": 0, "comment": "Test Comment202", "permalink": "https://app.delighted.com/r/0q7QEdWzosv5G5c3w9gakivDwEIM5Hq0", "created_at": 1641289816, "updated_at": 1641289816, "person_properties": null, "notes": [], "tags": [], "additional_answers": []},
{"id": "210554885", "person": "1042205947", "survey_type": "nps", "score": 5, "comment": "Test Comment201", "permalink": "https://app.delighted.com/r/GhWWrBT2wayswOc0AfT7fxpM3UwSpitN", "created_at": 1641289816, "updated_at": 1641289816, "person_properties": null, "notes": [], "tags": [], "additional_answers": []}
]
"""


UNSUBSCRIBES_RESPONSE = """
[
{"person_id": "1040826319", "email": "foo_test64@airbyte.io", "name": "Foo Test64", "unsubscribed_at": 1641289584}
]
"""


@pytest.mark.parametrize(
("stream_class", "url", "response_body"),
[
(Bounces, "https://api.delighted.com/v1/bounces.json", BOUNCES_RESPONSE),
(People, "https://api.delighted.com/v1/people.json", PEOPLE_RESPONSE),
(SurveyResponses, "https://api.delighted.com/v1/survey_responses.json", SURVEY_RESPONSES_RESPONSE),
(Unsubscribes, "https://api.delighted.com/v1/unsubscribes.json", UNSUBSCRIBES_RESPONSE),
],
)
@responses.activate
def test_not_output_records_where_cursor_field_equals_state(state, test_config, stream_class, url, response_body):
responses.add(
responses.GET,
url,
body=response_body,
status=200,
)

stream = stream_class(test_config["since"], authenticator=SourceDelighted()._get_authenticator(config=test_config))
records = [r for r in stream.read_records(SyncMode.incremental, stream_state=state[stream.name])]
assert not records


def test_example_method():
assert True

1 comment on commit 7bf1860

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SonarQube Report

SonarQube report for Airbyte Connectors Source Delighted(#9550)

Measures

Name Value Name Value Name Value
Code Smells 24 Security Rating A Lines to Cover 131
Lines of Code 200 Quality Gate Status OK Coverage 61.1
Reliability Rating A Bugs 0 Duplicated Blocks 0
Duplicated Lines (%) 0.0 Vulnerabilities 0 Blocker Issues 0
Critical Issues 0 Major Issues 3 Minor Issues 21

Detected Issues

Rule File Description Message
python:isort_need_format (MINOR) unit_tests/unit_test.py Please run one of the commands: "isort <path_to_updated_folder>" or "./gradlew format" 1 code part(s) should be updated.
flake8:E501 (MAJOR) unit_tests/unit_test.py:39 line too long (82 > 79 characters) line too long (197 > 140 characters)
flake8:E501 (MAJOR) unit_tests/unit_test.py:46 line too long (82 > 79 characters) line too long (319 > 140 characters)
flake8:E501 (MAJOR) unit_tests/unit_test.py:47 line too long (82 > 79 characters) line too long (318 > 140 characters)
python:mypy_no_untyped_def (MINOR) source_delighted/source.py:74 Check that every function has an annotation Function is missing a type annotation for one or more arguments . Code line: def parse_response(self, response: requests.Response, stream_state...
python:mypy_override (MINOR) source_delighted/source.py:74 Check that method override is compatible with base class Signature of "parse_response" incompatible with supertype "DelightedStream" . Code line: def parse_response(self, response: requests.Response, stream_state...
python:mypy_no_untyped_def (MINOR) source_delighted/source.py:85 Check that every function has an annotation Function is missing a type annotation for one or more arguments . Code line: def path(self, **kwargs) -> str:
python:mypy_return (MINOR) source_delighted/source.py:88 Check that function always returns a value Missing return statement . Code line: def next_page_token(self, response: requests.Response) -> Optional...
python:mypy_no_untyped_def (MINOR) source_delighted/source.py:103 Check that every function has an annotation Function is missing a type annotation for one or more arguments . Code line: def path(self, **kwargs) -> str:
python:mypy_no_untyped_def (MINOR) source_delighted/source.py:115 Check that every function has an annotation Function is missing a type annotation for one or more arguments . Code line: def path(self, **kwargs) -> str:
python:mypy_no_untyped_def (MINOR) source_delighted/source.py:126 Check that every function has an annotation Function is missing a type annotation for one or more arguments . Code line: def path(self, **kwargs) -> str:
python:isort_need_format (MINOR) main.py Please run one of the commands: "isort <path_to_updated_folder>" or "./gradlew format" 1 code part(s) should be updated.
python:mypy_no_untyped_def (MINOR) source_delighted/source.py:144 Check that every function has an annotation Function is missing a type annotation . Code line: def _get_authenticator(self, config):
python:mypy_no_untyped_def (MINOR) integration_tests/acceptance.py:12 Check that every function has an annotation Function is missing a return type annotation . Code line: def connector_setup():
python:mypy_import (MINOR) source_delighted/source.py:11 Require that imported module can be found or has stubs Library stubs not installed for "requests" (or incompatible with Python 3.7) . Code line: import requests
python:mypy_no_untyped_def (MINOR) source_delighted/source.py:30 Check that every function has an annotation Function is missing a type annotation for one or more arguments . Code line: def init(self, since: int, **kwargs):
python:mypy_return (MINOR) source_delighted/source.py:34 Check that function always returns a value Missing return statement . Code line: def next_page_token(self, response: requests.Response) -> Optional...
python:mypy_valid_type (MINOR) source_delighted/source.py:41 Check that type (annotation) is valid Function "builtins.any" is not valid as a type . Code line: ...e: Mapping[str, Any], stream_slice: Mapping[str, any] = None, next_pag...
python:mypy_no_untyped_def (MINOR) source_delighted/source.py:48 Check that every function has an annotation Function is missing a type annotation for one or more arguments . Code line: def parse_response(self, response: requests.Response, **kwargs) ->...
python:mypy_no_untyped_def (MINOR) source_delighted/source.py:55 Check that every function has an annotation Function is missing a return type annotation . Code line: def limit(self):
python:mypy_no_untyped_def (MINOR) source_delighted/source.py:67 Check that every function has an annotation Function is missing a type annotation . Code line: def request_params(self, stream_state=None, **kwargs):
python:mypy_no_untyped_def (MINOR) source_delighted/source.py:129 Check that every function has an annotation Function is missing a type annotation . Code line: def request_params(self, stream_state=None, **kwargs):
python:mypy_no_untyped_def (MINOR) source_delighted/source.py:148 Check that every function has an annotation Function is missing a type annotation for one or more arguments . Code line: def check_connection(self, logger, config) -> Tuple[bool, any]:
python:mypy_valid_type (MINOR) source_delighted/source.py:148 Check that type (annotation) is valid Function "builtins.any" is not valid as a type . Code line: def check_connection(self, logger, config) -> Tuple[bool, any]:

Coverage (61.1%)

File Coverage File Coverage
integration_tests/acceptance.py 0.0 main.py 0.0
setup.py 0.0 source_delighted/init.py 100.0
source_delighted/source.py 81.3 unit_tests/unit_test.py 0.0

Please sign in to comment.