diff --git a/src/meshapi/tests/test_admin_panel.py b/src/meshapi/tests/test_admin_panel.py index 7c685375..cc395c90 100644 --- a/src/meshapi/tests/test_admin_panel.py +++ b/src/meshapi/tests/test_admin_panel.py @@ -1,4 +1,5 @@ import datetime +from bs4 import BeautifulSoup from django.contrib.auth.models import Group, User from django.test import Client, TestCase from rest_framework.authtoken.models import TokenProxy @@ -84,15 +85,22 @@ def setUp(self) -> None: user=self.admin_user, target="http://example.com", event="building.created", headers="" ) - # TODO (wdn): Add more tests checking if navigating to xyz page works def test_iframe_loads(self): route = "/admin/panel/" code = 200 response = self.c.get(route) self.assertEqual(code, response.status_code, f"Could not view {route} in the admin panel.") - def test_iframe_loads_with_node(self): - route = f"/admin/panel/node/{self.node1.id}/change/" - code = 200 - response = self.c.get(route) - self.assertEqual(code, response.status_code, f"Could not view {route} in the admin panel.") + decoded_panel = response.content.decode() + soup = BeautifulSoup(decoded_panel, "html.parser") + iframe = soup.find(id="admin_panel_iframe") + iframe_src = iframe.attrs["src"] + self.assertEqual("/admin/", iframe_src) + iframe_response = self.c.get(iframe_src) + self.assertEqual(code, iframe_response.status_code, f"Could not view {route} in the admin panel.") + + + # TODO (wdn): Add more tests checking if navigating to xyz page works + # Unfortunately, because that is a lot of javascript, it's tricky to test. + # It may be possible to run selenium integration tests or something to validate + # that functionality diff --git a/src/meshapi/tests/util.py b/src/meshapi/tests/util.py index 0b3ed09c..cbcf72b3 100644 --- a/src/meshapi/tests/util.py +++ b/src/meshapi/tests/util.py @@ -18,4 +18,4 @@ def get_admin_results_count(html_string: str): if not result_list: return 0 - return sum(1 for tr in result_list.find("tbody").find_all("tr") if tr.find_all("td")) + return sum(1 for tr in result_list.find("tbody").find_all("tr") if tr.find_all("td") diff --git a/src/meshdb/templates/admin/iframed.html b/src/meshdb/templates/admin/iframed.html index 1b884152..43029774 100644 --- a/src/meshdb/templates/admin/iframed.html +++ b/src/meshdb/templates/admin/iframed.html @@ -32,7 +32,7 @@
- +