From a8a0322c871ef04920167ded706cfdc8a425d958 Mon Sep 17 00:00:00 2001 From: bast Date: Fri, 18 Jun 2021 13:46:06 -0700 Subject: Adjust Message model to support new nitro messages with over 4000 chars --- pydis_site/apps/api/tests/test_models.py | 40 +++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) (limited to 'pydis_site/apps/api/tests') diff --git a/pydis_site/apps/api/tests/test_models.py b/pydis_site/apps/api/tests/test_models.py index 66052e01..1303639e 100644 --- a/pydis_site/apps/api/tests/test_models.py +++ b/pydis_site/apps/api/tests/test_models.py @@ -1,6 +1,7 @@ from datetime import datetime as dt -from django.test import SimpleTestCase +from django.core.exceptions import ValidationError +from django.test import SimpleTestCase, TestCase from django.utils import timezone from pydis_site.apps.api.models import ( @@ -34,6 +35,43 @@ class ReprMixinTests(SimpleTestCase): self.assertEqual(repr(self.klass), expected) +class NitroMessageLengthTest(TestCase): + def setUp(self): + self.user = User.objects.create(id=50, name='bill', discriminator=5) + self.context = MessageDeletionContext.objects.create( + id=50, + actor=self.user, + creation=dt.utcnow() + ) + + def test_create(self): + message = DeletedMessage( + id=46, + author=self.user, + channel_id=666, + content="w"*4000, + deletion_context=self.context, + embeds=[] + ) + + try: + message.clean_fields() + except Exception as e: + self.fail(f"Creation of message of length 3950 failed with: {e}") + + def test_create_failure(self): + message = DeletedMessage( + id=47, + author=self.user, + channel_id=666, + content="w"*4001, + deletion_context=self.context, + embeds=[] + ) + + self.assertRaisesRegex(ValidationError, "content':", message.clean_fields) + + class StringDunderMethodTests(SimpleTestCase): def setUp(self): self.nomination = Nomination( -- cgit v1.2.3 From 05730b3c55811ec2b9c7c0ff8484714a3ee498b2 Mon Sep 17 00:00:00 2001 From: bast Date: Thu, 24 Jun 2021 07:34:59 -0700 Subject: Add pragma: no cover to mark failure condition of test as known ok --- pydis_site/apps/api/tests/test_models.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'pydis_site/apps/api/tests') diff --git a/pydis_site/apps/api/tests/test_models.py b/pydis_site/apps/api/tests/test_models.py index 1303639e..5c9ddea4 100644 --- a/pydis_site/apps/api/tests/test_models.py +++ b/pydis_site/apps/api/tests/test_models.py @@ -56,7 +56,7 @@ class NitroMessageLengthTest(TestCase): try: message.clean_fields() - except Exception as e: + except Exception as e: # pragma: no cover self.fail(f"Creation of message of length 3950 failed with: {e}") def test_create_failure(self): -- cgit v1.2.3