Skip to content

Commit

Permalink
Acutally, just add one test. See comment as to why
Browse files Browse the repository at this point in the history
  • Loading branch information
WillNilges committed Jan 14, 2025
1 parent eb9e896 commit 2a65892
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 deletions.
20 changes: 14 additions & 6 deletions src/meshapi/tests/test_admin_panel.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
2 changes: 1 addition & 1 deletion src/meshapi/tests/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
2 changes: 1 addition & 1 deletion src/meshdb/templates/admin/iframed.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
<body>
<div id="page_container">
<div id="admin_panel_div" class="frameGrow">
<iframe src="/admin" id="admin_panel_iframe" class="frameGrow"></iframe>
<iframe src="/admin/" id="admin_panel_iframe" class="frameGrow"></iframe>
</div>

<div class="floating-button">
Expand Down

0 comments on commit 2a65892

Please sign in to comment.