-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for timestamp in headers
It uses the **kwargs argument we have for request/response/event If time_ms_epoch is None => no timestamp in protobuf object If time_ms_epoch is 0 => Automatically added in object creation (default) If time_ms_epoch is set => Used as is
- Loading branch information
1 parent
2109876
commit 5a83035
Showing
16 changed files
with
201 additions
and
30 deletions.
There are no files selected for viewing
Submodule backend-apis
updated
129 files
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 |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
|
||
import wirepas_mesh_messaging | ||
from default_value import * | ||
import time | ||
|
||
DUMMY_CONFIGS = [NODE_CONFIG_1] | ||
|
||
|
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,122 @@ | ||
# flake8: noqa | ||
|
||
import wirepas_mesh_messaging | ||
from default_value import * | ||
import time | ||
|
||
now_ms = int(time.time() * 1000) | ||
|
||
def test_automatic_timestamp_request(): | ||
request = wirepas_mesh_messaging.UploadScratchpadRequest( | ||
SCRATCHPAD_SEQ, SINK_ID, REQUEST_ID | ||
) | ||
|
||
assert request.time_ms_epoch <= time.time() * 1000 | ||
|
||
request2 = wirepas_mesh_messaging.UploadScratchpadRequest.from_payload( | ||
request.payload | ||
) | ||
|
||
for k, v in request.__dict__.items(): | ||
assert v == request2.__dict__[k] | ||
|
||
def test_no_timestamp_request(): | ||
request = wirepas_mesh_messaging.UploadScratchpadRequest( | ||
SCRATCHPAD_SEQ, SINK_ID, REQUEST_ID, time_ms_epoch=None | ||
) | ||
|
||
assert request.time_ms_epoch == None | ||
|
||
request2 = wirepas_mesh_messaging.UploadScratchpadRequest.from_payload( | ||
request.payload | ||
) | ||
|
||
for k, v in request.__dict__.items(): | ||
assert v == request2.__dict__[k] | ||
|
||
def test_timestamp_request(): | ||
request = wirepas_mesh_messaging.UploadScratchpadRequest( | ||
SCRATCHPAD_SEQ, SINK_ID, REQUEST_ID, time_ms_epoch = now_ms | ||
) | ||
|
||
assert request.time_ms_epoch == now_ms | ||
|
||
request2 = wirepas_mesh_messaging.UploadScratchpadRequest.from_payload( | ||
request.payload | ||
) | ||
|
||
for k, v in request.__dict__.items(): | ||
assert v == request2.__dict__[k] | ||
|
||
|
||
def test_automatic_timestamp_response(): | ||
response = wirepas_mesh_messaging.UploadScratchpadResponse( | ||
REQUEST_ID, GATEWAY_ID, RES_OK, SINK_ID | ||
) | ||
|
||
assert response.time_ms_epoch <= time.time() * 1000 | ||
|
||
response2 = wirepas_mesh_messaging.UploadScratchpadResponse.from_payload( | ||
response.payload | ||
) | ||
|
||
for k, v in response.__dict__.items(): | ||
assert v == response2.__dict__[k] | ||
|
||
def test_no_timestamp_response(): | ||
response = wirepas_mesh_messaging.UploadScratchpadResponse( | ||
REQUEST_ID, GATEWAY_ID, RES_OK, SINK_ID, time_ms_epoch = None | ||
) | ||
|
||
assert response.time_ms_epoch == None | ||
|
||
response2 = wirepas_mesh_messaging.UploadScratchpadResponse.from_payload( | ||
response.payload | ||
) | ||
|
||
for k, v in response.__dict__.items(): | ||
assert v == response2.__dict__[k] | ||
|
||
def test_timestamp_response(): | ||
response = wirepas_mesh_messaging.UploadScratchpadResponse( | ||
REQUEST_ID, GATEWAY_ID, RES_OK, SINK_ID, time_ms_epoch = now_ms | ||
) | ||
|
||
assert response.time_ms_epoch == now_ms | ||
|
||
response2 = wirepas_mesh_messaging.UploadScratchpadResponse.from_payload( | ||
response.payload | ||
) | ||
|
||
for k, v in response.__dict__.items(): | ||
assert v == response2.__dict__[k] | ||
|
||
def test_automatic_timestamp_event(): | ||
status = wirepas_mesh_messaging.StatusEvent(GATEWAY_ID, GATEWAY_STATE) | ||
|
||
assert status.time_ms_epoch <= time.time() * 1000 | ||
|
||
status2 = wirepas_mesh_messaging.StatusEvent.from_payload(status.payload) | ||
|
||
for k, v in status.__dict__.items(): | ||
assert v == status2.__dict__[k] | ||
|
||
def test_no_timestamp_event(): | ||
status = wirepas_mesh_messaging.StatusEvent(GATEWAY_ID, GATEWAY_STATE, time_ms_epoch = None) | ||
|
||
assert status.time_ms_epoch == None | ||
|
||
status2 = wirepas_mesh_messaging.StatusEvent.from_payload(status.payload) | ||
|
||
for k, v in status.__dict__.items(): | ||
assert v == status2.__dict__[k] | ||
|
||
def test__timestamp_event(): | ||
status = wirepas_mesh_messaging.StatusEvent(GATEWAY_ID, GATEWAY_STATE, time_ms_epoch = now_ms) | ||
|
||
assert status.time_ms_epoch == now_ms | ||
|
||
status2 = wirepas_mesh_messaging.StatusEvent.from_payload(status.payload) | ||
|
||
for k, v in status.__dict__.items(): | ||
assert v == status2.__dict__[k] |
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
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
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
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
Oops, something went wrong.