Beispiel #1
0
    def test_revoke_session(self, monkeypatch):
        def json_request(verb, url, data={}, **kwargs):
            assert data.get('token', None) == 'TOKEN'
            return Promise.resolve({
                'code': 204,
                'headers': {},
                'content': None
            })

        monkeypatch.setattr(network, 'json_request', json_request)

        session = Session()
        session.refresh_token = 'TOKEN'
        p = session.revoke()
        assert session.refresh_token is None
        assert session.access_token is None
        assert p.result(0.001) is None
Beispiel #2
0
    def test_token_is_refreshed_when_it_expires(self, monkeypatch):
        """Test that the token is automatically refreshed if needed.

        The first DL request will fail with a '401' error.
        Then, the session should make a re-auth request, then eventually
        retry the DL.
        """
        network = MockSessionFunctions(monkeypatch)
        session = Session()
        session.access_token = 'EXPIRED_TOKEN'
        session.refresh_token = 'REFRESH_TOKEN'

        network.on('/path', MockTokenExpiredError())
        network.on('/token', network.auth_response())
        network.on('/path', network.ok_response('CONTENT'))

        p = session.download_storage_file('GET', '/path')
        assert p.result(0.001).get('content') == 'CONTENT'
        assert network.history == ['/path', '/token', '/path']