Skip to content

Commit

Permalink
add tests for activity edit view
Browse files Browse the repository at this point in the history
  • Loading branch information
SebastienReuiller committed Oct 15, 2024
1 parent c8f2a34 commit 15f5d9b
Show file tree
Hide file tree
Showing 3 changed files with 379 additions and 4 deletions.
4 changes: 2 additions & 2 deletions lemarche/siaes/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -740,7 +740,7 @@ class SiaeActivityAdmin(admin.ModelAdmin):
search_fields = ["id", "siae__id", "siae__name"]
search_help_text = "Cherche sur les champs : ID, Structure (ID, Nom)"

autocomplete_fields = ["siae", "sectors", "location"]
autocomplete_fields = ["siae", "sectors", "locations"]
readonly_fields = ["created_at", "updated_at"]

fieldsets = (
Expand All @@ -759,7 +759,7 @@ class SiaeActivityAdmin(admin.ModelAdmin):
(
"Localisation et périmètre d'intervention",
{
"fields": ("location", "geo_range", "geo_range_custom_distance"),
"fields": ("locations", "geo_range", "geo_range_custom_distance"),
},
),
("Dates", {"fields": ("created_at", "updated_at")}),
Expand Down
18 changes: 17 additions & 1 deletion lemarche/siaes/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import factory.fuzzy
from factory.django import DjangoModelFactory

from lemarche.sectors.factories import SectorGroupFactory
from lemarche.siaes import constants as siae_constants
from lemarche.siaes.models import (
Siae,
Expand Down Expand Up @@ -69,13 +70,28 @@ class SiaeActivityFactory(DjangoModelFactory):
class Meta:
model = SiaeActivity

presta_type = factory.List([factory.fuzzy.FuzzyChoice([key for (key, value) in siae_constants.PRESTA_CHOICES])])
class Params:
with_country_perimeter = factory.Trait(geo_range=siae_constants.GEO_RANGE_COUNTRY)
with_custom_distance_perimeter = factory.Trait(
geo_range=siae_constants.GEO_RANGE_CUSTOM,
geo_range_custom_distance=factory.fuzzy.FuzzyInteger(1, 100),
)
with_zones_perimeter = factory.Trait(geo_range=siae_constants.GEO_RANGE_ZONES)

sector_group = factory.SubFactory(SectorGroupFactory)

presta_type = factory.List([factory.fuzzy.FuzzyChoice([key for (key, _) in siae_constants.PRESTA_CHOICES])])

@factory.post_generation
def sectors(self, create, extracted, **kwargs):
if extracted:
self.sectors.add(*extracted)

@factory.post_generation
def locations(self, create, extracted, **kwargs):
if extracted:
self.locations.add(*extracted)


class SiaeOfferFactory(DjangoModelFactory):
class Meta:
Expand Down
Loading

0 comments on commit 15f5d9b

Please sign in to comment.