-
Notifications
You must be signed in to change notification settings - Fork 6
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
11 changed files
with
111 additions
and
16 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
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,13 @@ | ||
from factory.django import DjangoModelFactory | ||
|
||
from envergo.hedges.models import HedgeData | ||
|
||
|
||
class HedgeDataFactory(DjangoModelFactory): | ||
class Meta: | ||
model = HedgeData | ||
|
||
data = ( | ||
'[{"id":"D1","latLngs":[{"lat":43.687177253462714,"lng":3.58479488061279},' | ||
'{"lat":43.687301385409,"lng":3.5859104885342323}],"type":"TO_REMOVE"}]' | ||
) |
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
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,17 @@ | ||
import factory | ||
from factory.django import DjangoModelFactory | ||
|
||
from envergo.hedges.tests.factories import HedgeDataFactory | ||
from envergo.petitions.models import PetitionProject | ||
|
||
|
||
class PetitionProjectFactory(DjangoModelFactory): | ||
class Meta: | ||
model = PetitionProject | ||
|
||
reference = "ABC123" | ||
moulinette_url = ( | ||
"http://haie.local:3000/simulateur/resultat/?profil=autre&motif=autre&reimplantation=non" | ||
"&haies=4406e311-d379-488f-b80e-68999a142c9d&department=44&travaux=destruction&element=haie" | ||
) | ||
hedge_data = factory.SubFactory(HedgeDataFactory) |
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,49 @@ | ||
from unittest.mock import patch | ||
|
||
import pytest | ||
from django.test import RequestFactory | ||
|
||
from envergo.moulinette.tests.factories import ConfigHaieFactory | ||
from envergo.petitions.tests.factories import PetitionProjectFactory | ||
from envergo.petitions.views import PetitionProjectCreate | ||
|
||
pytestmark = pytest.mark.django_db | ||
|
||
|
||
@patch("requests.post") | ||
@patch("envergo.petitions.views.reverse") | ||
def test_pre_fill_demarche_simplifiee(mock_reverse, mock_post): | ||
mock_reverse.return_value = "http://haie.local:3000/projet/ABC123" | ||
|
||
mock_post.return_value.status_code = 200 | ||
mock_post.return_value.json.return_value = { | ||
"dossier_url": "demarche_simplifiee_url", | ||
"state": "prefilled", | ||
"dossier_id": "RG9zc2llci0yMTA3NTY2NQ==", | ||
"dossier_number": 21075665, | ||
"dossier_prefill_token": "W3LFL68vStyL62kRBdJSGU1f", | ||
} | ||
ConfigHaieFactory() | ||
|
||
view = PetitionProjectCreate() | ||
factory = RequestFactory() | ||
request = factory.get("") | ||
view.request = request | ||
|
||
petition_project = PetitionProjectFactory() | ||
demarche_simplifiee_url = view.pre_fill_demarche_simplifiee(petition_project) | ||
|
||
assert demarche_simplifiee_url == "demarche_simplifiee_url" | ||
|
||
# Assert the body of the requests.post call | ||
expected_body = { | ||
"champ_123": "Autre (collectivité, aménageur, gestionnaire de réseau, " | ||
"particulier, etc.)", | ||
"champ_321": "ABC123", | ||
"champ_456": None, # improve this test by configuring a result for bcae8 | ||
"champ_654": "http://haie.local:3000/simulateur/resultat/?profil=autre&motif=autre&reimplantation=non" | ||
"&haies=4406e311-d379-488f-b80e-68999a142c9d&department=44&travaux=destruction&element=haie", | ||
"champ_789": "http://haie.local:3000/projet/ABC123", | ||
} | ||
mock_post.assert_called_once() | ||
assert mock_post.call_args[1]["json"] == expected_body |
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