]> www.average.org Git - loctrkd.git/commitdiff
test: opencellid downloader
authorEugene Crosser <crosser@average.org>
Wed, 22 Jun 2022 15:55:43 +0000 (17:55 +0200)
committerEugene Crosser <crosser@average.org>
Wed, 22 Jun 2022 15:55:43 +0000 (17:55 +0200)
test/common.py
test/test_ocid_dload.py [new file with mode: 0644]
test/test_storage.py

index 434fef947adf0327724e5a9c1caf28388fb9491f..b9f768c8f55d84573a9149f5de248f955039d32b 100644 (file)
@@ -2,6 +2,7 @@
 
 from configparser import ConfigParser, SectionProxy
 from contextlib import closing, ExitStack
+from http.server import HTTPServer, SimpleHTTPRequestHandler
 from importlib import import_module
 from multiprocessing import Process
 from os import kill, unlink
@@ -15,6 +16,7 @@ from socket import (
     socket,
     SocketType,
 )
+from sys import exit
 from tempfile import mkstemp
 from time import sleep
 from typing import Optional
@@ -44,6 +46,7 @@ class TestWithServers(TestCase):
         }
         self.conf["opencellid"] = {
             "dbfn": self.tmpfilebase + ".opencellid.sqlite",
+            "downloadurl": f"http://localhost:{freeports[2]}/test/262.csv.gz",
         }
         self.conf["lookaside"] = {
             "backend": "opencellid",
@@ -62,7 +65,18 @@ class TestWithServers(TestCase):
             p.start()
             self.children.append((srvname, p))
         if httpd:
-            pass
+            server = HTTPServer(("", freeports[2]), SimpleHTTPRequestHandler)
+
+            def run(server):
+                try:
+                    server.serve_forever()
+                except KeyboardInterrupt:
+                    # TODO: this still leaves unclosed socket in the server
+                    server.shutdown()
+
+            p = Process(target=run, args=(server,))
+            p.start()
+            self.children.append(("httpd", p))
         sleep(1)
 
     def tearDown(self) -> None:
diff --git a/test/test_ocid_dload.py b/test/test_ocid_dload.py
new file mode 100644 (file)
index 0000000..0089ce0
--- /dev/null
@@ -0,0 +1,27 @@
+""" Send junk to the collector """
+
+from sqlite3 import connect
+from time import sleep
+from typing import Any
+import unittest
+from .common import send_and_drain, TestWithServers
+from gps303 import ocid_dload
+
+
+class Ocid_Dload(TestWithServers):
+    def setUp(self, *args: str, **kwargs: Any) -> None:
+        super().setUp(httpd=True)
+
+    def tearDown(self) -> None:
+        sleep(1)  # give collector some time
+        super().tearDown()
+
+    def test_ocid_dload(self) -> None:
+        ocid_dload.main(self.conf)
+        with connect(self.conf.get("opencellid", "dbfn")) as db:
+            (count,) = db.execute("select count(*) from cells").fetchone()
+        self.assertEqual(count, 163)
+
+
+if __name__ == "__main__":
+    unittest.main()
index 80ccba61fed7ad87a373162bcdea545526c77030..98366aa8d4cf60e59981125118a0c21ee749b3d9 100644 (file)
@@ -2,7 +2,7 @@
 
 from random import Random
 from socket import getaddrinfo, socket, AF_INET, SOCK_STREAM
-from sqlite3 import connect, Row
+from sqlite3 import connect
 from time import sleep
 from typing import Any
 import unittest
@@ -38,7 +38,6 @@ class Storage(TestWithServers):
         sleep(1)
         got = set()
         with connect(self.conf.get("storage", "dbfn")) as db:
-            db.row_factory = Row
             for is_incoming, packet in db.execute(
                 "select is_incoming, packet from events"
             ):