|
8 | 8 | from onvif.client import ONVIFCamera
|
9 | 9 | from onvif.settings import DEFAULT_SETTINGS
|
10 | 10 | from onvif.transport import ASYNC_TRANSPORT
|
| 11 | +from onvif.types import FastDateTime, ForgivingTime |
11 | 12 |
|
12 | 13 | INVALID_TERM_TIME = b'<?xml version="1.0" encoding="UTF-8"?>\r\n<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://www.w3.org/2003/05/soap-envelope" xmlns:SOAP-ENC="http://www.w3.org/2003/05/soap-encoding" xmlns:tev="http://www.onvif.org/ver10/events/wsdl" xmlns:wsnt="http://docs.oasis-open.org/wsn/b-2" xmlns:wsa5="http://www.w3.org/2005/08/addressing" xmlns:chan="http://schemas.microsoft.com/ws/2005/02/duplex" xmlns:wsa="http://www.w3.org/2005/08/addressing" xmlns:tt="http://www.onvif.org/ver10/schema" xmlns:tns1="http://www.onvif.org/ver10/topics">\r\n<SOAP-ENV:Header>\r\n<wsa5:Action>http://www.onvif.org/ver10/events/wsdl/PullPointSubscription/PullMessagesResponse</wsa5:Action>\r\n</SOAP-ENV:Header>\r\n<SOAP-ENV:Body>\r\n<tev:PullMessagesResponse>\r\n<tev:CurrentTime>2024-08-17T00:56:16Z</tev:CurrentTime>\r\n<tev:TerminationTime>2024-08-17T00:61:16Z</tev:TerminationTime>\r\n</tev:PullMessagesResponse>\r\n</SOAP-ENV:Body>\r\n</SOAP-ENV:Envelope>\r\n'
|
13 | 14 | _WSDL_PATH = os.path.join(os.path.dirname(os.path.dirname(__file__)), "onvif", "wsdl")
|
@@ -37,3 +38,30 @@ async def test_parse_invalid_time(caplog: pytest.LogCaptureFixture) -> None:
|
37 | 38 | 2024, 8, 17, 1, 1, 16, tzinfo=datetime.timezone.utc
|
38 | 39 | )
|
39 | 40 | assert "ValueError" not in caplog.text
|
| 41 | + |
| 42 | + |
| 43 | +def test_fix_datetime_overflow() -> None: |
| 44 | + assert FastDateTime().pythonvalue("2024-08-17T00:61:16Z") == datetime.datetime( |
| 45 | + 2024, 8, 17, 1, 1, 16, tzinfo=datetime.timezone.utc |
| 46 | + ) |
| 47 | + assert FastDateTime().pythonvalue("2024-08-17T00:60:16Z") == datetime.datetime( |
| 48 | + 2024, 8, 17, 1, 0, 16, tzinfo=datetime.timezone.utc |
| 49 | + ) |
| 50 | + assert FastDateTime().pythonvalue("2024-08-17T00:59:16Z") == datetime.datetime( |
| 51 | + 2024, 8, 17, 0, 59, 16, tzinfo=datetime.timezone.utc |
| 52 | + ) |
| 53 | + assert FastDateTime().pythonvalue("2024-08-17T23:59:59Z") == datetime.datetime( |
| 54 | + 2024, 8, 17, 23, 59, 59, tzinfo=datetime.timezone.utc |
| 55 | + ) |
| 56 | + assert FastDateTime().pythonvalue("2024-08-17T24:00:00Z") == datetime.datetime( |
| 57 | + 2024, 8, 18, 0, 0, 0, tzinfo=datetime.timezone.utc |
| 58 | + ) |
| 59 | + |
| 60 | + |
| 61 | +def test_fix_time_overflow() -> None: |
| 62 | + assert ForgivingTime().pythonvalue("24:00:00") == datetime.time(0, 0, 0) |
| 63 | + assert ForgivingTime().pythonvalue("23:59:59") == datetime.time(23, 59, 59) |
| 64 | + assert ForgivingTime().pythonvalue("23:59:60") == datetime.time(0, 0, 0) |
| 65 | + assert ForgivingTime().pythonvalue("23:59:61") == datetime.time(0, 0, 1) |
| 66 | + assert ForgivingTime().pythonvalue("23:60:00") == datetime.time(0, 0, 0) |
| 67 | + assert ForgivingTime().pythonvalue("23:61:00") == datetime.time(0, 1, 0) |
0 commit comments