def get_venue_bank_information_application_details_by_application_id(
        application_id: str) -> ApplicationDetail:
    response_application_details = get_application_details(
        application_id,
        procedure_id=settings.DMS_VENUE_PROCEDURE_ID,
        token=settings.DMS_TOKEN)

    application_details = ApplicationDetail(
        siren=response_application_details["dossier"]["entreprise"]["siren"],
        status=_get_status_from_demarches_simplifiees_application_state(
            response_application_details["dossier"]["state"]),
        application_id=int(response_application_details["dossier"]["id"]),
        iban=format_raw_iban_and_bic(
            _find_value_in_fields(
                response_application_details["dossier"]["champs"], "IBAN")),
        bic=format_raw_iban_and_bic(
            _find_value_in_fields(
                response_application_details["dossier"]["champs"], "BIC")),
        siret=_find_value_in_fields(
            response_application_details["dossier"]["champs"],
            FIELD_FOR_VENUE_WITH_SIRET),
        venue_name=_find_value_in_fields(
            response_application_details["dossier"]["champs"],
            FIELD_FOR_VENUE_WITHOUT_SIRET),
        modification_date=datetime.strptime(
            response_application_details["dossier"]["updated_at"],
            DATE_ISO_FORMAT),
    )
    return application_details
def run(procedure_id: int, use_graphql_api: bool = False) -> None:
    logger.info(
        "[BATCH][REMOTE IMPORT BENEFICIARIES] Start import from Démarches Simplifiées for "
        "procedure = %s - Procedure %s",
        procedure_id,
        procedure_id,
    )
    retry_ids = find_applications_ids_to_retry()
    logger.info(
        "[BATCH][REMOTE IMPORT BENEFICIARIES] %i previous applications to retry - Procedure %s",
        len(retry_ids),
        procedure_id,
    )

    existing_applications_ids = get_already_processed_applications_ids(procedure_id)
    if use_graphql_api:
        client = DMSGraphQLClient()
        for application_details in client.get_applications_with_details(
            procedure_id, GraphQLApplicationStates.accepted
        ):
            application_id = application_details["number"]
            if application_id in existing_applications_ids:
                continue
            process_application(
                procedure_id,
                application_id,
                application_details,
                retry_ids,
                parsing_function=parse_beneficiary_information_graphql,
            )

    else:
        applications_ids = get_closed_application_ids_for_demarche_simplifiee(procedure_id, settings.DMS_TOKEN)
        logger.info(
            "[BATCH][REMOTE IMPORT BENEFICIARIES] %i new applications to process - Procedure %s",
            len(applications_ids),
            procedure_id,
        )

        for application_id in retry_ids + applications_ids:
            application_details = get_application_details(application_id, procedure_id, settings.DMS_TOKEN)

            process_application(
                procedure_id,
                application_id,
                application_details,
                retry_ids,
                parsing_function=parse_beneficiary_information,
            )

    logger.info(
        "[BATCH][REMOTE IMPORT BENEFICIARIES] End import from Démarches Simplifiées - Procedure %s", procedure_id
    )
Пример #3
0
    def test_calls_demarche_simplifiee_api_with_right_link(self, requests_get):
        # Given
        response_return_value = MagicMock(status_code=200, text="")
        response_return_value.json = MagicMock(return_value={"test": "value"})
        requests_get.return_value = response_return_value
        procedure_id = 1
        application_id = 2
        token = "12345"

        # When
        application_details = get_application_details(application_id,
                                                      procedure_id, token)

        # Then
        call_args = requests_get.call_args
        assert call_args[0] == (
            "https://www.demarches-simplifiees.fr/api/v1/procedures/1/dossiers/2?token=12345",
        )
        assert application_details == {"test": "value"}