-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
client: add method to stream messages asynchronously
- Loading branch information
Showing
2 changed files
with
112 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
from io import BytesIO | ||
from datetime import datetime | ||
from unittest.mock import MagicMock, patch | ||
|
||
from mcap.records import Schema, Channel, Message | ||
|
||
from foxglove_data_platform.client import Client | ||
|
||
from .generate import generate_json_data | ||
|
||
|
||
def get_generated_data(url, **kwargs): | ||
assert url == "the_link" | ||
|
||
class Resp: | ||
def __init__(self): | ||
self.raw = BytesIO(generate_json_data()) | ||
|
||
def raise_for_status(self): | ||
return None | ||
|
||
return Resp() | ||
|
||
|
||
@patch("requests.get", side_effect=get_generated_data) | ||
def test_boot(arg): | ||
client = Client("test") | ||
client._make_stream_link = MagicMock(return_value="the_link") | ||
count = 0 | ||
for schema, channel, message, decoded_message in client.iter_messages( | ||
device_id="test_id", start=datetime.now(), end=datetime.now() | ||
): | ||
assert "level" in decoded_message | ||
assert isinstance(schema, Schema) | ||
assert isinstance(channel, Channel) | ||
assert isinstance(message, Message) | ||
count += 1 | ||
|
||
assert count == 10 |