Skip to content

Commit

Permalink
#12591 source zendesk: fix unittest fixture
Browse files Browse the repository at this point in the history
  • Loading branch information
davydov-d committed May 27, 2022
1 parent d172cd5 commit f3d2ae4
Showing 1 changed file with 21 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,40 +3,46 @@
#

import json
import pytest
from typing import Any, Dict, Mapping

import requests
from source_zendesk_support.source import SourceZendeskSupport
from source_zendesk_support.streams import Users


def read_config(config_path: str) -> Mapping[str, Any]:
"""
Get the config from /test_input
"""
with open(config_path, "r") as f:
return json.loads(f.read())
@pytest.fixture(scope="session", name="config")
def test_config():
config = {
"subdomain": "sandbox",
"start_date": "2021-06-01T00:00:00Z",
"credentials": {
"credentials": "api_token",
"email": "integration-test@airbyte.io",
"api_token": "api_token"
}
}
return config


def prepare_config(config: Dict):
return SourceZendeskSupport().convert_config2stream_args(config)


# create client
config = prepare_config(read_config("secrets/config.json"))
# test stream
TEST_STREAM = Users(**config)


def test_backoff(requests_mock):
def test_backoff(requests_mock, config):
""" """
test_response_header = {"Retry-After": "5", "X-Rate-Limit": "0"}
test_response_json = {"count": {"value": 1, "refreshed_at": "2022-03-29T10:10:51+00:00"}}
expected = int(test_response_header.get("Retry-After"))

url = f"{TEST_STREAM.url_base}{TEST_STREAM.path()}/count.json"
# create client
config = prepare_config(config)
# test stream
test_stream = Users(**config)

url = f"{test_stream.url_base}{test_stream.path()}/count.json"
requests_mock.get(url, json=test_response_json, headers=test_response_header, status_code=429)
test_response = requests.get(url)

actual = TEST_STREAM.backoff_time(test_response)
actual = test_stream.backoff_time(test_response)
assert actual == expected

0 comments on commit f3d2ae4

Please sign in to comment.