Esempio n. 1
0
    def test_authorize(self, fetch_patched, input_patched):
        scope = [
            'https://www.googleapis.com/auth/photoslibrary.readonly',
            'https://www.googleapis.com/auth/photoslibrary.sharing',
        ]

        bad_file: Path = Path(__file__).absolute().parent.parent / \
                         'test_credentials' / '.no-token-here'
        token_file: Path = Path(__file__).absolute().parent.parent / \
                           'test_credentials' / '.gphotos.token'
        secrets_file: Path = Path(__file__).absolute().parent.parent / \
                             'test_credentials' / 'client_secret.json'
        test_data: Path = Path(__file__).absolute().parent.parent / 'test-data'

        if bad_file.exists():
            bad_file.unlink()
        with pytest.raises(SystemExit) as test_wrapped_e:
            a = auth.Authorize(scope, bad_file, bad_file)
        assert test_wrapped_e.type == SystemExit

        a = auth.Authorize(scope, bad_file, secrets_file)
        res = a.load_token()
        assert res is None

        a.authorize()
        assert a.token == 'dummy_token_string'
Esempio n. 2
0
    def test_http_500_retries(self):
        a = auth.Authorize(scope, token_file, secrets_file)
        a.authorize()

        start = datetime.now()

        result = a.session.get("https://httpbin.org/status/500", timeout=10)
        self.assertEqual(result.status_code, 500)
        elapsed = datetime.now() - start
        # timeout should not affect the 5 retries
        self.assertLess(elapsed.seconds, 10)
Esempio n. 3
0
    def test_download_timeout(self):
        a = auth.Authorize(scope, token_file, secrets_file)
        a.authorize()
        retry_error = False
        start = datetime.now()

        try:
            _ = a.session.get("https://httpbin.org//delay/5", stream=True, timeout=0.2)
        except exc.ConnectionError as e:
            retry_error = True
            print(e)

        elapsed = datetime.now() - start
        self.assertEqual(retry_error, True)
        # .2 timeout by 5 retries = 1 sec
        self.assertGreater(elapsed.seconds, 1)