RFCartography/tests/test_search.py
2023-01-03 14:42:54 +01:00

93 lines
8.7 KiB
Python

from unittest import TestCase
from flask import Flask
from werkzeug.datastructures import MultiDict
from rfcartography import create_app
from rfcartography.index_parser import RFC, NotIssued, STD, BCP, FYI, DocType
from rfcartography.rfcartographer import RFCartographer
class TestDetailsPages(TestCase):
def setUp(self):
"""create an app object for testing purposes"""
self.app:Flask = create_app()
self.app.config.update({"TESTING": True})
rfc42: RFC = RFC(42)
rfc23: NotIssued = NotIssued(23)
std42: STD = STD(42)
bcp42: BCP = BCP(42)
fyi42: FYI = FYI(42)
index: dict[DocType: dict[int, Document]] = {DocType.RFC: {42: rfc42,
23: rfc23},
DocType.STD: {42: std42},
DocType.BCP: {42: bcp42},
DocType.FYI: {42: fyi42},
DocType.NIC: {},
DocType.IEN: {},
DocType.RTR: {}}
self.app.cartographer = RFCartographer(index)
return
def test_search_page(self):
"""testing the start page"""
client: FlaskClient = self.app.test_client()
response: TestResponse = client.get('/')
self.assertEqual(response.status, '200 OK')
def test_no_search_result(self):
"""testing searching for not existing RFCs"""
client: FlaskClient = self.app.test_client()
response: TestResponse = client.get('/map?type=rfc&num=666')
self.assertEqual(response.status, '404 NOT FOUND')
def test_quicksearch_validation(self):
"""testing the validation of user input in the quick search"""
client: FlaskClient = self.app.test_client()
# valid type and valid number shall be accepted
response = client.get('/map?type=rfc&num=42')
self.assertEqual(response.status, '200 OK')
# number with leading 0s shall be accepted
response = client.get('/map?type=rfc&num=0042')
self.assertEqual(response.status, '200 OK')
# number with letters shall be rejected
response = client.get('/map?type=rfc&num=42a')
self.assertEqual(response.status, '400 BAD REQUEST')
# invalid type shall be rejected
response = client.get('/map?type=test&num=42')
self.assertEqual(response.status, '400 BAD REQUEST')
# missing type shall be rejected
response = client.get('/map?num=42')
self.assertEqual(response.status, '400 BAD REQUEST')
# missing num shall be rejected
response = client.get('/map?type=test')
self.assertEqual(response.status, '400 BAD REQUEST')
return
def test_advanced_search_validation(self):
"""testing the validation of user input in the advanced search"""
client: FlaskClient = self.app.test_client()
# valid requests shall be accepted
response: TestResponse = client.get('/map?type=rfc&num=42&depth=23&nodes_enabled=rfc&nodes_enabled=std&nodes_enabled=bcp&nodes_enabled=fyi&nodes_enabled=nic&nodes_enabled=ien&nodes_enabled=rtr&rfc_color=%232072b1&std_color=%23c21a7e&bcp_color=%236d388d&fyi_color=%238bbd3e&nic_color=%23efe50b&ien_color=%23f28f20&rtr_color=%23e32326&obsoletes_style=dashed&obsoleted_by_style=dashed&updates_style=dashdot&updated_by_style=dashdot&is_also_style=solid&see_also_style=dotted&obsoletes_color=%23303c50&obsoleted_by_color=%23303c50&updates_color=%23607d8d&updated_by_color=%23607d8d&is_also_color=%23132e41&see_also_color=%23008e90')
self.assertEqual(response.status, '200 OK')
# invalid type values shall be rejected
response = client.get('/map?type=invalid&num=42&depth=23&nodes_enabled=rfc&nodes_enabled=std&nodes_enabled=bcp&nodes_enabled=fyi&nodes_enabled=nic&nodes_enabled=ien&nodes_enabled=rtr&rfc_color=%232072b1&std_color=%23c21a7e&bcp_color=%236d388d&fyi_color=%238bbd3e&nic_color=%23efe50b&ien_color=%23f28f20&rtr_color=%23e32326&obsoletes_style=dashed&obsoleted_by_style=dashed&updates_style=dashdot&updated_by_style=dashdot&is_also_style=solid&see_also_style=dotted&obsoletes_color=%23303c50&obsoleted_by_color=%23303c50&updates_color=%23607d8d&updated_by_color=%23607d8d&is_also_color=%23132e41&see_also_color=%23008e90')
self.assertEqual(response.status, '400 BAD REQUEST')
# invalid num values shall be rejected
response = client.get('/map?type=rfc&num=invalid&depth=23&nodes_enabled=rfc&nodes_enabled=std&nodes_enabled=bcp&nodes_enabled=fyi&nodes_enabled=nic&nodes_enabled=ien&nodes_enabled=rtr&rfc_color=%232072b1&std_color=%23c21a7e&bcp_color=%236d388d&fyi_color=%238bbd3e&nic_color=%23efe50b&ien_color=%23f28f20&rtr_color=%23e32326&obsoletes_style=dashed&obsoleted_by_style=dashed&updates_style=dashdot&updated_by_style=dashdot&is_also_style=solid&see_also_style=dotted&obsoletes_color=%23303c50&obsoleted_by_color=%23303c50&updates_color=%23607d8d&updated_by_color=%23607d8d&is_also_color=%23132e41&see_also_color=%23008e90')
self.assertEqual(response.status, '400 BAD REQUEST')
# num values with leading 0s shall be accepted
response = client.get('/map?type=rfc&num=0042&depth=23&nodes_enabled=rfc&nodes_enabled=std&nodes_enabled=bcp&nodes_enabled=fyi&nodes_enabled=nic&nodes_enabled=ien&nodes_enabled=rtr&rfc_color=%232072b1&std_color=%23c21a7e&bcp_color=%236d388d&fyi_color=%238bbd3e&nic_color=%23efe50b&ien_color=%23f28f20&rtr_color=%23e32326&obsoletes_style=dashed&obsoleted_by_style=dashed&updates_style=dashdot&updated_by_style=dashdot&is_also_style=solid&see_also_style=dotted&obsoletes_color=%23303c50&obsoleted_by_color=%23303c50&updates_color=%23607d8d&updated_by_color=%23607d8d&is_also_color=%23132e41&see_also_color=%23008e90')
self.assertEqual(response.status, '200 OK')
# invalid color values shall be rejected
response = client.get('/map?type=rfc&num=42&depth=23&nodes_enabled=rfc&nodes_enabled=std&nodes_enabled=bcp&nodes_enabled=fyi&nodes_enabled=nic&nodes_enabled=ien&nodes_enabled=rtr&rfc_color=%232072b1&std_color=%23c21a7e&bcp_color=%236d388d&fyi_color=invalid&nic_color=%23efe50b&ien_color=%23f28f20&rtr_color=%23e32326&obsoletes_style=dashed&obsoleted_by_style=dashed&updates_style=dashdot&updated_by_style=dashdot&is_also_style=solid&see_also_style=dotted&obsoletes_color=%23303c50&obsoleted_by_color=%23303c50&updates_color=%23607d8d&updated_by_color=%23607d8d&is_also_color=%23132e41&see_also_color=%23008e90')
# invalid color values shall be rejected
response = client.get('/map?type=rfc&num=42&depth=23&nodes_enabled=rfc&nodes_enabled=std&nodes_enabled=bcp&nodes_enabled=fyi&nodes_enabled=nic&nodes_enabled=ien&nodes_enabled=rtr&rfc_color=%232072b1&std_color=%23c21a7e&bcp_color=%236d388d&fyi_color=%238bbd3e&nic_color=%23efe50b&ien_color=%23f28f20&rtr_color=%23e32326&obsoletes_style=dashed&obsoleted_by_style=dashed&updates_style=dashdot&updated_by_style=dashdot&is_also_style=solid&see_also_style=dotted&obsoletes_color=%23fail00&obsoleted_by_color=%23303c50&updates_color=%23607d8d&updated_by_color=%23607d8d&is_also_color=%23132e41&see_also_color=%23008e90')
self.assertEqual(response.status, '400 BAD REQUEST')
# invalid line style values shall be rejected
response = client.get('/map?type=rfc&num=42&depth=23&nodes_enabled=rfc&nodes_enabled=std&nodes_enabled=bcp&nodes_enabled=fyi&nodes_enabled=nic&nodes_enabled=ien&nodes_enabled=rtr&rfc_color=%232072b1&std_color=%23c21a7e&bcp_color=%236d388d&fyi_color=%238bbd3e&nic_color=%23efe50b&ien_color=%23f28f20&rtr_color=%23e32326&obsoletes_style=dashed&obsoleted_by_style=dashed&updates_style=dashdot&updated_by_style=dashdot&is_also_style=solid&see_also_style=invalid&obsoletes_color=%23303c50&obsoleted_by_color=%23303c50&updates_color=%23607d8d&updated_by_color=%23607d8d&is_also_color=%23132e41&see_also_color=%23008e90')
self.assertEqual(response.status, '400 BAD REQUEST')
# invalid DocType shall be rejected
response = client.get('/map?type=rfc&num=42&depth=23&nodes_enabled=rfc&nodes_enabled=std&nodes_enabled=bcp&nodes_enabled=fyi&nodes_enabled=nic&nodes_enabled=invalid&nodes_enabled=rtr&rfc_color=%232072b1&std_color=%23c21a7e&bcp_color=%236d388d&fyi_color=%238bbd3e&nic_color=%23efe50b&ien_color=%23f28f20&rtr_color=%23e32326&obsoletes_style=dashed&obsoleted_by_style=dashed&updates_style=dashdot&updated_by_style=dashdot&is_also_style=solid&see_also_style=dotted&obsoletes_color=%23303c50&obsoleted_by_color=%23303c50&updates_color=%23607d8d&updated_by_color=%23607d8d&is_also_color=%23132e41&see_also_color=%23008e90')
self.assertEqual(response.status, '400 BAD REQUEST')
return