diff options
Diffstat (limited to 'pydis_site/apps/staff/tests')
-rw-r--r-- | pydis_site/apps/staff/tests/test_deletedmessage_filters.py | 43 | ||||
-rw-r--r-- | pydis_site/apps/staff/tests/test_logs_view.py | 20 |
2 files changed, 56 insertions, 7 deletions
diff --git a/pydis_site/apps/staff/tests/test_deletedmessage_filters.py b/pydis_site/apps/staff/tests/test_deletedmessage_filters.py index d9179044..31215784 100644 --- a/pydis_site/apps/staff/tests/test_deletedmessage_filters.py +++ b/pydis_site/apps/staff/tests/test_deletedmessage_filters.py @@ -18,16 +18,49 @@ class Colour(enum.IntEnum): class DeletedMessageFilterTests(TestCase): def test_hex_colour_filter(self): - self.assertEqual(deletedmessage_filters.hex_colour(Colour.BLACK), "#000000") - self.assertEqual(deletedmessage_filters.hex_colour(Colour.BLUE), "#0000FF") - self.assertEqual(deletedmessage_filters.hex_colour(Colour.GREEN), "#00FF00") - self.assertEqual(deletedmessage_filters.hex_colour(Colour.RED), "#FF0000") - self.assertEqual(deletedmessage_filters.hex_colour(Colour.WHITE), "#FFFFFF") + """The filter should produce the correct hex values from the integer representations.""" + test_values = ( + (Colour.BLUE, "#0000FF"), + (Colour.GREEN, "#00FF00"), + (Colour.RED, "#FF0000"), + (Colour.WHITE, "#FFFFFF"), + + # Since we're using a "Discord dark theme"-like front-end, show black text as white. + (Colour.BLACK, "#FFFFFF"), + ) + + for colour, hex_value in test_values: + with self.subTest(colour=colour, hex_value=hex_value): + self.assertEqual(deletedmessage_filters.hex_colour(colour), hex_value) def test_footer_datetime_filter(self): + """The filter should parse the ISO-datetime string and return a timezone-aware datetime.""" datetime_aware = timezone.now() iso_string = datetime_aware.isoformat() datetime_returned = deletedmessage_filters.footer_datetime(iso_string) self.assertTrue(timezone.is_aware(datetime_returned)) self.assertEqual(datetime_aware, datetime_returned) + + def test_visual_newlines_filter(self): + """The filter should replace newline characters by newline character and html linebreak.""" + html_br = " <span class='has-text-grey'>↵</span><br>" + + test_values = ( + ( + "Hello, this line does not contain a linebreak", + "Hello, this line does not contain a linebreak" + ), + ( + "A single linebreak\nin a string", + f"A single linebreak{html_br}in a string" + ), + ( + "Consecutive linebreaks\n\n\nwork, too", + f"Consecutive linebreaks{html_br}{html_br}{html_br}work, too" + ) + ) + + for input_, expected_output in test_values: + with self.subTest(input=input_, expected_output=expected_output): + self.assertEqual(deletedmessage_filters.visible_newlines(input_), expected_output) diff --git a/pydis_site/apps/staff/tests/test_logs_view.py b/pydis_site/apps/staff/tests/test_logs_view.py index 5036363b..00e0ab2f 100644 --- a/pydis_site/apps/staff/tests/test_logs_view.py +++ b/pydis_site/apps/staff/tests/test_logs_view.py @@ -21,10 +21,9 @@ class TestLogsView(TestCase): id=12345678901, name='Alan Turing', discriminator=1912, - avatar_hash=None ) - cls.author.roles.add(cls.developers_role) + cls.author.roles.append(cls.developers_role.id) cls.deletion_context = MessageDeletionContext.objects.create( actor=cls.actor, @@ -37,6 +36,7 @@ class TestLogsView(TestCase): channel_id=1984, content='<em>I think my tape has run out...</em>', embeds=[], + attachments=[], deletion_context=cls.deletion_context, ) @@ -101,6 +101,7 @@ class TestLogsView(TestCase): channel_id=1984, content='Does that mean this thing will halt?', embeds=[cls.embed_one, cls.embed_two], + attachments=['https://http.cat/100', 'https://http.cat/402'], deletion_context=cls.deletion_context, ) @@ -149,6 +150,21 @@ class TestLogsView(TestCase): 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_both_attachments_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() + attachment_needle = '<img alt="Attachment" class="discord-attachment" src="{url}">' + self.assertInHTML( + attachment_needle.format(url=self.deleted_message_two.attachments[0]), + html_response + ) + self.assertInHTML( + attachment_needle.format(url=self.deleted_message_two.attachments[1]), + 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) |