feat: add native API client for common submission use case
this should work for simple API endpoint which requires an auth token. if more is needed, you'll have to override telemetry handler
This commit is contained in:
parent
e0dd704247
commit
0f42626cb1
7 changed files with 437 additions and 5 deletions
|
@ -1,6 +1,6 @@
|
|||
# -*- coding: utf-8; -*-
|
||||
|
||||
from unittest.mock import patch
|
||||
from unittest.mock import patch, MagicMock
|
||||
|
||||
from wuttjamaican.testing import ConfigTestCase
|
||||
|
||||
|
@ -160,9 +160,24 @@ class TestTelemetryHandler(ConfigTestCase):
|
|||
self.assertNotIn('errors', data)
|
||||
|
||||
def test_submit_all_data(self):
|
||||
profile = self.handler.get_profile('default')
|
||||
profile.submit_url = '/testing'
|
||||
|
||||
# not (yet?) implemented
|
||||
self.assertRaises(NotImplementedError, self.handler.submit_all_data)
|
||||
with patch.object(mod, 'SimpleAPIClient') as SimpleAPIClient:
|
||||
client = MagicMock()
|
||||
SimpleAPIClient.return_value = client
|
||||
|
||||
# collecting all data
|
||||
with patch.object(self.handler, 'collect_all_data') as collect_all_data:
|
||||
collect_all_data.return_value = []
|
||||
self.handler.submit_all_data(profile)
|
||||
collect_all_data.assert_called_once_with(profile)
|
||||
client.post.assert_called_once_with('/testing', data=[])
|
||||
|
||||
# use data from caller
|
||||
client.post.reset_mock()
|
||||
self.handler.submit_all_data(profile, data=['foo'])
|
||||
client.post.assert_called_once_with('/testing', data=['foo'])
|
||||
|
||||
|
||||
class TestTelemetryProfile(ConfigTestCase):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue