Make test less dependent on template changes

This commit is contained in:
Christopher Broderick 2023-07-18 01:01:10 +01:00
parent 7b72a2cad2
commit 07f6d5f6c8

View File

@ -1085,21 +1085,32 @@ class EmailInteractionsTestCase(TestCase):
cat = KBCategory.objects.create(
title="Test Cat",
slug="test_cat",
description="This is a test category",
description="This is a test category",
queue=self.queue_public,
)
cat.save()
attr_list = {
"f1_field_title": "KBItem 1",
"f1_attr": "kbitem",
"f1_attr_value": "1",
"f2_attr": "submitter_email",
"f2_attr_value": "foo@bar.cz",
"f3_attr": "title",
"f3_attr_value": "lol",
}
self.kbitem1 = KBItem.objects.create(
category=cat,
title="KBItem 1",
title=attr_list["f1_field_title"],
question="What?",
answer="A KB Item",
)
self.kbitem1.save()
cat_url = reverse('helpdesk:submit') + \
"?kbitem=1&submitter_email=foo@bar.cz&title=lol"
cat_url = reverse('helpdesk:submit') + '?' \
+ attr_list["f1_attr"] + '=' + attr_list["f1_attr_value"] + '&' \
+ attr_list["f2_attr"] + '=' + attr_list["f2_attr_value"] + '&' \
+ attr_list["f3_attr"] + '=' + attr_list["f3_attr_value"]
response = self.client.get(cat_url)
# Get the rendered response to make it easier to debug if things go wrong
if (
hasattr(response, "render")
and callable(response.render)
@ -1114,8 +1125,8 @@ class EmailInteractionsTestCase(TestCase):
msg_prefix = content.decode(response.charset)
self.assertContains(
response, '<option value="1" selected>KBItem 1</option>', msg_prefix = msg_prefix)
response, '<option value="' + attr_list["f1_attr_value"] + '" selected>' + attr_list["f1_field_title"] + '</option>', msg_prefix = msg_prefix)
self.assertContains(
response, '<input type="email" name="submitter_email" value="foo@bar.cz" class="form-control form-control" required id="id_submitter_email">', msg_prefix = msg_prefix)
response, '<input type="email" name="' + attr_list["f2_attr"] + '" value="' + attr_list["f2_attr_value"], msg_prefix = msg_prefix)
self.assertContains(
response, '<input type="text" name="title" value="lol" class="form-control form-control" maxlength="100" required id="id_title">', msg_prefix = msg_prefix)
response, '<input type="text" name="' + attr_list["f3_attr"] + '" value="' + attr_list["f3_attr_value"], msg_prefix = msg_prefix)