-
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.
Ajout de modèles pour la suite (#16)
- Loading branch information
Showing
22 changed files
with
615 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -70,6 +70,7 @@ | |
# gsl apps: | ||
"gsl_core", | ||
"gsl_demarches_simplifiees", | ||
"gsl_projet", | ||
"gsl_pages", | ||
"gsl_oidc", | ||
] | ||
|
143 changes: 143 additions & 0 deletions
143
gsl_core/migrations/0003_commune_departement_region_adresse_and_more.py
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,143 @@ | ||
# Generated by Django 5.1.1 on 2024-11-06 14:22 | ||
|
||
import django.db.models.deletion | ||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
dependencies = [ | ||
("gsl_core", "0002_collegue_proconnect_chorusdt_and_more"), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name="Commune", | ||
fields=[ | ||
("created_at", models.DateTimeField(auto_now_add=True)), | ||
("updated_at", models.DateTimeField(auto_now=True)), | ||
( | ||
"insee_code", | ||
models.CharField( | ||
primary_key=True, | ||
serialize=False, | ||
unique=True, | ||
verbose_name="Code INSEE", | ||
), | ||
), | ||
("name", models.CharField(verbose_name="Nom")), | ||
], | ||
options={ | ||
"abstract": False, | ||
}, | ||
), | ||
migrations.CreateModel( | ||
name="Departement", | ||
fields=[ | ||
("created_at", models.DateTimeField(auto_now_add=True)), | ||
("updated_at", models.DateTimeField(auto_now=True)), | ||
( | ||
"insee_code", | ||
models.CharField( | ||
primary_key=True, | ||
serialize=False, | ||
unique=True, | ||
verbose_name="Code INSEE", | ||
), | ||
), | ||
("name", models.CharField(verbose_name="Nom")), | ||
], | ||
options={ | ||
"verbose_name": "Département", | ||
}, | ||
), | ||
migrations.CreateModel( | ||
name="Region", | ||
fields=[ | ||
("created_at", models.DateTimeField(auto_now_add=True)), | ||
("updated_at", models.DateTimeField(auto_now=True)), | ||
( | ||
"insee_code", | ||
models.CharField( | ||
primary_key=True, | ||
serialize=False, | ||
unique=True, | ||
verbose_name="Code INSEE", | ||
), | ||
), | ||
("name", models.CharField(verbose_name="Nom")), | ||
], | ||
options={ | ||
"verbose_name": "Région", | ||
}, | ||
), | ||
migrations.CreateModel( | ||
name="Adresse", | ||
fields=[ | ||
( | ||
"id", | ||
models.BigAutoField( | ||
auto_created=True, | ||
primary_key=True, | ||
serialize=False, | ||
verbose_name="ID", | ||
), | ||
), | ||
("created_at", models.DateTimeField(auto_now_add=True)), | ||
("updated_at", models.DateTimeField(auto_now=True)), | ||
("label", models.TextField(verbose_name="Adresse complète")), | ||
("postal_code", models.CharField(verbose_name="Code postal")), | ||
("street_address", models.CharField(verbose_name="Adresse")), | ||
( | ||
"commune", | ||
models.ForeignKey( | ||
on_delete=django.db.models.deletion.PROTECT, | ||
to="gsl_core.commune", | ||
), | ||
), | ||
], | ||
options={ | ||
"abstract": False, | ||
}, | ||
), | ||
migrations.AddField( | ||
model_name="commune", | ||
name="departement", | ||
field=models.ForeignKey( | ||
on_delete=django.db.models.deletion.PROTECT, to="gsl_core.departement" | ||
), | ||
), | ||
migrations.CreateModel( | ||
name="Arrondissement", | ||
fields=[ | ||
("created_at", models.DateTimeField(auto_now_add=True)), | ||
("updated_at", models.DateTimeField(auto_now=True)), | ||
( | ||
"insee_code", | ||
models.CharField( | ||
primary_key=True, | ||
serialize=False, | ||
unique=True, | ||
verbose_name="Code INSEE", | ||
), | ||
), | ||
("name", models.CharField(verbose_name="Nom")), | ||
( | ||
"departement", | ||
models.ForeignKey( | ||
on_delete=django.db.models.deletion.PROTECT, | ||
to="gsl_core.departement", | ||
), | ||
), | ||
], | ||
options={ | ||
"abstract": False, | ||
}, | ||
), | ||
migrations.AddField( | ||
model_name="departement", | ||
name="region", | ||
field=models.ForeignKey( | ||
on_delete=django.db.models.deletion.PROTECT, to="gsl_core.region" | ||
), | ||
), | ||
] |
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,58 @@ | ||
import factory | ||
|
||
from ..models import Adresse, Arrondissement, Collegue, Commune, Departement, Region | ||
|
||
|
||
class CollegueFactory(factory.django.DjangoModelFactory): | ||
class Meta: | ||
model = Collegue | ||
|
||
username = factory.Faker("user_name") | ||
email = factory.Faker("email") | ||
is_staff = False | ||
is_active = True | ||
|
||
|
||
class RegionFactory(factory.django.DjangoModelFactory): | ||
class Meta: | ||
model = Region | ||
|
||
insee_code = factory.Sequence(lambda n: f"{n}") | ||
name = factory.Faker("word", locale="fr_FR") | ||
|
||
|
||
class DepartementFactory(factory.django.DjangoModelFactory): | ||
class Meta: | ||
model = Departement | ||
|
||
insee_code = factory.Sequence(lambda n: f"{n}") | ||
name = factory.Faker("word", locale="fr_FR") | ||
region = factory.SubFactory(RegionFactory) | ||
|
||
|
||
class ArrondissementFactory(factory.django.DjangoModelFactory): | ||
class Meta: | ||
model = Arrondissement | ||
|
||
insee_code = factory.Sequence(lambda n: f"{n}") | ||
name = factory.Faker("city", locale="fr_FR") | ||
departement = factory.SubFactory(DepartementFactory) | ||
|
||
|
||
class CommuneFactory(factory.django.DjangoModelFactory): | ||
class Meta: | ||
model = Commune | ||
|
||
insee_code = factory.Sequence(lambda n: f"{n}") | ||
name = factory.Faker("city", locale="fr_FR") | ||
departement = factory.SubFactory(DepartementFactory) | ||
|
||
|
||
class AdresseFactory(factory.django.DjangoModelFactory): | ||
class Meta: | ||
model = Adresse | ||
|
||
label = factory.Faker("address", locale="fr_FR") | ||
postal_code = factory.Faker("postcode", locale="fr_FR") | ||
commune = factory.SubFactory(CommuneFactory) | ||
street_address = factory.Faker("street_address", locale="fr_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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import pytest | ||
|
||
from ..models import Adresse, Arrondissement, Collegue, Commune, Departement, Region | ||
from .factories import ( | ||
AdresseFactory, | ||
ArrondissementFactory, | ||
CollegueFactory, | ||
CommuneFactory, | ||
DepartementFactory, | ||
RegionFactory, | ||
) | ||
|
||
pytestmark = pytest.mark.django_db | ||
|
||
test_data = ( | ||
(CollegueFactory, Collegue), | ||
(RegionFactory, Region), | ||
(DepartementFactory, Departement), | ||
(ArrondissementFactory, Arrondissement), | ||
(CommuneFactory, Commune), | ||
(AdresseFactory, Adresse), | ||
) | ||
|
||
|
||
@pytest.mark.parametrize("factory,expected_class", test_data) | ||
def test_every_factory_can_be_called_twice(factory, expected_class): | ||
for _ in range(2): | ||
obj = factory() | ||
assert isinstance(obj, expected_class) |
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
Empty file.
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,23 @@ | ||
import factory | ||
|
||
from ..models import Demarche, Dossier | ||
|
||
|
||
class DemarcheFactory(factory.django.DjangoModelFactory): | ||
class Meta: | ||
model = Demarche | ||
|
||
ds_id = factory.Sequence(lambda n: f"demarche-{n}") | ||
ds_number = factory.Faker("random_int", min=1000000, max=9999999) | ||
ds_title = "Titre de la démarche" | ||
ds_state = Demarche.STATE_PUBLIEE | ||
|
||
|
||
class DossierFactory(factory.django.DjangoModelFactory): | ||
class Meta: | ||
model = Dossier | ||
|
||
ds_demarche = factory.SubFactory(DemarcheFactory) | ||
ds_id = factory.Sequence(lambda n: f"dossier-{n}") | ||
ds_number = factory.Faker("random_int", min=1000000, max=9999999) | ||
ds_state = Dossier.STATE_ACCEPTE |
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,22 @@ | ||
import pytest | ||
|
||
from gsl_demarches_simplifiees.models import ( | ||
Demarche, | ||
Dossier, | ||
) | ||
|
||
from .factories import DemarcheFactory, DossierFactory | ||
|
||
pytestmark = pytest.mark.django_db | ||
|
||
test_data = ( | ||
(DemarcheFactory, Demarche), | ||
(DossierFactory, Dossier), | ||
) | ||
|
||
|
||
@pytest.mark.parametrize("factory,expected_class", test_data) | ||
def test_every_factory_can_be_called_twice(factory, expected_class): | ||
for _ in range(2): | ||
obj = factory() | ||
assert isinstance(obj, expected_class) |
Empty file.
Oops, something went wrong.