-
Notifications
You must be signed in to change notification settings - Fork 0
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
Perrine Letellier
committed
Dec 20, 2024
1 parent
6b9ed71
commit b150b4b
Showing
5 changed files
with
106 additions
and
12 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
File renamed without changes.
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,27 @@ | ||
import random | ||
import string | ||
|
||
import factory | ||
import faker | ||
from phonenumber_field.phonenumber import PhoneNumber | ||
|
||
from data.choices import CountryChoices | ||
from data.models.teleicare_history.etablissement import IcaEtablissement | ||
from data.utils.string_utils import make_random_str | ||
from data.factories.company import _make_siret, _make_vat, _make_phone_number | ||
|
||
|
||
class EtablissementFactory(factory.django.DjangoModelFactory): | ||
class Meta: | ||
model = IcaEtablissement | ||
|
||
etab_ident = factory.Sequence(lambda n: n + 1) | ||
etab_raison_sociale = factory.Faker("company", locale="FR") | ||
etab_enseigne = factory.Faker("company", locale="FR") | ||
etab_siret = factory.LazyFunction(_make_siret) | ||
etab_numero_tva_intra = factory.LazyFunction(_make_siret) | ||
pays_ident = factory.Faker("pyint", min_value=0, max_value=200) | ||
etab_nb_compte_autorise = factory.Faker("pyint", min_value=0, max_value=5) | ||
# contact | ||
etab_telephone = factory.LazyFunction(_make_phone_number) | ||
etab_courriel = factory.Faker("email", locale="FR") |
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,65 @@ | ||
from django.db import connection | ||
from django.test import TestCase | ||
|
||
from data.etl.teleicare_history.extractor import match_companies_on_siret_or_vat | ||
from data.factories.company import CompanyFactory, _make_siret, _make_vat | ||
from data.factories.teleicare_history import EtablissementFactory | ||
from data.models.teleicare_history.etablissement import IcaEtablissement | ||
|
||
|
||
class TeleicareHistoryImporterTestCase(TestCase): | ||
""" | ||
Cette classe vise à tester les fonction liées à l'import d'historique de la plateforme TeleIcare | ||
""" | ||
|
||
def setUp(self): | ||
""" | ||
Adapted from: https://stackoverflow.com/a/49800437 | ||
""" | ||
super().setUp() | ||
with connection.schema_editor() as schema_editor: | ||
schema_editor.create_model(IcaEtablissement) | ||
|
||
if IcaEtablissement._meta.db_table not in connection.introspection.table_names(): | ||
raise ValueError( | ||
"Table `{table_name}` is missing in test database.".format( | ||
table_name=IcaEtablissement._meta.db_table | ||
) | ||
) | ||
|
||
def tearDown(self): | ||
super().tearDown() | ||
|
||
with connection.schema_editor() as schema_editor: | ||
schema_editor.delete_model(IcaEtablissement) | ||
|
||
def test_match_companies_on_siret_or_vat(self): | ||
""" | ||
Une entreprise enregistrée dans Teleicare ayant le même SIRET ou n° TVA intracom | ||
qu'une entreprise enregistrée dans Compl'Alim doit être liée par le siccrf_id | ||
""" | ||
# create_model_table(IcaEtablissement) | ||
siret = _make_siret() | ||
etablissement_with_siret = EtablissementFactory(etab_siret=siret) | ||
company_with_siret = CompanyFactory(siret=siret) | ||
|
||
vat = _make_vat() | ||
etablissement_with_vat = EtablissementFactory(etab_siret=None, etab_numero_tva_intra=vat) | ||
company_with_vat = CompanyFactory(vat=vat) | ||
|
||
random_company = CompanyFactory() | ||
random_etablissement = EtablissementFactory() | ||
|
||
match_companies_on_siret_or_vat() | ||
company_with_siret.refresh_from_db() | ||
etablissement_with_siret.refresh_from_db() | ||
company_with_vat.refresh_from_db() | ||
etablissement_with_vat.refresh_from_db() | ||
random_company.refresh_from_db() | ||
random_etablissement.refresh_from_db() | ||
|
||
# self.assertEqual(company_with_siret.siccrf_id, etablissement_with_siret.etab_ident) | ||
self.assertEqual(company_with_vat.siccrf_id, etablissement_with_vat.etab_ident) | ||
self.assertNotEqual(random_company.siccrf_id, random_etablissement.etab_ident) | ||
self.assertEqual(random_company.siccrf_id, None) | ||
# delete_model_table(IcaEtablissement) |