2016-05-01 18:12:02 +02:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
import unittest
|
2021-01-02 06:20:53 +01:00
|
|
|
from io import StringIO
|
2016-05-01 18:12:02 +02:00
|
|
|
|
2021-01-02 06:20:53 +01:00
|
|
|
from .util import SphinxTestApplication, test_root
|
2016-05-01 18:12:02 +02:00
|
|
|
|
2021-01-02 06:20:53 +01:00
|
|
|
IP4_ADDRESSES = ["127.0.0.1", "192.168.0.1"]
|
|
|
|
IP6_ADDRESSES = ["::1", "2001:dead:beef::1"]
|
|
|
|
IP4_RANGES = ["172.16.0.0/24", "192.168.0.0/24"]
|
|
|
|
IP6_RANGES = ["2001:dead:beef::/64", "2001:dada:b001::/64"]
|
2016-05-02 20:55:09 +02:00
|
|
|
|
|
|
|
|
2016-05-01 18:12:02 +02:00
|
|
|
class TestIPExtension(unittest.TestCase):
|
|
|
|
def setUp(self):
|
2021-01-02 06:20:53 +01:00
|
|
|
if not (test_root / "_static").exists():
|
|
|
|
(test_root / "_static").mkdir()
|
2016-05-01 18:12:02 +02:00
|
|
|
self.feed_warnfile = StringIO()
|
2021-01-02 06:16:25 +01:00
|
|
|
self.app = SphinxTestApplication(
|
2021-01-02 06:20:53 +01:00
|
|
|
buildername="html", warning=self.feed_warnfile, cleanenv=True
|
|
|
|
)
|
2016-05-02 20:55:09 +02:00
|
|
|
self.app.build(force_all=True, filenames=[])
|
2016-05-01 18:12:02 +02:00
|
|
|
|
|
|
|
def tearDown(self):
|
2016-05-02 20:55:09 +02:00
|
|
|
self.app.cleanup()
|
2021-01-02 06:20:53 +01:00
|
|
|
(test_root / "_build").rmtree(True)
|
2016-05-01 18:12:02 +02:00
|
|
|
|
2016-05-02 20:55:09 +02:00
|
|
|
def test_ip_domaindata(self):
|
2021-01-02 06:20:53 +01:00
|
|
|
self.assertIn("ip", self.app.env.domaindata)
|
|
|
|
ipdomdata = self.app.env.domaindata["ip"]
|
2021-09-04 17:15:27 +02:00
|
|
|
self.assertIn("ip_refs", ipdomdata)
|
|
|
|
self.assertIn("range_refs", ipdomdata)
|
|
|
|
self.assertIn("range_nodes", ipdomdata)
|
|
|
|
self.assertIn("ranges", ipdomdata)
|
2021-09-04 19:54:24 +02:00
|
|
|
self.assertIn("ip_dict", ipdomdata)
|
2016-05-02 20:55:09 +02:00
|
|
|
|
|
|
|
def find_in_index(self, entry):
|
2021-01-02 06:20:53 +01:00
|
|
|
indexentries = self.app.env.get_domain("index").entries
|
2016-05-02 20:55:09 +02:00
|
|
|
for index in indexentries:
|
|
|
|
for value in indexentries[index]:
|
|
|
|
if value[1] == entry:
|
|
|
|
return
|
|
|
|
self.fail("%s not found in index" % entry)
|
|
|
|
|
|
|
|
def test_ip4_addresses(self):
|
2021-09-04 19:54:24 +02:00
|
|
|
ips = self.app.env.domaindata["ip"]["ip_refs"]
|
2016-05-02 20:55:09 +02:00
|
|
|
for ip in IP4_ADDRESSES:
|
2021-09-04 17:15:27 +02:00
|
|
|
self.assertIn(ip, ips)
|
2016-05-02 20:55:09 +02:00
|
|
|
self.find_in_index("IPv4 address; %s" % ip)
|
|
|
|
self.find_in_index("%s; Test page 2" % ip)
|
|
|
|
|
|
|
|
def test_ip6_addresses(self):
|
2021-09-04 19:54:24 +02:00
|
|
|
ips = self.app.env.domaindata["ip"]["ip_refs"]
|
2016-05-02 20:55:09 +02:00
|
|
|
for ip in IP6_ADDRESSES:
|
2021-09-04 17:15:27 +02:00
|
|
|
self.assertIn(ip, ips)
|
2016-05-02 20:55:09 +02:00
|
|
|
self.find_in_index("IPv6 address; %s" % ip)
|
|
|
|
self.find_in_index("%s; Test page 2" % ip)
|