def test_stream_running(): with pytest.raises(PyTwitterError): api = StreamApi(bearer_token="bearer token") api.running = True api.sample_stream() with pytest.raises(PyTwitterError): api = StreamApi(bearer_token="bearer token") api.running = True api.search_stream()
def test_stream_error(patched_time_sleep): responses.add( responses.Response( responses.GET, url="https://api.twitter.com/2/tweets/search/stream", stream=True, content_type="application/json", status=400, )) api = StreamApi(bearer_token="bearer token", max_retries=10) api.search_stream(backfill_minutes=1)
def test_initial_api(helpers): # test with not auth with pytest.raises(PyTwitterError): StreamApi() api = StreamApi(bearer_token="bearer token") token_data = helpers.load_json_data( "testdata/apis/authflow/bearer_token.json") responses.add(responses.POST, url="https://api.twitter.com/oauth2/token", json=token_data) api = StreamApi(consumer_key="consumer key", consumer_secret="consumer secret")
def test_generate_token(): responses.add( responses.POST, url="https://api.twitter.com/oauth2/token", json={ "errors": [{ "code": 99, "message": "Unable to verify your credentials", "label": "authenticity_token_error", }] }, status=403, ) with pytest.raises(PyTwitterError): StreamApi(consumer_key="error", consumer_secret="error")
def stream_api(): return StreamApi(bearer_token="bearer token")