def test_derouleur_urls_and_mission_refs_plf2020_2e_partie( dossier_plf_2020, texte_plf_2020): from zam_repondeur.models import Lecture, Phase from zam_repondeur.services.fetch.missions import MissionRef from zam_repondeur.services.fetch.senat.derouleur import ( derouleur_urls_and_mission_refs, ) lecture = Lecture.create( phase=Phase.PREMIERE_LECTURE, texte=texte_plf_2020, partie=2, titre="Première lecture – Séance publique (2e partie)", organe="PO78718", dossier=dossier_plf_2020, ) urls = list(derouleur_urls_and_mission_refs(lecture)) assert len(urls) == 50 assert urls[0] == ( "https://www.senat.fr/enseance/2019-2020/139/liste_discussion_103930.json", MissionRef(titre="", titre_court=""), ) assert urls[1] == ( "https://www.senat.fr/enseance/2019-2020/139/liste_discussion_103931.json", MissionRef( titre="Budget annexe - Contrôle et exploitation aériens", titre_court="Contrôle et exploitation aériens", ), ) assert urls[-1] == ( "https://www.senat.fr/enseance/2019-2020/139/liste_discussion_103979.json", MissionRef(titre="Mission Travail et emploi", titre_court="Trav. emploi"), )
def test_derouleur_urls_and_mission_refs_plf2019_2e_partie( dossier_plf_2019, texte_plf_2019): from zam_repondeur.models import Lecture, Phase from zam_repondeur.services.fetch.missions import MissionRef from zam_repondeur.services.fetch.senat.derouleur import ( derouleur_urls_and_mission_refs, ) lecture = Lecture.create( phase=Phase.PREMIERE_LECTURE, texte=texte_plf_2019, partie=2, titre="Première lecture – Séance publique (2e partie)", organe="PO78718", dossier=dossier_plf_2019, ) urls = list(derouleur_urls_and_mission_refs(lecture)) assert len(urls) == 52 assert urls[0] == ( "https://www.senat.fr/enseance/2018-2019/146/liste_discussion_103414.json", MissionRef( titre="Mission Action et transformation publiques", titre_court="Action transfo.", ), ) assert urls[1] == ( "https://www.senat.fr/enseance/2018-2019/146/liste_discussion_103415.json", MissionRef(titre="Mission Action extérieure de l'État", titre_court="Action ext."), ) assert urls[-1] == ( "https://www.senat.fr/enseance/2018-2019/146/liste_discussion_103394.json", MissionRef(titre="", titre_court=""), )
def test_parse_sous_amendement(self): from zam_repondeur.services.fetch.missions import MissionRef from zam_repondeur.services.fetch.senat.derouleur import ( parse_discussion_details, ) amend1 = { "idAmendement": "1104289", "posder": "1", "subpos": "0", "isSousAmendement": "false", "idAmendementPere": "0", "urlAmdt": "Amdt_230.html", "typeAmdt": "Amt", "num": "230 rect.", "libelleAlinea": "Al. 2", "urlAuteur": "pellevat_cyril14237s.html", "auteur": "M. PELLEVAT", "isDiscussionCommune": "false", "isDiscussionCommuneIsolee": "false", "isIdentique": "false", "sort": "Rejeté", "isAdopte": "false", "isRejete": "true", } amend2 = { "idAmendement": "1110174", "posder": "1", "subpos": "0", "isSousAmendement": "true", "idAmendementPere": "1104289", "urlAmdt": "Amdt_131.html", "typeAmdt": "Amt", "num": "131 rect.", "libelleAlinea": "", "urlAuteur": "bocquet_eric11040e.html", "auteur": "M. BOCQUET", "isDiscussionCommune": "true", "idDiscussionCommune": "110541", "isDiscussionCommuneIsolee": "false", "isIdentique": "false", "sort": "Rejeté", "isAdopte": "false", "isRejete": "true", } details1 = parse_discussion_details({}, amend1, position=1, mission_ref=MissionRef( titre="", titre_court="")) details2 = parse_discussion_details( {"1104289": details1.num}, amend2, position=2, mission_ref=MissionRef(titre="", titre_court=""), ) assert details2.num == 131 assert details2.parent_num == 230
def test_not_discussion_commune(self): from zam_repondeur.services.fetch.missions import MissionRef from zam_repondeur.services.fetch.senat.derouleur import ( parse_discussion_details, ) amend = { "idAmendement": "1103376", "posder": "1", "subpos": "0", "isSousAmendement": "false", "idAmendementPere": "0", "urlAmdt": "Amdt_31.html", "typeAmdt": "Amt", "num": "31", "libelleAlinea": "Al. 8", "urlAuteur": "vanlerenberghe_jean_marie01034p.html", "auteur": "M. VANLERENBERGHE", "isDiscussionCommune": "false", "isDiscussionCommuneIsolee": "false", "isIdentique": "false", "sort": "Adopté", "isAdopte": "true", "isRejete": "false", } details = parse_discussion_details({}, amend, position=1, mission_ref=MissionRef( titre="", titre_court="")) assert details.id_discussion_commune is None
def test_discussion_commune(self): from zam_repondeur.services.fetch.missions import MissionRef from zam_repondeur.services.fetch.senat.derouleur import ( parse_discussion_details, ) amend = { "idAmendement": "1110174", "posder": "1", "subpos": "0", "isSousAmendement": "false", "idAmendementPere": "0", "urlAmdt": "Amdt_131.html", "typeAmdt": "Amt", "num": "131", "libelleAlinea": "", "urlAuteur": "bocquet_eric11040e.html", "auteur": "M. BOCQUET", "isDiscussionCommune": "true", "idDiscussionCommune": "110541", "isDiscussionCommuneIsolee": "false", "isIdentique": "false", "sort": "Rejeté", "isAdopte": "false", "isRejete": "true", } details = parse_discussion_details({}, amend, position=1, mission_ref=MissionRef( titre="", titre_court="")) assert details.id_discussion_commune == 110541
def test_parse_basic_data(self): from zam_repondeur.services.fetch.missions import MissionRef from zam_repondeur.services.fetch.senat.derouleur import ( parse_discussion_details, ) amend = { "idAmendement": "1104289", "posder": "1", "subpos": "0", "isSousAmendement": "false", "idAmendementPere": "0", "urlAmdt": "Amdt_230.html", "typeAmdt": "Amt", "num": "230 rect.", "libelleAlinea": "Al. 2", "urlAuteur": "pellevat_cyril14237s.html", "auteur": "M. PELLEVAT", "isDiscussionCommune": "false", "isDiscussionCommuneIsolee": "false", "isIdentique": "false", "sort": "Rejeté", "isAdopte": "false", "isRejete": "true", } details = parse_discussion_details({}, amend, position=1, mission_ref=MissionRef( titre="", titre_court="")) assert details.num == 230 assert details.position == 1 assert details.id_discussion_commune is None assert details.id_identique is None assert details.parent_num is None
def test_derouleur_urls_and_mission_refs(lecture_senat): from zam_repondeur.models import DBSession from zam_repondeur.services.fetch.missions import MissionRef from zam_repondeur.services.fetch.senat.derouleur import ( derouleur_urls_and_mission_refs, ) assert list(derouleur_urls_and_mission_refs(lecture_senat)) == [( "https://www.senat.fr/enseance/2017-2018/63/liste_discussion.json", MissionRef(titre="", titre_court=""), )] with transaction.manager: lecture_senat.organe = "PO744107" DBSession.add(lecture_senat) assert list(derouleur_urls_and_mission_refs(lecture_senat)) == [( "https://www.senat.fr/encommission/2017-2018/63/liste_discussion.json", MissionRef(titre="", titre_court=""), )]
def test_derouleur_urls_and_mission_refs_plf2020_1re_partie( dossier_plf_2020, texte_plf_2020): from zam_repondeur.models import Lecture, Phase from zam_repondeur.services.fetch.missions import MissionRef from zam_repondeur.services.fetch.senat.derouleur import ( derouleur_urls_and_mission_refs, ) lecture = Lecture.create( phase=Phase.PREMIERE_LECTURE, texte=texte_plf_2020, partie=1, titre="Première lecture – Séance publique (1re partie)", organe="PO78718", dossier=dossier_plf_2020, ) assert list(derouleur_urls_and_mission_refs(lecture)) == [( "https://www.senat.fr/enseance/2019-2020/139/liste_discussion_103929.json", MissionRef(titre="", titre_court=""), )]
def test_fetch_amendements_senat( app, source_senat, lecture_senat, article1_senat, amendements_senat ): from zam_repondeur.models import Amendement, DBSession from zam_repondeur.services.fetch.missions import MissionRef # Add a response to one of the amendements with transaction.manager: amendement = amendements_senat[1] amendement.user_content.avis = "Favorable" amendement.user_content.objet = "Objet" amendement.user_content.reponse = "Réponse" # The object is no longer bound to a session here, as it was created in a # previous transaction, so we add it to the current session to make sure that # our changes will be committed with the current transaction DBSession.add(amendement) # Update amendements with patch( "zam_repondeur.services.fetch.senat.amendements._fetch_all" ) as mock_fetch_all, patch( "zam_repondeur.services.fetch.senat.derouleur._fetch_discussion_details" ) as mock_fetch_discussion_details: mock_fetch_all.return_value = ( { "Numéro ": "6666", "Subdivision ": "Article 1", "Alinéa": "1", "Auteur ": "LE GOUVERNEMENT", "Date de dépôt ": "2017-11-13", "Fiche Sénateur": "", "Sort ": "Adopté", "Dispositif ": "", "Objet ": "", }, { "Numéro ": "7777", "Subdivision ": "Article 1", "Alinéa": "1", "Auteur ": "LE GOUVERNEMENT", "Date de dépôt ": "2017-11-13", "Fiche Sénateur": "", "Sort ": "Adopté", "Dispositif ": "", "Objet ": "", }, { "Numéro ": "9999", "Subdivision ": "Article 1", "Alinéa": "1", "Auteur ": "LE GOUVERNEMENT", "Date de dépôt ": "2017-11-13", "Fiche Sénateur": "", "Sort ": "Adopté", "Dispositif ": "", "Objet ": "", }, ) mock_fetch_discussion_details.return_value = [ ( { "info_generales": { "natureLoi": "Projet de loi", "intituleLoi": "Financement de la sécurité sociale pour 2018", "lecture": "1ère lecture", "tsgenhtml": "1531427548000", "idtxt": "103021", "nbAmdtsDeposes": "595", "nbAmdtsAExaminer": "0", "doslegsignet": "plfss2018", }, "Subdivisions": [ { "libelle_subdivision": "Article 1", "id_subdivision": "151610", "signet": "../../textes/2017-2018/63.html#AMELI_SUB_4__Article_3", # noqa "Amendements": [ { "idAmendement": "1103376", "posder": "1", "subpos": "0", "isSousAmendement": "false", "idAmendementPere": "0", "urlAmdt": "Amdt_31.html", "typeAmdt": "Amt", "num": "6666", "libelleAlinea": "Al. 8", "urlAuteur": "vanlerenberghe_jean_marie01034p.html", "auteur": "M. VANLERENBERGHE", "isDiscussionCommune": "false", "isDiscussionCommuneIsolee": "false", "isIdentique": "false", "sort": "Adopté", "isAdopte": "true", "isRejete": "false", }, { "idAmendement": "1103376", "posder": "1", "subpos": "0", "isSousAmendement": "false", "idAmendementPere": "0", "urlAmdt": "Amdt_31.html", "typeAmdt": "Amt", "num": "7777", "libelleAlinea": "Al. 8", "urlAuteur": "vanlerenberghe_jean_marie01034p.html", "auteur": "M. VANLERENBERGHE", "isDiscussionCommune": "false", "isDiscussionCommuneIsolee": "false", "isIdentique": "false", "sort": "Adopté", "isAdopte": "true", "isRejete": "false", }, { "idAmendement": "1103376", "posder": "1", "subpos": "0", "isSousAmendement": "false", "idAmendementPere": "0", "urlAmdt": "Amdt_31.html", "typeAmdt": "Amt", "num": "9999", "libelleAlinea": "Al. 8", "urlAuteur": "vanlerenberghe_jean_marie01034p.html", "auteur": "M. VANLERENBERGHE", "isDiscussionCommune": "false", "isDiscussionCommuneIsolee": "false", "isIdentique": "false", "sort": "Adopté", "isAdopte": "true", "isRejete": "false", }, ], } ], }, MissionRef(titre="", titre_court=""), ) ] DBSession.add(lecture_senat) result = source_senat.fetch(lecture_senat) assert result.fetched == {6666, 7777, 9999} assert result.created == {7777} assert result.errored == set() # Check that the response was preserved on the updated amendement amendement = DBSession.query(Amendement).filter(Amendement.num == 9999).one() assert amendement.user_content.avis == "Favorable" assert amendement.user_content.objet == "Objet" assert amendement.user_content.reponse == "Réponse" # Check that the position was changed on the updated amendement assert amendement.position == 3 # Check that the position is set for the new amendement amendement = DBSession.query(Amendement).filter(Amendement.num == 7777).one() assert amendement.position == 2