2024-05-31 14:58:46 +03:00
|
|
|
import socket
|
|
|
|
import urllib
|
|
|
|
|
2024-05-31 15:09:48 +03:00
|
|
|
from functools import partial
|
2024-05-31 14:58:46 +03:00
|
|
|
from unittest import TestCase
|
|
|
|
|
2024-05-31 15:09:48 +03:00
|
|
|
import models
|
|
|
|
import fixtures
|
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'
|
|
|
|
|
2024-05-31 15:09:48 +03:00
|
|
|
nm_req = partial(
|
|
|
|
models.create_nm_req,
|
|
|
|
fixtures.device_mac,
|
|
|
|
fixtures.device_name,
|
|
|
|
fixtures.sensors,
|
|
|
|
)
|
|
|
|
|
|
|
|
json_req = None # TODO
|
|
|
|
|
2024-05-31 14:58:46 +03:00
|
|
|
|
|
|
|
class TestTCP(TestCase):
|
|
|
|
|
|
|
|
def setUp(self) -> None:
|
|
|
|
self.sock = socket.socket()
|
|
|
|
self.sock.connect(TCP_ADDR)
|
|
|
|
|
|
|
|
def test_nm(self) -> None:
|
2024-05-31 15:09:48 +03:00
|
|
|
self.sock.sendall(nm_req().encode('utf-8'))
|
2024-05-31 14:58:46 +03:00
|
|
|
self._wait_for_ok()
|
|
|
|
|
|
|
|
def test_json(self) -> None:
|
|
|
|
self.sock.sendall(b'') # TODO
|
|
|
|
self._wait_for_ok()
|
|
|
|
|
|
|
|
def _wait_for_ok(self) -> None:
|
|
|
|
data = self.sock.recv(1024)
|
|
|
|
self.assertEqual(data, b'OK')
|