2021-07-07 15:23:26 +02:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
|
|
|
"""Test by executing 'pytest' https://docs.pytest.org/
|
|
|
|
|
|
|
|
Don't forget to set PYTHONPATH if you want to test the development
|
|
|
|
tree and not the installed package. """
|
|
|
|
|
|
|
|
import ianardap
|
|
|
|
|
|
|
|
import tempfile
|
|
|
|
import os.path
|
|
|
|
import datetime
|
|
|
|
|
|
|
|
def test_basic():
|
|
|
|
database = ianardap.IanaRDAPDatabase()
|
|
|
|
assert database.description.startswith("RDAP bootstrap file") and database.version == "1.0" and \
|
|
|
|
len(database.services) > 1000
|
|
|
|
|
|
|
|
def test_alternative_cache():
|
2022-11-09 16:17:03 +01:00
|
|
|
tmpdir = tempfile.TemporaryDirectory(suffix=".testianacaches")
|
|
|
|
database = ianardap.IanaRDAPDatabase(cachedir=tmpdir.name, maxage=0)
|
|
|
|
assert os.path.exists(database.cachefile) and \
|
|
|
|
datetime.datetime.fromtimestamp(os.path.getmtime(database.cachefile)) > \
|
2021-07-07 15:23:26 +02:00
|
|
|
(datetime.datetime.now() - datetime.timedelta(minutes=1))
|
2022-11-09 16:17:03 +01:00
|
|
|
os.remove(database.cachefile)
|
|
|
|
os.remove(database.cachefile + ".lock")
|
2021-07-07 15:23:26 +02:00
|
|
|
|
|
|
|
def test_refresh():
|
|
|
|
# Force a resfresh
|
|
|
|
database = ianardap.IanaRDAPDatabase(maxage=0)
|
|
|
|
assert (database.retrieved > (datetime.datetime.now() - datetime.timedelta(minutes=1))) and \
|
|
|
|
(datetime.datetime.fromtimestamp(os.path.getmtime(database.cachefile)) > \
|
|
|
|
(datetime.datetime.now() - datetime.timedelta(minutes=1)))
|
|
|
|
|
|
|
|
def test_find_exists():
|
|
|
|
database = ianardap.IanaRDAPDatabase()
|
|
|
|
server = database.find("www.foobar.ar")
|
2022-11-09 16:17:03 +01:00
|
|
|
assert server == ["https://rdap.nic.ar/"]
|
2021-07-07 15:23:26 +02:00
|
|
|
|
|
|
|
def test_find_not_exists():
|
|
|
|
database = ianardap.IanaRDAPDatabase()
|
|
|
|
server = database.find("www.foobar.example")
|
|
|
|
assert server is None
|
2021-07-07 15:50:47 +02:00
|
|
|
|
|
|
|
def test_pickle():
|
|
|
|
database = ianardap.IanaRDAPDatabase(pickleformat=True)
|
|
|
|
assert database.description.startswith("RDAP bootstrap file") and database.version == "1.0" and \
|
|
|
|
len(database.services) > 1000
|
|
|
|
|
|
|
|
|