pytest_http_request.py 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  1. #!/usr/bin/env python
  2. #
  3. # SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD
  4. # SPDX-License-Identifier: Apache-2.0
  5. import logging
  6. import os
  7. import pytest
  8. from pytest_embedded import Dut
  9. @pytest.mark.esp32
  10. @pytest.mark.ethernet
  11. def test_examples_protocol_http_request(dut: Dut) -> None:
  12. """
  13. steps: |
  14. 1. join AP/Ethernet
  15. 2. connect to example.com
  16. 3. check conneciton success
  17. """
  18. # check and log bin size
  19. binary_file = os.path.join(dut.app.binary_path, 'http_request.bin')
  20. bin_size = os.path.getsize(binary_file)
  21. logging.info('http_request_bin_size : {}KB'.format(bin_size // 1024))
  22. # start test
  23. dut.expect(r'DNS lookup succeeded.', timeout=30)
  24. # check if connected or not
  25. dut.expect(' ... connected', timeout=60)
  26. dut.expect(' ... socket send success')
  27. dut.expect(' ... set socket receiving timeout success')
  28. # check server response
  29. dut.expect(r'HTTP/1.0 200 OK')
  30. # read from the socket completed
  31. dut.expect('... done reading from socket. Last read return=0 errno=128')
  32. dut.expect(r'(\d)...')