|
| 1 | +from datetime import datetime |
| 2 | + |
1 | 3 | import pytest |
2 | 4 |
|
3 | 5 | from shellhub.exceptions import ShellHubApiError |
@@ -118,16 +120,48 @@ def test_get_device(self, shellhub, requests_mock): |
118 | 120 | == "-----BEGIN RSA PUBLIC KEY-----\nxxx\nxxx\nxxx\nxxx\nxxx\nxxx\n-----END RSA PUBLIC KEY-----\n" |
119 | 121 | ) |
120 | 122 | assert device.tenant_id == "1" |
121 | | - assert device.last_seen == "1970-01-01T00:00:00Z" |
| 123 | + assert device.last_seen == datetime.fromisoformat("1970-01-01T00:00:00Z") |
122 | 124 | assert device.online |
123 | 125 | assert device.namespace == "dev" |
124 | 126 | assert device.status == "accepted" |
125 | | - assert device.status_updated_at == "1970-01-01T00:00:00Z" |
126 | | - assert device.created_at == "1970-01-01T00:00:00Z" |
| 127 | + assert device.status_updated_at == datetime.fromisoformat("1970-01-01T00:00:00Z") |
| 128 | + assert device.created_at == datetime.fromisoformat("1970-01-01T00:00:00Z") |
127 | 129 | assert device.remote_addr == "0.0.0.0" |
128 | 130 | assert device.tags == [] |
129 | 131 | assert not device.acceptable |
130 | 132 |
|
| 133 | + def test_get_incorrect_datetime_format(self, shellhub, requests_mock): |
| 134 | + mock_response = { |
| 135 | + "uid": "1", |
| 136 | + "name": "default", |
| 137 | + "identity": {"mac": "06:04:ju:le:s7:08"}, |
| 138 | + "info": { |
| 139 | + "id": "ubuntu", |
| 140 | + "pretty_name": "Ubuntu 20.04.2 LTS", |
| 141 | + "version": "v0.14.1", |
| 142 | + "arch": "amd64", |
| 143 | + "platform": "docker", |
| 144 | + }, |
| 145 | + "public_key": "-----BEGIN RSA PUBLIC KEY-----\nxxx\nxxx\nxxx\n" |
| 146 | + "xxx\nxxx\nxxx\n-----END RSA PUBLIC KEY-----\n", |
| 147 | + "tenant_id": "1", |
| 148 | + "last_seen": "-1", |
| 149 | + "online": True, |
| 150 | + "namespace": "dev", |
| 151 | + "status": "accepted", |
| 152 | + "status_updated_at": "-1", |
| 153 | + "created_at": "-1", |
| 154 | + "remote_addr": "0.0.0.0", |
| 155 | + "position": {"latitude": 0, "longitude": 0}, |
| 156 | + "tags": [], |
| 157 | + "public_url": False, |
| 158 | + "public_url_address": "", |
| 159 | + "acceptable": False, |
| 160 | + } |
| 161 | + requests_mock.get(f"{MOCKED_DOMAIN_URL}/api/devices/1", json=mock_response) |
| 162 | + with pytest.raises(ShellHubApiError): |
| 163 | + shellhub.get_device("1") |
| 164 | + |
131 | 165 |
|
132 | 166 | class TestDeleteDevice: |
133 | 167 | def test_delete_device(self, shellhub_device, requests_mock): |
|
0 commit comments