Skip to content

Commit

Permalink
Réparons les tests que nous n'avions pas vu que nous avions cassés (#72)
Browse files Browse the repository at this point in the history
  • Loading branch information
tut-tuuut authored Jan 24, 2025
2 parents 3b99e04 + 29eeed5 commit 10d7525
Show file tree
Hide file tree
Showing 10 changed files with 47 additions and 37 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/django.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ name: Django CI

on:
push:
branches: [ "main" ]
branches: [ "main", "develop" ]
pull_request:
branches: [ "main" ]
branches: [ "main", "develop" ]

jobs:
tests:
Expand Down
1 change: 0 additions & 1 deletion gsl_demarches_simplifiees/tests.py

This file was deleted.

4 changes: 3 additions & 1 deletion gsl_demarches_simplifiees/tests/factories.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from datetime import UTC

import factory

from gsl_core.tests.factories import AdresseFactory
Expand Down Expand Up @@ -40,5 +42,5 @@ class Meta:
ds_number = factory.Faker("random_int", min=1000000, max=9999999)
ds_state = Dossier.STATE_ACCEPTE
ds_demandeur = factory.SubFactory(PersonneMoraleFactory)
ds_date_depot = factory.Faker("date_this_year", before_today=True)
ds_date_depot = factory.Faker("date_time_this_year", before_now=True, tzinfo=UTC)
porteur_de_projet_nature = factory.SubFactory(NaturePorteurProjetFactory)
7 changes: 5 additions & 2 deletions gsl_programmation/tasks.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from datetime import date
from datetime import UTC

from celery import shared_task
from django.db.models import Q
from django.utils import timezone

from gsl_demarches_simplifiees.models import Dossier
from gsl_programmation.models import Simulation, SimulationProjet
Expand Down Expand Up @@ -38,7 +39,9 @@ def add_enveloppe_projets_to_simulation(simulation_id):
Dossier.STATE_SANS_SUITE,
Dossier.STATE_REFUSE,
],
dossier_ds__ds_date_traitement__gte=date(2025, 1, 1),
dossier_ds__ds_date_traitement__gte=timezone.datetime(
2025, 1, 1, tzinfo=UTC
),
)
)
.all()
Expand Down
15 changes: 9 additions & 6 deletions gsl_programmation/tests/services/test_projet_services.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
from datetime import UTC

import pytest
from django.utils import timezone

from gsl_demarches_simplifiees.tests.factories import (
DossierFactory,
Expand All @@ -17,7 +20,7 @@ def simulation() -> Simulation:


@pytest.fixture
def projets_with_assiette(simulation) -> list[Projet]:
def projets_with_assiette(simulation):
for amount in (10_000, 20_000, 30_000):
p = ProjetFactory(assiette=amount)
SimulationProjetFactory(projet=p, simulation=simulation)
Expand All @@ -26,7 +29,7 @@ def projets_with_assiette(simulation) -> list[Projet]:
@pytest.fixture
def projets_without_assiette_but_finance_cout_total_from_dossier_ds(
simulation,
) -> list[Projet]:
):
for amount in (15_000, 25_000):
p = ProjetFactory(
dossier_ds__finance_cout_total=amount,
Expand All @@ -37,7 +40,7 @@ def projets_without_assiette_but_finance_cout_total_from_dossier_ds(


@pytest.fixture
def projets_with_assiette_but_not_in_simulation() -> list[Projet]:
def projets_with_assiette_but_not_in_simulation():
p = ProjetFactory(assiette=50_000)
SimulationProjetFactory(projet=p)

Expand Down Expand Up @@ -177,17 +180,17 @@ def test_add_filters_to_projets_qs(create_projets):
def test_add_ordering_to_projets_qs():
projet1 = ProjetFactory(
dossier_ds__finance_cout_total=100,
dossier_ds__ds_date_depot="2023-01-01",
dossier_ds__ds_date_depot=timezone.datetime(2023, 1, 1, tzinfo=UTC),
address__commune__name="Beaune",
)
projet2 = ProjetFactory(
dossier_ds__finance_cout_total=200,
dossier_ds__ds_date_depot="2023-01-02",
dossier_ds__ds_date_depot=timezone.datetime(2023, 1, 2, tzinfo=UTC),
address__commune__name="Dijon",
)
projet3 = ProjetFactory(
dossier_ds__finance_cout_total=150,
dossier_ds__ds_date_depot="2023-01-03",
dossier_ds__ds_date_depot=timezone.datetime(2023, 1, 3, tzinfo=UTC),
address__commune__name="Auxonne",
)

Expand Down
36 changes: 18 additions & 18 deletions gsl_programmation/tests/test_tasks.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from datetime import datetime
from datetime import UTC, datetime
from decimal import Decimal

import pytest
Expand Down Expand Up @@ -53,14 +53,14 @@ def dsil_simulation(region_perimetre):
def detr_projets(departement_perimetre):
projets = []
for montant, assiette, state, date_traitement in [
(1_000, 2_000, Dossier.STATE_EN_CONSTRUCTION, datetime(2024, 1, 1)),
(600, None, Dossier.STATE_EN_INSTRUCTION, datetime(2023, 1, 1)),
(2_000, 3_000, Dossier.STATE_ACCEPTE, datetime(2024, 1, 1)),
(2_000, 4_000, Dossier.STATE_ACCEPTE, datetime(2025, 1, 1)),
(1_500, None, Dossier.STATE_REFUSE, datetime(2024, 1, 1)),
(1_500, None, Dossier.STATE_REFUSE, datetime(2025, 1, 1)),
(6_500, 0, Dossier.STATE_SANS_SUITE, datetime(2024, 1, 1)),
(2_500, 0, Dossier.STATE_SANS_SUITE, datetime(2025, 1, 1)),
(1_000, 2_000, Dossier.STATE_EN_CONSTRUCTION, datetime(2024, 1, 1, tzinfo=UTC)),
(600, None, Dossier.STATE_EN_INSTRUCTION, datetime(2023, 1, 1, tzinfo=UTC)),
(2_000, 3_000, Dossier.STATE_ACCEPTE, datetime(2024, 1, 1, tzinfo=UTC)),
(2_000, 4_000, Dossier.STATE_ACCEPTE, datetime(2025, 1, 1, tzinfo=UTC)),
(1_500, None, Dossier.STATE_REFUSE, datetime(2024, 1, 1, tzinfo=UTC)),
(1_500, None, Dossier.STATE_REFUSE, datetime(2025, 1, 1, tzinfo=UTC)),
(6_500, 0, Dossier.STATE_SANS_SUITE, datetime(2024, 1, 1, tzinfo=UTC)),
(2_500, 0, Dossier.STATE_SANS_SUITE, datetime(2025, 1, 1, tzinfo=UTC)),
]:
projets.append(
ProjetFactory(
Expand All @@ -84,14 +84,14 @@ def detr_projets(departement_perimetre):
def dsil_projets(departement_perimetre):
projets = []
for montant, assiette, state, date_traitement in [
(1_000, 2_000, Dossier.STATE_EN_CONSTRUCTION, datetime(2024, 1, 1)),
(600, None, Dossier.STATE_EN_INSTRUCTION, datetime(2023, 1, 1)),
(2_000, 4_000, Dossier.STATE_ACCEPTE, datetime(2024, 12, 21)),
(5_000, 10_000, Dossier.STATE_ACCEPTE, datetime(2025, 1, 1)),
(3_500, None, Dossier.STATE_REFUSE, datetime(2024, 12, 31)),
(1_500, None, Dossier.STATE_REFUSE, datetime(2025, 1, 1)),
(2_500, 0, Dossier.STATE_SANS_SUITE, datetime(2024, 12, 13)),
(2_500, 0, Dossier.STATE_SANS_SUITE, datetime(2025, 1, 1)),
(1_000, 2_000, Dossier.STATE_EN_CONSTRUCTION, datetime(2024, 1, 1, tzinfo=UTC)),
(600, None, Dossier.STATE_EN_INSTRUCTION, datetime(2023, 1, 1, tzinfo=UTC)),
(2_000, 4_000, Dossier.STATE_ACCEPTE, datetime(2024, 12, 21, tzinfo=UTC)),
(5_000, 10_000, Dossier.STATE_ACCEPTE, datetime(2025, 1, 1, tzinfo=UTC)),
(3_500, None, Dossier.STATE_REFUSE, datetime(2024, 12, 31, tzinfo=UTC)),
(1_500, None, Dossier.STATE_REFUSE, datetime(2025, 1, 1, tzinfo=UTC)),
(2_500, 0, Dossier.STATE_SANS_SUITE, datetime(2024, 12, 13, tzinfo=UTC)),
(2_500, 0, Dossier.STATE_SANS_SUITE, datetime(2025, 1, 1, tzinfo=UTC)),
]:
projets.append(
ProjetFactory(
Expand All @@ -112,7 +112,7 @@ def dsil_projets(departement_perimetre):

@pytest.mark.django_db
def test_add_enveloppe_projets_to_detr_simulation(
detr_simulation, detr_projets, dsil_projet
detr_simulation, detr_projets, dsil_projets
):
add_enveloppe_projets_to_simulation(detr_simulation.id)

Expand Down
3 changes: 1 addition & 2 deletions gsl_programmation/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
PerimetreDepartementalFactory,
RequestFactory,
)
from gsl_programmation.models import Simulation
from gsl_programmation.tests.factories import DetrEnveloppeFactory, SimulationFactory
from gsl_programmation.views import SimulationListView

Expand All @@ -28,7 +27,7 @@ def view() -> SimulationListView:


@pytest.fixture
def simulations(perimetre_departemental) -> list[Simulation]:
def simulations(perimetre_departemental):
enveloppe = DetrEnveloppeFactory(perimetre=perimetre_departemental)
SimulationFactory(enveloppe=enveloppe)
SimulationFactory(enveloppe=enveloppe)
Expand Down
2 changes: 1 addition & 1 deletion gsl_programmation/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from urllib.parse import parse_qs


def replace_comma_by_dot(value: str | None) -> float:
def replace_comma_by_dot(value: str | None) -> float | None:
"""
Convert a string with spaces and commas to a float.
Example: "10 000 ,00" -> 10000.00
Expand Down
7 changes: 5 additions & 2 deletions gsl_projet/tests/test_views.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
from datetime import UTC

import pytest
from django.utils import timezone

from gsl_core.models import Collegue, Departement
from gsl_core.tests.factories import (
Expand Down Expand Up @@ -73,13 +76,13 @@ def test_get_ordering(req, view, tri_param, expected_ordering):
@pytest.fixture
def projets(demandeur) -> list[Projet]:
projet0 = ProjetFactory(
dossier_ds__ds_date_depot="2024-09-01",
dossier_ds__ds_date_depot=timezone.datetime(2024, 9, 1, tzinfo=UTC),
dossier_ds__finance_cout_total=1000,
address__commune__name="Commune A",
demandeur=demandeur,
)
projet1 = ProjetFactory(
dossier_ds__ds_date_depot="2024-09-02",
dossier_ds__ds_date_depot=timezone.datetime(2024, 9, 2, tzinfo=UTC),
dossier_ds__finance_cout_total=2000,
address__commune__name="Commune B",
demandeur=demandeur,
Expand Down
5 changes: 3 additions & 2 deletions gsl_projet/views.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import datetime
from datetime import UTC

from django.shortcuts import get_object_or_404, render
from django.urls import reverse
from django.utils import timezone
from django.views.decorators.http import require_GET
from django.views.generic import ListView

Expand Down Expand Up @@ -94,7 +95,7 @@ def get_context_data(self, **kwargs):

def get_queryset(self):
qs = Projet.objects.for_user(self.request.user).filter(
dossier_ds__ds_date_depot__gte=datetime.date(2024, 9, 1)
dossier_ds__ds_date_depot__gte=timezone.datetime(2024, 9, 1, tzinfo=UTC)
)
qs = ProjetService.add_filters_to_projets_qs(qs, self.request.GET)
qs = ProjetService.add_ordering_to_projets_qs(qs, self.request.GET.get("tri"))
Expand Down

0 comments on commit 10d7525

Please sign in to comment.