Skip to content

Commit

Permalink
✅ [#108] Test for callback URL check in admin
Browse files Browse the repository at this point in the history
  • Loading branch information
stevenbal committed Aug 30, 2024
1 parent b20ffed commit 7f4e311
Showing 1 changed file with 59 additions and 1 deletion.
60 changes: 59 additions & 1 deletion src/nrc/tests/admin/test_abonnement.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
from django.test import override_settings
from django.test import override_settings, tag
from django.urls import reverse

import requests_mock
from django_webtest import WebTest
from freezegun import freeze_time
from maykin_2fa.test import disable_admin_mfa
from requests.exceptions import RequestException

from nrc.accounts.tests.factories import SuperUserFactory
from nrc.datamodel.tests.factories import (
Expand Down Expand Up @@ -31,6 +33,7 @@ def setUp(self):
100, abonnement=self.abonnement, notificatie__kanaal=self.kanaal
)

@tag("gh-157")
def test_delete_abonnement_hide_notificatie_responses(self):
"""
Regression test for https://github.com/open-zaak/open-notificaties/issues/157
Expand All @@ -50,6 +53,7 @@ def test_delete_abonnement_hide_notificatie_responses(self):

self.assertNotIn("Notificatie response", deleted_objects)

@tag("gh-157")
def test_bulk_delete_abonnement_hide_notificatie_responses(self):
"""
Regression test for https://github.com/open-zaak/open-notificaties/issues/157
Expand All @@ -75,3 +79,57 @@ def test_bulk_delete_abonnement_hide_notificatie_responses(self):
)

self.assertNotIn("Notificatie response", deleted_objects)

@tag("gh-108")
@requests_mock.Mocker()
def test_abonnement_list_check_if_callback_urls_are_reachable(self, m):
self.abonnement.delete()

abonnement_url_reachable = AbonnementFactory.create(
callback_url="http://reachable.local/foo",
auth="Token 1234",
)
abonnement_url_unreachable = AbonnementFactory.create(
callback_url="http://unreachable.local/foo",
auth="Token 1234",
)
abonnement_url_incorrect_auth = AbonnementFactory.create(
callback_url="http://incorrect.auth.local/foo",
auth="Token 4321",
)

m.post("http://reachable.local/foo", status_code=204)
m.post("http://unreachable.local/foo", status_code=403)
m.post("http://incorrect.auth.local/foo", exc=RequestException)

response = self.app.get(
reverse("admin:datamodel_abonnement_changelist"),
user=self.user,
)

row_incorrect_auth, row_unreachable, row_reachable = response.html.find(
"tbody"
).find_all("tr")

self.assertEqual(
row_incorrect_auth.find_all("td")[2].text,
abonnement_url_incorrect_auth.callback_url,
)
self.assertEqual(
row_incorrect_auth.find_all("td")[3].find("img").attrs["alt"], "False"
)

self.assertEqual(
row_unreachable.find_all("td")[2].text,
abonnement_url_unreachable.callback_url,
)
self.assertEqual(
row_unreachable.find_all("td")[3].find("img").attrs["alt"], "False"
)

self.assertEqual(
row_reachable.find_all("td")[2].text, abonnement_url_reachable.callback_url
)
self.assertEqual(
row_reachable.find_all("td")[3].find("img").attrs["alt"], "True"
)

0 comments on commit 7f4e311

Please sign in to comment.