mirror of
https://github.com/aclist/dztui.git
synced 2026-11-01 23:52:47 +01:00
chore: update tests
This commit is contained in:
1 parent
33b8dfba70
commit
78144e9127
1 file changed
+44
-7
+44
-7
@@ -1,16 +1,40 @@
|
|||||||
from dzgui.config.ipdb import get_ipdb
|
|
||||||
from pathlib import Path
|
|
||||||
import os
|
import os
|
||||||
|
import sqlite3
|
||||||
import pytest
|
import pytest
|
||||||
import tempfile
|
import tempfile
|
||||||
|
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
from dzgui.const.endpoints import DB_IP
|
||||||
|
from dzgui.config.ipdb import (
|
||||||
|
create_table,
|
||||||
|
find_download_url,
|
||||||
|
serialize,
|
||||||
|
strip_ipv6,
|
||||||
|
unzip,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def get_db_len(path: Path) -> int:
|
||||||
|
conn = sqlite3.connect(path)
|
||||||
|
c = conn.cursor()
|
||||||
|
c.execute("SELECT COUNT(*) from ips")
|
||||||
|
db_len = c.fetchone()[0]
|
||||||
|
return db_len
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def csv() -> Path:
|
||||||
|
csv = Path(tempfile.NamedTemporaryFile().name)
|
||||||
|
url = find_download_url(DB_IP)
|
||||||
|
tmp = serialize(url)
|
||||||
|
unzip(tmp, csv)
|
||||||
|
strip_ipv6(csv)
|
||||||
|
return csv
|
||||||
|
|
||||||
@pytest.mark.slow
|
@pytest.mark.slow
|
||||||
def test_stripping():
|
def test_stripping(csv):
|
||||||
d = tempfile.TemporaryDirectory()
|
with open(csv, "rb") as f:
|
||||||
path = Path(d.name).joinpath("ips.csv")
|
|
||||||
get_ipdb(path)
|
|
||||||
with open(path, "rb") as f:
|
|
||||||
first = f.readline().decode().rstrip()
|
first = f.readline().decode().rstrip()
|
||||||
try:
|
try:
|
||||||
f.seek(-2, os.SEEK_END)
|
f.seek(-2, os.SEEK_END)
|
||||||
@@ -25,3 +49,16 @@ def test_stripping():
|
|||||||
|
|
||||||
assert first_els[0] == "0.0.0.0"
|
assert first_els[0] == "0.0.0.0"
|
||||||
assert last_els[0] == "224.0.0.0"
|
assert last_els[0] == "224.0.0.0"
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.slow
|
||||||
|
def test_row_parity(csv) -> None:
|
||||||
|
rows = csv.read_text().splitlines()
|
||||||
|
|
||||||
|
db = Path(tempfile.NamedTemporaryFile().name)
|
||||||
|
create_table(db, csv)
|
||||||
|
|
||||||
|
csv_len = len(rows)
|
||||||
|
db_len = get_db_len(db)
|
||||||
|
|
||||||
|
assert csv_len == db_len
|
||||||
Reference in new issue
Block a user