forked from bortzmeyer/check_expire
44 lines
1.5 KiB
Python
44 lines
1.5 KiB
Python
#!/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():
|
|
tmpfile = tempfile.NamedTemporaryFile(suffix=".testianacache", delete=False)
|
|
database = ianardap.IanaRDAPDatabase(cachefile=tmpfile.name, maxage=0)
|
|
assert os.path.exists(tmpfile.name) and \
|
|
datetime.datetime.fromtimestamp(os.path.getmtime(tmpfile.name)) > \
|
|
(datetime.datetime.now() - datetime.timedelta(minutes=1))
|
|
os.remove(tmpfile.name)
|
|
os.remove(tmpfile.name + ".lock")
|
|
|
|
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")
|
|
assert server == "https://rdap.nic.ar/"
|
|
|
|
def test_find_not_exists():
|
|
database = ianardap.IanaRDAPDatabase()
|
|
server = database.find("www.foobar.example")
|
|
assert server is None
|