generated from BrandonElectronic/ESP-PROJECT-TEMPLATE
-
Notifications
You must be signed in to change notification settings - Fork 1
/
pytest_esp32-ip-to-geolocation.py
50 lines (43 loc) · 1.39 KB
/
pytest_esp32-ip-to-geolocation.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# SPDX-FileCopyrightText: 2022-2024 Hays Chan
# SPDX-License-Identifier: MIT
'''
Steps to run these cases:
- Build
- . ${IDF_PATH}/export.sh
- pip install idf_build_apps
- python tools/build_apps.py components/button/test_apps -t esp32
- Test
- pip install -r tools/requirements/requirement.pytest.txt
- pytest components/button/test_apps --target esp32
'''
import pytest
from pytest_embedded import Dut
@pytest.mark.supported_targets("esp32") # Specify the target, esp32 in this case
def test_esp32_ip_to_geolocation(dut: Dut):
# Start the test
dut.expect_exact("wifi_init_sta finished.")
dut.expect("connected to ap SSID:Wokwi-GUEST")
# Check for a successful HTTP request
dut.expect("HTTP GET Status = 200, content_length = ")
# Check for the expected logs from the JSON response
expected_keys = [
"status:",
"country:",
"countryCode:",
"region:",
"regionName:",
"city:",
"zip:",
"lat:",
"lon:",
"timezone:",
"isp:",
"org:",
"as:",
"query:"
]
# Check each expected log entry for presence only, not specific content
for key in expected_keys:
dut.expect(key)
# Optionally, check for completion of the HTTP task or any other specific logs
dut.expect("HTTP request completed successfully") # Modify based on actual log message on success