def test_request_format_fallback_is_csv(execute_request): api_csv = ApiInsee(key=conf.SIRENE_API_CONSUMER_KEY, secret=conf.SIRENE_API_CONSUMER_SECRET, format='csv') request = api_csv.siret('39860733300059') assert request.header['Accept'] == 'text/csv'
def call_insee_api(siret): api_insee = ApiInsee(key=settings.API_INSEE_KEY, secret=settings.API_INSEE_SECRET) try: data = api_insee.siret(siret).get() except urllib.error.HTTPError as err: logger.error( "HTTP Error `%s` while calling Sirene - V3 API for SIRET %s", err.code, siret) return None return data
def test_unauthorized_credentials(): with pytest.raises(AuthExeption): api = ApiInsee( key = conf.SIRENE_API_CONSUMER_KEY+'wrongly', secret= conf.SIRENE_API_CONSUMER_SECRET )
def test_generate_token(): api = ApiInsee( key = conf.SIRENE_API_CONSUMER_KEY, secret= conf.SIRENE_API_CONSUMER_SECRET ) assert len(api.auth.token.access_token) > 0
#!/usr/bin/env python # -*- coding: utf-8 -*- import pytest import conftest as conf from api_insee import ApiInsee from api_insee.conf import API_VERSION import api_insee.criteria as Criteria __author__ = "Lenselle Nicolas" __copyright__ = "Lenselle Nicolas" __license__ = "mit" api = ApiInsee( key = conf.SIRENE_API_CONSUMER_KEY, secret = conf.SIRENE_API_CONSUMER_SECRET ) base_siret_url = API_VERSION['url'] + API_VERSION['path_siret'] def test_siret_search(execute_request): request = api.siret('39860733300059') unit = request.get() assert unit['etablissement']['siret'] == '39860733300059' assert unit['header']['statut'] == 200 assert request.url == base_siret_url + '/39860733300059' execute_request(request)
def test_missing_credentials(): with pytest.raises(AuthExeption): api = ApiInsee(False, False)