2020-12-21 13:51:29 +01:00
|
|
|
|
import freezegun
|
2017-05-12 15:34:56 +02:00
|
|
|
|
import pytest
|
2020-12-21 13:51:29 +01:00
|
|
|
|
from httmock import HTTMock, response
|
2017-05-12 15:34:56 +02:00
|
|
|
|
|
2022-03-18 09:46:37 +01:00
|
|
|
|
import tests.utils
|
2017-05-12 15:34:56 +02:00
|
|
|
|
from passerelle.apps.airquality.models import AirQuality
|
|
|
|
|
|
2020-12-21 13:51:29 +01:00
|
|
|
|
SAMPLE_RESPONSE = {
|
|
|
|
|
'licence': 'https://opendatacommons.org/licenses/odbl/',
|
|
|
|
|
'commune': 'LYON-1ER-ARRONDISSEMENT',
|
|
|
|
|
'code_insee': '69381',
|
|
|
|
|
'indices': {
|
|
|
|
|
'current_page': 1,
|
|
|
|
|
'data': [
|
|
|
|
|
{
|
|
|
|
|
'date': '2020-12-22',
|
|
|
|
|
'valeur': '26.6503231768126',
|
|
|
|
|
'couleur_html': '#5CCB60',
|
|
|
|
|
'qualificatif': 'Bon',
|
|
|
|
|
'type_valeur': 'prévision',
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
'date': '2020-12-21',
|
|
|
|
|
'valeur': '21.6876695818178',
|
|
|
|
|
'couleur_html': '#5CCB60',
|
|
|
|
|
'qualificatif': 'Bon',
|
|
|
|
|
'type_valeur': 'prévision',
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
'date': '2020-12-20',
|
|
|
|
|
'valeur': '26.1405508214683',
|
|
|
|
|
'couleur_html': '#5CCB60',
|
|
|
|
|
'qualificatif': 'Bon',
|
|
|
|
|
'type_valeur': 'prévision',
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
},
|
|
|
|
|
'first_page_url': 'https://api.atmo-aura.fr/communes/69381/indices?api_token=XXX&page=1',
|
|
|
|
|
'from': 1,
|
|
|
|
|
'last_page': 23,
|
|
|
|
|
'last_page_url': 'https://api.atmo-aura.fr/communes/69381/indices?api_token=XXX&page=23',
|
|
|
|
|
'next_page_url': 'https://api.atmo-aura.fr/communes/69381/indices?api_token=XXX&page=2',
|
|
|
|
|
'path': 'https://api.atmo-aura.fr/communes/69381/indices',
|
|
|
|
|
'per_page': 50,
|
|
|
|
|
'prev_page_url': None,
|
|
|
|
|
'to': 50,
|
|
|
|
|
'total': 1137,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SAMPLE_COMMENT_RESPONSE = {
|
|
|
|
|
'licence': 'https://opendatacommons.org/licenses/odbl/',
|
|
|
|
|
'commentaire': 'Jeudi 11 mai, le temps perturbé a permis d’avoir une bonne qualité de l’air sur la zone de surveillance.',
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-12 15:34:56 +02:00
|
|
|
|
|
|
|
|
|
@pytest.fixture
|
|
|
|
|
def airquality(db):
|
2020-12-21 13:51:29 +01:00
|
|
|
|
return AirQuality.objects.create(slug='atmo', atmo_aura_api_token='XXX')
|
2017-05-12 15:34:56 +02:00
|
|
|
|
|
|
|
|
|
|
2020-12-21 13:51:29 +01:00
|
|
|
|
def mocked_http(url, request):
|
|
|
|
|
if url.path.startswith('/commune'):
|
|
|
|
|
return response(200, SAMPLE_RESPONSE, request=request)
|
|
|
|
|
if url.path.startswith('/commentaire'):
|
|
|
|
|
return response(200, SAMPLE_COMMENT_RESPONSE, request=request)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@freezegun.freeze_time('2020-12-21')
|
2017-05-12 15:34:56 +02:00
|
|
|
|
def test_airquality_details(app, airquality):
|
2022-03-18 09:46:37 +01:00
|
|
|
|
endpoint = tests.utils.generic_endpoint_url('airquality', 'details', slug=airquality.slug)
|
2017-05-12 15:34:56 +02:00
|
|
|
|
assert endpoint == '/airquality/atmo/details'
|
2020-12-21 13:51:29 +01:00
|
|
|
|
with HTTMock(mocked_http):
|
2017-05-12 15:34:56 +02:00
|
|
|
|
resp = app.get(endpoint + '/fr/lyon/', status=200)
|
2020-12-21 13:51:29 +01:00
|
|
|
|
assert resp.json['data']['latest']['value'] == '21.6876695818178'
|
|
|
|
|
assert 'Jeudi 11 mai, le temps' in resp.json['data']['comment']
|
|
|
|
|
|
2017-05-12 15:34:56 +02:00
|
|
|
|
|
|
|
|
|
def test_airquality_details_unknown_city(app, airquality):
|
2022-03-18 09:46:37 +01:00
|
|
|
|
endpoint = tests.utils.generic_endpoint_url('airquality', 'details', slug=airquality.slug)
|
2022-03-17 16:47:33 +01:00
|
|
|
|
app.get(endpoint + '/fr/paris/', status=404)
|