diff options
author | 2019-08-23 15:38:54 +0200 | |
---|---|---|
committer | 2019-08-23 15:40:53 +0200 | |
commit | bf75fd6c450dc1566f9ac0c25bf3db2e4be872a0 (patch) | |
tree | 2437d04599108c5e21285e8476c6bbc87ebd7942 | |
parent | Adding tests for filters and the deleted message front-end view (diff) |
Adding tests for deleted message view
Tests include:
- Properly escaping html;
- Correct messages have been passed to templates;
- Embeds are both rendered by the template.
-rw-r--r-- | pydis_site/apps/staff/tests/test_logs_view.py | 100 |
1 files changed, 98 insertions, 2 deletions
diff --git a/pydis_site/apps/staff/tests/test_logs_view.py b/pydis_site/apps/staff/tests/test_logs_view.py index b5f7bb24..4fc38c7a 100644 --- a/pydis_site/apps/staff/tests/test_logs_view.py +++ b/pydis_site/apps/staff/tests/test_logs_view.py @@ -31,15 +31,79 @@ class TestLogsView(TestCase): creation=timezone.now() ) - cls.deleted_message = DeletedMessage.objects.create( + cls.deleted_message_one = DeletedMessage.objects.create( author=cls.author, id=614125807161573397, channel_id=1984, - content='I think my tape has run out...', + content='<em>I think my tape has run out...</em>', embeds=[], deletion_context=cls.deletion_context, ) + cls.embed_one = { + "footer": { + "text": "This will be displayed in the footer!", + "icon_url": "https://avatars0.githubusercontent.com/u/33516116?s=460&v=4" + }, + "image": { + "url": "https://avatars0.githubusercontent.com/u/33516116?s=460&v=4" + }, + "thumbnail": { + "url": "https://avatars0.githubusercontent.com/u/33516116?s=460&v=4" + }, + "author": { + "name": "Ves Zappa", + "url": "https://pydis.com", + "icon_url": "https://avatars0.githubusercontent.com/u/33516116?s=460&v=4" + }, + "fields": [ + { + "inline": False, + "name": "Field Name 1", + "value": "Field Value 1" + }, + { + "inline": False, + "name": "Field Name 2", + "value": "Field Value 2" + }, + { + "inline": True, + "name": "Field Name 3", + "value": "Field Value 3" + }, + { + "inline": True, + "name": "Field Name 4", + "value": "Field Value 4" + }, + { + "inline": True, + "name": "Field Name 5", + "value": "Field Value 5" + } + ], + "color": 16711680, + "timestamp": "2019-08-21T13:58:34.480053+00:00", + "type": "rich", + "description": "This embed is way too cool to be seen in public channels.", + "url": "https://pythondiscord.com/", + "title": "Hello, PyDis" + } + + cls.embed_two = { + "description": "This embed is way too cool to be seen in public channels.", + } + + cls.deleted_message_two = DeletedMessage.objects.create( + author=cls.author, + id=614444836291870750, + channel_id=1984, + content='Does that mean this thing will halt?', + embeds=[cls.embed_one, cls.embed_two], + deletion_context=cls.deletion_context, + ) + def setUp(self): """Sets up a test client that automatically sets the correct HOST header.""" self.client = Client(HTTP_HOST=reverse_host(host="staff")) @@ -62,3 +126,35 @@ class TestLogsView(TestCase): f'<span class="discord-username" style="color: {role_colour}">{self.author}</span>' ) self.assertInHTML(html_needle, response.content.decode()) + + def test_correct_messages_have_been_passed_to_template(self): + url = reverse('logs', host="staff", args=(self.deletion_context.id,)) + response = self.client.get(url) + self.assertIn("messages", response.context) + self.assertListEqual( + [self.deleted_message_one, self.deleted_message_two], + list(response.context["messages"]) + ) + + def test_if_both_embeds_are_included_html_response(self): + url = reverse('logs', host="staff", args=(self.deletion_context.id,)) + response = self.client.get(url) + + html_response = response.content.decode() + embed_colour_needle = ( + '<div class="discord-embed-color" style="background-color: {colour}"></div>' + ) + embed_one_colour = hex_colour(self.embed_one["color"]) + embed_two_colour = "#cacbce" + self.assertInHTML(embed_colour_needle.format(colour=embed_one_colour), html_response) + self.assertInHTML(embed_colour_needle.format(colour=embed_two_colour), html_response) + + def test_if_html_in_content_is_properly_escaped(self): + url = reverse('logs', host="staff", args=(self.deletion_context.id,)) + response = self.client.get(url) + + html_response = response.content.decode() + unescaped_content = "<em>I think my tape has run out...</em>" + self.assertInHTML(unescaped_content, html_response, count=0) + escaped_content = "<em>I think my tape has run out...</em>" + self.assertInHTML(escaped_content, html_response, count=1) |