-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
107 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
from django.core.management import call_command | ||
from django.test import TestCase | ||
|
||
from lemarche.siaes.factories import SiaeFactory | ||
from lemarche.users.factories import UserFactory | ||
from lemarche.utils.apis.api_brevo import create_or_update_company | ||
from lemarche.utils.urls import get_object_admin_url, get_object_share_url | ||
|
||
from unittest.mock import patch, MagicMock | ||
|
||
|
||
class CrmBrevoSyncCompaniesCommandTest(TestCase): | ||
@classmethod | ||
def setUpTestData(cls): | ||
cls.user = UserFactory(api_key="toto") | ||
cls.siae = SiaeFactory(users=[cls.user]) | ||
|
||
@patch("lemarche.utils.apis.api_brevo.sib_api_v3_sdk.Body") | ||
def test_create_or_update_company_with_mocked_body(self, mock_body): | ||
# Créer un mock pour `Body` | ||
mock_body_instance = MagicMock() | ||
mock_body.return_value = mock_body_instance | ||
|
||
# Créer un objet `Siae` de test | ||
siae = SiaeFactory(name="Test Company", completion_rate=0.5) | ||
|
||
# Appeler la fonction que l'on souhaite tester | ||
create_or_update_company(siae) | ||
|
||
expected_attributes = { | ||
"domain": siae.website, | ||
"phone_number": siae.contact_phone_display, | ||
"app_id": siae.id, | ||
"siae": True, | ||
"active": siae.is_active, | ||
"description": siae.description, | ||
"kind": siae.kind, | ||
"address_street": siae.address, | ||
"address_post_code": siae.post_code, | ||
"address_city": siae.city, | ||
"contact_email": siae.contact_email, | ||
"logo_url": siae.logo_url, | ||
"geo_range": siae.geo_range, | ||
"app_url": get_object_share_url(siae), | ||
"app_admin_url": get_object_admin_url(siae), | ||
# Champs de extra_data | ||
**siae.extra_data, # inclut completion_rate, tender_email_send_count, etc. | ||
} | ||
|
||
mock_body.assert_called_once_with(name="Test Company", attributes=expected_attributes) | ||
|
||
def test_command_creates_or_updates_siae(self): | ||
siae = SiaeFactory(extra_data={"completion_rate": 0.5}) | ||
|
||
call_command("crm_brevo_sync_companies") | ||
|
||
siae.refresh_from_db() | ||
print(siae) | ||
self.assertIsNotNone(siae.brevo_company_id) | ||
self.assertEqual(siae.extra_data.get("completion_rate"), siae.completion_rate) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters