2020-03-11 09:46:42 +00:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
import sys, os
|
|
|
|
sys.path.append(".")
|
|
|
|
sys.path.append("src/")
|
|
|
|
import uuid
|
|
|
|
import ipaddress
|
|
|
|
TEST_DIR = 'testdata/%s-%s' % (uuid.uuid4(), os.path.basename(__file__)) + '/'
|
|
|
|
print("Test directory:", TEST_DIR)
|
|
|
|
os.environ["ONIONR_HOME"] = TEST_DIR
|
|
|
|
import unittest
|
|
|
|
|
2020-03-19 21:02:15 +00:00
|
|
|
from lan.getip import lan_ips, best_ip
|
2020-03-11 09:46:42 +00:00
|
|
|
|
|
|
|
class TestGetLanIps(unittest.TestCase):
|
|
|
|
def test_get_lan_ips(self):
|
|
|
|
self.assertGreater(len(lan_ips), 0)
|
|
|
|
for ip in lan_ips:
|
|
|
|
ip = ipaddress.IPv4Address(ip)
|
|
|
|
if not ip.is_private or ip.is_multicast or ip.is_reserved:
|
|
|
|
raise ValueError
|
|
|
|
|
2020-03-19 21:02:15 +00:00
|
|
|
def test_best_lan_ip(self):
|
|
|
|
ip = best_ip
|
|
|
|
ip = ipaddress.IPv4Address(ip)
|
|
|
|
if not ip.is_private or ip.is_multicast or ip.is_reserved:
|
|
|
|
raise ValueError
|
|
|
|
|
2020-03-11 09:46:42 +00:00
|
|
|
|
|
|
|
unittest.main()
|