Skip to content

Commit

Permalink
If siae contact_full_name is empty, use slug
Browse files Browse the repository at this point in the history
  • Loading branch information
raphodn committed Sep 18, 2023
1 parent 6c8aaf7 commit b415a67
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 2 deletions.
5 changes: 4 additions & 1 deletion lemarche/conversations/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,10 @@ def set_siae_encoded(self):
The UUID of siae.
"""
if not self.siae_encoded:
siae_slug_full_name = slugify(self.siae.contact_full_name).replace("-", "_")
if self.siae.contact_full_name:
siae_slug_full_name = slugify(self.siae.contact_full_name).replace("-", "_")
else:
siae_slug_full_name = self.siae.slug.replace("-", "_")
self.siae_encoded = f"{siae_slug_full_name}_{str(uuid4())[:4]}"

def save(self, *args, **kwargs):
Expand Down
30 changes: 30 additions & 0 deletions lemarche/conversations/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from lemarche.conversations.factories import ConversationFactory
from lemarche.conversations.models import Conversation
from lemarche.siaes.factories import SiaeFactory


class ConversationModelTest(TestCase):
Expand All @@ -19,6 +20,35 @@ def test_str(self):
self.assertEqual(str(self.conversation), "Je souhaite me renseigner")


class ConversationModelSaveTest(TestCase):
@classmethod
def setUpTestData(cls):
cls.siae_with_contact_full_name = SiaeFactory(
name="Une structure",
contact_first_name="Prénom",
contact_last_name="Nom",
contact_email="[email protected]",
)
cls.conversation_1 = ConversationFactory(
title="Je souhaite me renseigner",
sender_first_name="Acheteur",
sender_last_name="Curieux",
sender_email="[email protected]",
siae=cls.siae_with_contact_full_name,
)
cls.siae_without_contact_full_name = SiaeFactory(
name="Une autre structure", contact_first_name="", contact_last_name="", contact_email="[email protected]"
)
cls.conversation_2 = ConversationFactory(
title="Je souhaite encore me renseigner", siae=cls.siae_without_contact_full_name
)

def test_set_siae_encoded(self):
self.assertTrue("acheteur_curieux" in self.conversation_1.sender_encoded)
self.assertTrue("prenom_nom" in self.conversation_1.siae_encoded)
self.assertTrue("une_autre_structure" in self.conversation_2.siae_encoded)


class ConversationQuerysetTest(TestCase):
@classmethod
def setUpTestData(cls):
Expand Down
4 changes: 3 additions & 1 deletion lemarche/siaes/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -938,7 +938,9 @@ def etp_count_display(self):

@property
def contact_full_name(self):
return f"{self.contact_first_name} {self.contact_last_name}"
if self.contact_first_name and self.contact_last_name:
return f"{self.contact_first_name} {self.contact_last_name}"
return ""

@property
def contact_short_name(self):
Expand Down

0 comments on commit b415a67

Please sign in to comment.