Update tests (see "refactor" commit)

This commit is contained in:
DarkCat09 2024-05-31 17:49:44 +04:00
parent ef41123264
commit 3668a917a7
Signed by: DarkCat09
GPG key ID: 0A26CD5B3345D6E3

26
main.py
View file

@ -1,26 +1,15 @@
import socket import socket
from urllib.request import urlopen, Request from urllib.request import urlopen, Request
from functools import partial
from unittest import TestCase from unittest import TestCase
import models from fixtures import device
import fixtures
TCP_ADDR = ('127.0.0.1', 8283) TCP_ADDR = ('127.0.0.1', 8283)
UDP_ADDR = ('127.0.0.1', 8283) UDP_ADDR = ('127.0.0.1', 8283)
HTTP_URL = 'http://127.0.0.1:8080' HTTP_URL = 'http://127.0.0.1:8080'
nm_req = partial(
models.create_nm_req,
fixtures.device_mac,
fixtures.device_name,
fixtures.sensors,
)
json_req = None # TODO
class TestTCP(TestCase): class TestTCP(TestCase):
@ -29,7 +18,7 @@ class TestTCP(TestCase):
self.sock.connect(TCP_ADDR) self.sock.connect(TCP_ADDR)
def test_nm(self) -> None: def test_nm(self) -> None:
self.sock.sendall(nm_req()) self.sock.sendall(device.nm_req_data().encode())
self._wait_for_ok() self._wait_for_ok()
def test_json(self) -> None: def test_json(self) -> None:
@ -42,13 +31,10 @@ class TestTCP(TestCase):
class TestHTTP(TestCase): class TestHTTP(TestCase):
def test_nm(self) -> None: def test_get(self) -> None:
req = Request( self._send_and_check(Request(
url=(HTTP_URL + '/get'), HTTP_URL + '/get?' + device.http_req_data(),
data=nm_req(), ))
method='GET',
)
self._send_and_check(req)
def test_json(self) -> None: def test_json(self) -> None:
raise NotImplemented raise NotImplemented