57 lines
1.9 KiB
Python
57 lines
1.9 KiB
Python
import http.client
|
|
import subprocess
|
|
import sys
|
|
import time
|
|
import unittest
|
|
from pathlib import Path
|
|
|
|
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
|
|
|
|
class UpdateServerTests(unittest.TestCase):
|
|
@classmethod
|
|
def setUpClass(cls):
|
|
cls.process = subprocess.Popen([sys.executable, "service/server.py", "18080"], cwd=ROOT)
|
|
for _ in range(50):
|
|
try:
|
|
conn = http.client.HTTPConnection("127.0.0.1", 18080, timeout=1)
|
|
conn.request("GET", "/healthz")
|
|
if conn.getresponse().status == 200:
|
|
conn.close()
|
|
return
|
|
except OSError:
|
|
pass
|
|
time.sleep(0.1)
|
|
raise RuntimeError("update server did not start")
|
|
|
|
@classmethod
|
|
def tearDownClass(cls):
|
|
cls.process.terminate()
|
|
cls.process.wait(timeout=5)
|
|
|
|
def get(self, path):
|
|
conn = http.client.HTTPConnection("127.0.0.1", 18080, timeout=5)
|
|
conn.request("GET", path)
|
|
response = conn.getresponse()
|
|
result = response.status, response.getheader("Content-Type"), response.read()
|
|
conn.close()
|
|
return result
|
|
|
|
def test_latest_channel_wire_format(self):
|
|
status, content_type, body = self.get("/routeros/NEWESTa7.stable?version=7.23.8")
|
|
self.assertEqual(status, 200)
|
|
self.assertTrue(content_type.startswith("text/plain"))
|
|
self.assertEqual(body, b"7.25.1 1793623193\n")
|
|
|
|
def test_old_series_is_available_for_changelog(self):
|
|
status, content_type, body = self.get("/routeros/7.23.8/CHANGELOG")
|
|
self.assertEqual(status, 200)
|
|
self.assertTrue(content_type.startswith("text/plain"))
|
|
self.assertTrue(body.startswith(b"What's new in 7.23.8"))
|
|
|
|
def test_unknown_channel_does_not_claim_a_release(self):
|
|
status, _, body = self.get("/routeros/NEWESTa7.development")
|
|
self.assertEqual(status, 200)
|
|
self.assertIn(b"No version available", body)
|