Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
 into MNCH-1030-whatsapp-list-messages
  • Loading branch information
Buhle79 committed Feb 1, 2024
2 parents ceb5f8b + 05d716d commit 6c5b26b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 17 deletions.
19 changes: 2 additions & 17 deletions home/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from django.db.models.signals import pre_save
from django.dispatch import receiver
from django.forms import CheckboxSelectMultiple
from django.utils.text import slugify
from django.utils.translation import gettext_lazy as _
from modelcluster.contrib.taggit import ClusterTaggableManager
from modelcluster.fields import ParentalKey
Expand Down Expand Up @@ -39,6 +38,7 @@
MultiFieldPanel,
ObjectList,
TabbedInterface,
TitleFieldPanel,
)
import logging

Expand Down Expand Up @@ -66,17 +66,6 @@ def get_unique_slug(self, slug):
candidate_slug = f"{slug}-{suffix}"
return candidate_slug

def full_clean(self, *args, **kwargs):
# Autogenerate slug if not present
if not self.slug:
allow_unicode = getattr(settings, "WAGTAIL_ALLOW_UNICODE_SLUGS", True)
base_slug = slugify(self.title, allow_unicode=allow_unicode)

if base_slug:
self.slug = self.get_unique_slug(base_slug)

super().full_clean(*args, **kwargs)

def clean(self):
super().clean()

Expand Down Expand Up @@ -500,7 +489,7 @@ class WhatsAppTemplateCategory(models.TextChoices):
web_panels = [
MultiFieldPanel(
[
FieldPanel("title"),
TitleFieldPanel("title"),
FieldPanel("subtitle"),
FieldPanel("body"),
FieldPanel("include_in_footer"),
Expand Down Expand Up @@ -945,10 +934,6 @@ def clean(self):
return result


# Allow slug to be blank in forms, we fill it in in full_clean
Page._meta.get_field("slug").blank = True


@receiver(pre_save, sender=ContentPage)
def update_embedding(sender, instance, *args, **kwargs):
from .word_embedding import preprocess_content_for_embedding
Expand Down
11 changes: 11 additions & 0 deletions home/tests/test_models.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from io import StringIO
from unittest import mock

from django.core.exceptions import ValidationError
from django.core.management import call_command
from django.test import TestCase, override_settings
from requests import HTTPError
from wagtail.blocks import StructBlockValidationError
Expand Down Expand Up @@ -322,6 +324,15 @@ def test_create_whatsapp_template_submit_return_error(
self.assertRaises(ValidationError)
self.assertEqual(e.exception.message, "Failed to submit template")

def test_for_missing_migrations(self):
output = StringIO()
call_command("makemigrations", no_input=True, dry_run=True, stdout=output)
self.assertEqual(
output.getvalue().strip(),
"No changes detected",
"There are missing migrations:\n %s" % output.getvalue(),
)


class WhatsappBlockTests(TestCase):
def create_message_value(
Expand Down

0 comments on commit 6c5b26b

Please sign in to comment.