tests/main.py

45 lines
1,003 B
Python
Raw Normal View History

2024-05-31 14:58:46 +03:00
import socket
2024-05-31 15:22:25 +03:00
from urllib.request import urlopen, Request
2024-05-31 14:58:46 +03:00
from unittest import TestCase
2024-05-31 16:49:44 +03:00
from fixtures import device
2024-05-31 14:58:46 +03:00
TCP_ADDR = ('127.0.0.1', 8283)
UDP_ADDR = ('127.0.0.1', 8283)
HTTP_URL = 'http://127.0.0.1:8080'
class TestTCP(TestCase):
def setUp(self) -> None:
self.sock = socket.socket()
self.sock.connect(TCP_ADDR)
def test_nm(self) -> None:
2024-05-31 16:49:44 +03:00
self.sock.sendall(device.nm_req_data().encode())
2024-05-31 14:58:46 +03:00
self._wait_for_ok()
def test_json(self) -> None:
2024-05-31 15:20:25 +03:00
raise NotImplemented
2024-05-31 14:58:46 +03:00
def _wait_for_ok(self) -> None:
data = self.sock.recv(1024)
self.assertEqual(data, b'OK')
2024-05-31 15:22:25 +03:00
class TestHTTP(TestCase):
2024-05-31 16:49:44 +03:00
def test_get(self) -> None:
self._send_and_check(Request(
HTTP_URL + '/get?' + device.http_req_data(),
))
2024-05-31 15:22:25 +03:00
def test_json(self) -> None:
raise NotImplemented
def _send_and_check(self, req: Request) -> None:
with urlopen(req) as resp:
self.assertEqual(resp.status, 200)