Exemple #1
0
    def test_500_backend_triggers_no_retry(self, mocked_time_sleep, mocked_session_post, mocked_session_request, mocked_request_post):
        client = Client(self.config, self.config_path)
        with self.assertRaisesRegex(requests.exceptions.RequestException, 'Raise for status'):
            client.post("500-INTERNAL")

        # Assert we gave up only after the first try
        self.assertEqual(mocked_session_post.call_count, 2)
Exemple #2
0
    def test_403_backend_triggers_no_retry(self, mocked_time_sleep, mocked_session_post, mocked_session_request, mocked_request_post):
        client = Client(self.config, self.config_path)
        with self.assertRaisesRegex(Exception, 'Client Error, error message'):
            client.post("403-PERMISSION_DENIED")

        # Assert we gave up only after the first try
        self.assertEqual(mocked_session_post.call_count, 2)
Exemple #3
0
    def test_503_unavailable_triggers_retry_backoff(self, mocked_time_sleep, mocked_session_post, mocked_session_request, mocked_request_post):
        client = Client(self.config, self.config_path)
        with self.assertRaisesRegex(requests.exceptions.RequestException, 'Raise for status'):
            client.post("503-UNAVAILABLE")

        # Assert we retried 3 times until failing the last one
        # max tries = 4
        self.assertEqual(mocked_session_post.call_count, 5)
Exemple #4
0
    def test_429_triggers_retry_backoff(self, mocked_time_sleep, mocked_session_post, mocked_session_request, mocked_request_post):
        client = Client(self.config, self.config_path)
        with self.assertRaisesRegex(requests.exceptions.RequestException, 'Raise for status'):
            client.post("429-RESOURCE_EXHAUSTED")

        # Assert we retried 3 times until failing the last one
        # max tries = 4
        self.assertEqual(mocked_session_post.call_count, 5)
Exemple #5
0
    def test_timeout_error_get_retry(self, mocked_time_sleep, mocked_session_post, mocked_session_request, mocked_request_post):
        '''
            Verify that timeout error is retrying for 4 times for get call
        '''
        client = Client(self.config, self.config_path)
        with self.assertRaises(requests.exceptions.Timeout):
            client.get("TimeoutError")

        # Get request(Session.request) called 5 times (4 for backoff + 1 for _populate_profile_lookup())
        self.assertEqual(mocked_session_request.call_count, 5)
Exemple #6
0
    def test_timeout_error_post_retry(self, mocked_time_sleep, mocked_session_post, mocked_session_request, mocked_request_post):
        '''
            Verify that timeout error is retrying for 4 times for post call
        '''
        client = Client(self.config, self.config_path)
        with self.assertRaises(requests.exceptions.Timeout):
            client.post("TimeoutError")

        # Post request(Session.post) called 5 times (4 for backoff + 1 for _ensure_access_token())
        self.assertEqual(mocked_session_post.call_count, 5)
Exemple #7
0
 def test_keepalive_on_session_request(self):
     client = Client(self.config, self.config_path)
     self.assertEqual(self.request_spy.call_args[1].get('headers', {}).get('Connection'), 'keep-alive')
from singer import get_logger

from tap_google_analytics.client import Client

LOGGER = get_logger()

# 1. Get config from file and create client
with open('/tmp/tap_config.json', 'r') as f:
    config = json.load(f)

if "refresh_token" in config:  # if refresh_token in config assume OAuth2 credentials
    config['auth_method'] = "oauth2"
else:  # otherwise, assume Service Account details should be present
    config['auth_method'] = "service_account"

client = Client(config)

# 2. Configure these to match what you want to test
metrics = [
    'ga:users', 'ga:bounceRate', 'ga:pageviewsPerSession',
    'ga:avgSessionDuration', 'ga:sessions', 'ga:newUsers'
]
dimensions = [
    'ga:acquisitionSource', 'ga:acquisitionSourceMedium',
    'ga:acquisitionMedium', 'ga:acquisitionTrafficChannel', 'ga:date'
]
profile_id = config['view_id']
report_date = datetime.datetime(2019, 2, 26)

# 3. Attempt all combinations (order-indepedent) of metrics and dimensions, saving successes in file_name
file_name = "successful_mets_dims.jsonl"