def test_cannot_get_data_without_channel(self): api = ThingSpeakApi( key='ABCDEFGHIJKLMNOPQRST', base_url='https://api.example.com:6666' ) with responses.RequestsMock() as r_mock, \ pytest.raises(ConfigurationError): data = api.get_data() assert len(r_mock.calls) == 0
def test_get_data_connection_error(self): api = ThingSpeakApi( channel=666, base_url='https://api.example.com:6666' ) with responses.RequestsMock() as r_mock: r_mock.add( r_mock.GET, 'https://api.example.com:6666/channels/666/feed/last.json', body=requests.exceptions.ConnectionError() ) with pytest.raises(requests.exceptions.ConnectionError): _ = api.get_data() assert len(r_mock.calls) == 1 assert r_mock.calls[0].request.url == 'https://api.example.com:6666/channels/666/feed/last.json' assert type(r_mock.calls[0].response) is requests.exceptions.ConnectionError
def test_can_get_data_without_key(self): api = ThingSpeakApi( channel=666, base_url='https://api.example.com:6666' ) with responses.RequestsMock() as r_mock: r_mock.add( r_mock.GET, 'https://api.example.com:6666/channels/666/feed/last.json', json=canned_responses['last.json'] ) data = api.get_data() assert len(r_mock.calls) == 1 the_request = r_mock.calls[0].request assert the_request.url == 'https://api.example.com:6666/channels/666/feed/last.json' assert 'X-THINGSPEAKAPIKEY' not in the_request.headers assert data['created_at'] == '2016-01-27T20:52:10Z' assert data['field1'] == '58.5 F'