-
Notifications
You must be signed in to change notification settings - Fork 25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
API: ajout des filtres departement
et departement_postes
sur la route /api/v1/siaes/
#4270
Changes from all commits
66cf8e5
3f99e13
2ca6dde
5396341
b144e94
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,9 @@ | ||
import json | ||
|
||
from django.urls import reverse | ||
from rest_framework.test import APIClient, APITestCase | ||
|
||
from itou.companies.enums import CompanyKind, ContractType | ||
from tests.cities.factories import create_city_guerande, create_city_saint_andre | ||
from tests.companies.factories import CompanyFactory, JobDescriptionFactory | ||
from tests.users.factories import EmployerFactory | ||
from tests.utils.test import BASE_NUM_QUERIES | ||
|
||
from ..utils import _str_with_tz | ||
|
@@ -16,18 +13,19 @@ | |
|
||
|
||
class SiaeAPIFetchListTest(APITestCase): | ||
@classmethod | ||
def setUpTestData(cls): | ||
# We create 2 cities and 2 siaes in Saint-Andre. | ||
cls.saint_andre = create_city_saint_andre() | ||
cls.guerande = create_city_guerande() | ||
cls.company_without_jobs = CompanyFactory(kind=CompanyKind.EI, department="44", coords=cls.saint_andre.coords) | ||
cls.company_with_jobs = CompanyFactory( | ||
with_jobs=True, romes=("N1101", "N1105", "N1103", "N4105"), department="44", coords=cls.saint_andre.coords | ||
) | ||
|
||
def setUp(self): | ||
super().setUp() | ||
self.client = APIClient() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. À se demander si le |
||
self.user = EmployerFactory() | ||
|
||
# We create 2 cities and 2 siaes in Saint-Andre. | ||
self.saint_andre = create_city_saint_andre() | ||
self.guerande = create_city_guerande() | ||
CompanyFactory(kind=CompanyKind.EI, department="44", coords=self.saint_andre.coords) | ||
CompanyFactory( | ||
with_jobs=True, romes=("N1101", "N1105", "N1103", "N4105"), department="44", coords=self.saint_andre.coords | ||
) | ||
|
||
def test_performances(self): | ||
num_queries = BASE_NUM_QUERIES | ||
|
@@ -41,13 +39,15 @@ def test_performances(self): | |
|
||
def test_fetch_siae_list_without_params(self): | ||
""" | ||
The query parameters for INSEE code and distance are mandatories | ||
The query parameters need to contain either a department or both an INSEE code and a distance | ||
""" | ||
response = self.client.get(ENDPOINT_URL, format="json") | ||
|
||
self.assertContains( | ||
response, "Les paramètres `code_insee` et `distance_max_km` sont obligatoires.", status_code=400 | ||
) | ||
assert response.status_code == 400 | ||
assert response.json() == [ | ||
"Les paramètres `code_insee` et `distance_max_km` sont obligatoires si ni `departement` ni " | ||
"`postes_dans_le_departement` ne sont spécifiés." | ||
] | ||
|
||
def test_fetch_siae_list_with_too_high_distance(self): | ||
""" | ||
|
@@ -56,9 +56,8 @@ def test_fetch_siae_list_with_too_high_distance(self): | |
query_params = {"code_insee": 44056, "distance_max_km": 200} | ||
response = self.client.get(ENDPOINT_URL, query_params, format="json") | ||
|
||
self.assertContains( | ||
response, "Le paramètre `distance_max_km` doit être compris entre 0 et 100", status_code=400 | ||
) | ||
assert response.status_code == 400 | ||
assert response.json() == {"distance_max_km": ["Assurez-vous que cette valeur est inférieure ou égale à 100."]} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Faudrait-il également une mention dans la release note de ce changement ? C’est un breaking change. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Certes mais comme on est sur un cas d'erreur et que j'espère qu'aucun système automatique ne s'amuse à envoyer des données invalides j'aurais tendance à laisser tel quel. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Juste une mention dans le changelog ne me semble pas trop lourde, et évite des surprises aux utilisateurs ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Mais comment ajouter des choses dans le changelog en dehors du titre de cette PR ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. C'est un coup à péter la prochaine PR de changelog non ? |
||
|
||
def test_fetch_siae_list_with_negative_distance(self): | ||
""" | ||
|
@@ -67,9 +66,8 @@ def test_fetch_siae_list_with_negative_distance(self): | |
query_params = {"code_insee": 44056, "distance_max_km": -10} | ||
response = self.client.get(ENDPOINT_URL, query_params, format="json") | ||
|
||
self.assertContains( | ||
response, "Le paramètre `distance_max_km` doit être compris entre 0 et 100", status_code=400 | ||
) | ||
assert response.status_code == 400 | ||
assert response.json() == {"distance_max_km": ["Assurez-vous que cette valeur est supérieure ou égale à 0."]} | ||
|
||
def test_fetch_siae_list_with_invalid_code_insee(self): | ||
""" | ||
|
@@ -162,9 +160,20 @@ def test_fetch_siae_list(self): | |
query_params = {"code_insee": self.saint_andre.code_insee, "distance_max_km": 100} | ||
response = self.client.get(ENDPOINT_URL, query_params, format="json") | ||
|
||
body = json.loads(response.content) | ||
assert body["count"] == 2 | ||
assert response.json()["count"] == 2 | ||
assert response.status_code == 200 | ||
|
||
# Add a department filter matching the companies | ||
query_params["departement"] = "44" | ||
response = self.client.get(ENDPOINT_URL, query_params, format="json") | ||
assert response.status_code == 200 | ||
assert response.json()["count"] == 2 | ||
|
||
# Add a department filter NOT matching the companies | ||
query_params["departement"] = "33" | ||
response = self.client.get(ENDPOINT_URL, query_params, format="json") | ||
assert response.status_code == 200 | ||
assert response.json()["count"] == 0 | ||
|
||
def test_fetch_siae_list_too_far(self): | ||
""" | ||
|
@@ -174,10 +183,55 @@ def test_fetch_siae_list_too_far(self): | |
query_params = {"code_insee": self.guerande.code_insee, "distance_max_km": 10} | ||
response = self.client.get(ENDPOINT_URL, query_params, format="json") | ||
|
||
body = json.loads(response.content) | ||
assert body["count"] == 0 | ||
assert response.json()["count"] == 0 | ||
assert response.status_code == 200 | ||
|
||
def test_fetch_siae_list_by_department(self): | ||
# Declare company in 56 despite its coordinates | ||
company56 = CompanyFactory(kind=CompanyKind.EI, department="56", coords=self.saint_andre.coords) | ||
query_params = {"departement": "44"} | ||
response = self.client.get(ENDPOINT_URL, query_params, format="json") | ||
|
||
body = response.json() | ||
assert body["count"] == 2 | ||
assert response.status_code == 200 | ||
assert company56.siret not in {company["siret"] for company in body["results"]} | ||
|
||
def test_fetch_siae_list_by_postes_dans_le_departement(self): | ||
# Declare company in 56 | ||
company56 = CompanyFactory(kind=CompanyKind.EI, department="56") | ||
query_params = {"postes_dans_le_departement": "56"} | ||
response = self.client.get(ENDPOINT_URL, query_params, format="json") | ||
|
||
assert response.status_code == 200 | ||
assert response.json()["count"] == 0 # No job in 56 | ||
|
||
# Add a job without location, it should use the company department | ||
JobDescriptionFactory(company=company56, location=None) | ||
response = self.client.get(ENDPOINT_URL, query_params, format="json") | ||
assert response.status_code == 200 | ||
assert response.json()["count"] == 1 | ||
|
||
query_params = {"postes_dans_le_departement": "44"} | ||
response = self.client.get(ENDPOINT_URL, query_params, format="json") | ||
|
||
assert response.status_code == 200 | ||
body = response.json() | ||
assert body["count"] == 1 | ||
assert body["results"][0]["siret"] == self.company_with_jobs.siret | ||
|
||
xavfernandez marked this conversation as resolved.
Show resolved
Hide resolved
|
||
# Add a new job for company 56 in department 44 | ||
JobDescriptionFactory(company=company56, location=self.guerande) | ||
response = self.client.get(ENDPOINT_URL, query_params, format="json") | ||
|
||
assert response.status_code == 200 | ||
body = response.json() | ||
assert body["count"] == 2 | ||
assert {body["results"][0]["siret"], body["results"][1]["siret"]} == { | ||
self.company_with_jobs.siret, | ||
company56.siret, | ||
} | ||
|
||
def test_fetch_siae_list_rate_limits(self): | ||
query_params = {"code_insee": self.saint_andre.code_insee, "distance_max_km": 100} | ||
# Declared in itou.api.siae_api.viewsets.RestrictedUserRateThrottle. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
departement_postes
pour correspondre au nom du filtre ?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
postes_dans_le_departement
?