Ejemplo n.º 1
0
def test_article_changed(lecture_senat):
    """
    The targeted article may change
    """

    from zam_repondeur.fetch.senat.amendements import Senat
    from zam_repondeur.models import DBSession

    responses.add(
        responses.GET,
        "https://www.senat.fr/amendements/2017-2018/63/jeu_complet_2017-2018_63.csv",
        body=read_sample_data("jeu_complet_2017-2018_63-short.csv"),
        status=200,
    )
    responses.add(
        responses.GET,
        "https://www.senat.fr/amendements/2017-2018/63/jeu_complet_2017-2018_63.csv",
        body=read_sample_data("jeu_complet_2017-2018_63-short-article.csv"),
        status=200,
    )
    responses.add(
        responses.GET,
        "https://data.senat.fr/data/senateurs/ODSEN_GENERAL.csv",
        body=read_sample_data("ODSEN_GENERAL-short.csv"),
        status=200,
    )
    responses.add(
        responses.GET,
        "https://www.senat.fr/enseance/2017-2018/63/liste_discussion.json",
        body=read_sample_data("liste_discussion_63-short.json"),
        status=200,
    )
    responses.add(
        responses.GET,
        "https://www.senat.fr/enseance/2017-2018/63/liste_discussion.json",
        body=read_sample_data("liste_discussion_63-short-article.json"),
        status=200,
    )

    DBSession.add(lecture_senat)

    source = Senat()

    source.fetch(lecture_senat)

    assert {amdt.num: str(amdt.article) for amdt in lecture_senat.amendements} == {
        31: "Art. 3",
        443: "Art. 4",
    }

    source.fetch(lecture_senat)

    assert {amdt.num: str(amdt.article) for amdt in lecture_senat.amendements} == {
        31: "Art. 3",
        443: "Art. 3",
    }
Ejemplo n.º 2
0
def test_abandoned_before_seance(lecture_senat):
    """
    An amendement that is either withdrawn by its author or declared invalid
    will be removed from the "liste_discussion"
    """

    from zam_repondeur.fetch.senat.amendements import Senat
    from zam_repondeur.models import DBSession

    responses.add(
        responses.GET,
        "https://www.senat.fr/amendements/2017-2018/63/jeu_complet_2017-2018_63.csv",
        body=read_sample_data("jeu_complet_2017-2018_63-short.csv"),
        status=200,
    )
    responses.add(
        responses.GET,
        "https://data.senat.fr/data/senateurs/ODSEN_GENERAL.csv",
        body=read_sample_data("ODSEN_GENERAL-short.csv"),
        status=200,
    )
    responses.add(
        responses.GET,
        "https://www.senat.fr/enseance/2017-2018/63/liste_discussion.json",
        body=read_sample_data("liste_discussion_63-short.json"),
        status=200,
    )
    responses.add(
        responses.GET,
        "https://www.senat.fr/enseance/2017-2018/63/liste_discussion.json",
        body=read_sample_data("liste_discussion_63-short-retire.json"),
        status=200,
    )

    DBSession.add(lecture_senat)

    source = Senat()

    source.fetch(lecture_senat)

    assert {amdt.num: amdt.position for amdt in lecture_senat.amendements} == {
        31: 1,
        443: 2,
    }

    source.fetch(lecture_senat)

    assert {amdt.num: amdt.position for amdt in lecture_senat.amendements} == {
        31: 1,
        443: None,
    }
Ejemplo n.º 3
0
def test_position_changed(lecture_senat):
    """
    The discussion order of amendements may change
    """

    from zam_repondeur.fetch.senat.amendements import Senat
    from zam_repondeur.models import DBSession

    responses.add(
        responses.GET,
        "https://www.senat.fr/amendements/2017-2018/63/jeu_complet_2017-2018_63.csv",
        body=read_sample_data("jeu_complet_2017-2018_63-short.csv"),
        status=200,
    )
    responses.add(
        responses.GET,
        "https://data.senat.fr/data/senateurs/ODSEN_GENERAL.csv",
        body=read_sample_data("ODSEN_GENERAL-short.csv"),
        status=200,
    )
    responses.add(
        responses.GET,
        "https://www.senat.fr/enseance/2017-2018/63/liste_discussion.json",
        body=read_sample_data("liste_discussion_63-short.json"),
        status=200,
    )
    responses.add(
        responses.GET,
        "https://www.senat.fr/enseance/2017-2018/63/liste_discussion.json",
        body=read_sample_data("liste_discussion_63-short-position.json"),
        status=200,
    )

    DBSession.add(lecture_senat)

    source = Senat()

    source.fetch(lecture_senat)

    assert {amdt.num: amdt.position for amdt in lecture_senat.amendements} == {
        31: 1,
        443: 2,
    }

    source.fetch(lecture_senat)

    assert {amdt.num: amdt.position for amdt in lecture_senat.amendements} == {
        31: 2,
        443: 1,
    }
Ejemplo n.º 4
0
def test_aspire_senat_plf2019_1re_partie(app, texte_senat, dossier_plf):
    from zam_repondeur.fetch.senat.amendements import Senat
    from zam_repondeur.models import DBSession, Lecture

    with transaction.manager:
        texte_senat.numero = 146
        lecture = Lecture.create(
            chambre="senat",
            session="2018-2019",
            texte=texte_senat,
            partie=1,
            titre="Numéro lecture – Titre lecture sénat",
            organe="PO78718",
            dossier=dossier_plf,
        )

    sample_data = read_sample_data("jeu_complet_2018-2019_146.csv")

    responses.add(
        responses.GET,
        "https://www.senat.fr/amendements/2018-2019/146/jeu_complet_2018-2019_146.csv",
        body=sample_data,
        status=200,
    )

    odsen_data = read_sample_data("ODSEN_GENERAL.csv")

    responses.add(
        responses.GET,
        "https://data.senat.fr/data/senateurs/ODSEN_GENERAL.csv",
        body=odsen_data,
        status=200,
    )

    json_data = json.loads(read_sample_data("liste_discussion_103393.json"))

    responses.add(
        responses.GET,
        "https://www.senat.fr/enseance/2018-2019/146/liste_discussion_103393.json",
        json=json_data,
        status=200,
    )

    DBSession.add(lecture)

    source = Senat()

    amendements, created, errored = source.fetch(lecture)

    # All amendements from part 1 are fetched
    assert len(amendements) == 1005
Ejemplo n.º 5
0
def test_aspire_senat(app, lecture_senat):
    from zam_repondeur.fetch.senat.amendements import Senat
    from zam_repondeur.models import DBSession
    from zam_repondeur.models.events.amendement import (
        AmendementRectifie,
        CorpsAmendementModifie,
        ExposeAmendementModifie,
    )

    sample_data = read_sample_data("jeu_complet_2017-2018_63.csv")

    responses.add(
        responses.GET,
        "https://www.senat.fr/amendements/2017-2018/63/jeu_complet_2017-2018_63.csv",
        body=sample_data,
        status=200,
    )

    odsen_data = read_sample_data("ODSEN_GENERAL.csv")

    responses.add(
        responses.GET,
        "https://data.senat.fr/data/senateurs/ODSEN_GENERAL.csv",
        body=odsen_data,
        status=200,
    )

    json_data = json.loads(read_sample_data("liste_discussion_63.json"))

    responses.add(
        responses.GET,
        "https://www.senat.fr/enseance/2017-2018/63/liste_discussion.json",
        json=json_data,
        status=200,
    )

    DBSession.add(lecture_senat)

    source = Senat()

    amendements, created, errored = source.fetch(lecture_senat)

    # All amendements are fetched
    assert len(amendements) == 595

    # Check details of #1
    amendement = [
        amendement for amendement in amendements if amendement.num == 1
    ][0]
    assert amendement.num == 1
    assert amendement.rectif == 1
    assert amendement.article.num == "7"
    assert amendement.article.pos == "après"
    assert amendement.parent is None

    events = sorted(amendement.events,
                    key=attrgetter("created_at"),
                    reverse=True)

    assert len(events) == 3
    assert isinstance(events[0], ExposeAmendementModifie)
    assert events[0].created_at is not None
    assert events[0].user is None
    assert events[0].data["old_value"] == ""
    assert events[0].data["new_value"].startswith("<p>Cet amendement vise")
    assert events[0].render_summary(
    ) == "L’exposé de l’amendement a été initialisé"

    assert isinstance(events[1], CorpsAmendementModifie)
    assert events[1].created_at is not None
    assert events[1].user is None
    assert events[1].data["old_value"] == ""
    assert events[1].data["new_value"].startswith("<p>Après l’article")
    assert events[1].render_summary(
    ) == "Le corps de l’amendement a été initialisé"

    assert isinstance(events[2], AmendementRectifie)
    assert events[2].created_at is not None
    assert events[2].user is None
    assert events[2].data["old_value"] == 0
    assert events[2].data["new_value"] == 1
    assert events[2].render_summary() == "L’amendement a été rectifié"

    # Check that #596 has a parent
    sous_amendement = [
        amendement for amendement in amendements if amendement.num == 596
    ][0]
    assert sous_amendement.parent.num == 229
    assert sous_amendement.parent.rectif == 1
Ejemplo n.º 6
0
def test_aspire_senat_plf2019_2e_partie(app, texte_senat, dossier_plf):
    from zam_repondeur.fetch.senat.amendements import Senat
    from zam_repondeur.models import DBSession, Lecture

    with transaction.manager:
        texte_senat.numero = 146
        lecture = Lecture.create(
            chambre="senat",
            session="2018-2019",
            texte=texte_senat,
            partie=2,
            titre="Numéro lecture – Titre lecture sénat",
            organe="PO78718",
            dossier=dossier_plf,
        )

    sample_data = read_sample_data("jeu_complet_2018-2019_146.csv")

    responses.add(
        responses.GET,
        "https://www.senat.fr/amendements/2018-2019/146/jeu_complet_2018-2019_146.csv",
        body=sample_data,
        status=200,
    )

    odsen_data = read_sample_data("ODSEN_GENERAL.csv")

    responses.add(
        responses.GET,
        "https://data.senat.fr/data/senateurs/ODSEN_GENERAL.csv",
        body=odsen_data,
        status=200,
    )

    json_data = json.loads(read_sample_data("liste_discussion_103394.json"))

    responses.add(
        responses.GET,
        "https://www.senat.fr/enseance/2018-2019/146/liste_discussion_103394.json",
        json=json_data,
        status=200,
    )

    json_data = json.loads(read_sample_data("liste_discussion_103395.json"))

    responses.add(
        responses.GET,
        "https://www.senat.fr/enseance/2018-2019/146/liste_discussion_103395.json",
        json=json_data,
        status=200,
    )

    for i in range(103396, 103445 + 1):
        responses.add(
            responses.GET,
            f"https://www.senat.fr/enseance/2018-2019/146/liste_discussion_{i}.json",
            status=404,
        )

    DBSession.add(lecture)

    source = Senat()

    amendements, created, errored = source.fetch(lecture)

    # All amendements from part 2 are fetched
    assert len(amendements) == 35

    # Positions are unique
    positions = [
        amdt.position for amdt in amendements if amdt.position is not None
    ]
    assert len(set(positions)) == len(positions) == 12
Ejemplo n.º 7
0
def test_aspire_senat_again_with_irrecevable_transfers_to_index(
        app, lecture_senat, user_david_table_an):
    from zam_repondeur.fetch.senat.amendements import Senat
    from zam_repondeur.models import DBSession
    from zam_repondeur.models.events.amendement import (
        AmendementIrrecevable,
        AmendementTransfere,
    )

    sample_data = read_sample_data("jeu_complet_2017-2018_63.csv")

    responses.add(
        responses.GET,
        "https://www.senat.fr/amendements/2017-2018/63/jeu_complet_2017-2018_63.csv",
        body=sample_data,
        status=200,
    )
    # On second call we want an irrecevable.
    responses.add(
        responses.GET,
        "https://www.senat.fr/amendements/2017-2018/63/jeu_complet_2017-2018_63.csv",
        body=sample_data.decode("latin-1").replace(
            "Adopté\t//www.senat.fr/amendements/2017-2018/63/Amdt_1.html",
            "Irrecevable\t//www.senat.fr/amendements/2017-2018/63/Amdt_1.html",
        ).encode("latin-1"),
        status=200,
    )

    odsen_data = read_sample_data("ODSEN_GENERAL.csv")

    responses.add(
        responses.GET,
        "https://data.senat.fr/data/senateurs/ODSEN_GENERAL.csv",
        body=odsen_data,
        status=200,
    )

    json_data = json.loads(read_sample_data("liste_discussion_63.json"))

    responses.add(
        responses.GET,
        "https://www.senat.fr/enseance/2017-2018/63/liste_discussion.json",
        json=json_data,
        status=200,
    )

    DBSession.add(lecture_senat)

    source = Senat()

    # Let's fetch a new amendement
    amendements, created, errored = source.fetch(lecture_senat)
    amendement = [
        amendement for amendement in amendements if amendement.num == 1
    ][0]
    assert len(amendement.events) == 3

    # Put it on a user table
    DBSession.add(user_david_table_an)
    user_david_table_an.amendements.append(amendement)
    assert user_david_table_an.amendements == [amendement]
    assert amendement.user_table == user_david_table_an

    # Now fetch the same amendement again (now irrecevable)
    amendements, created, errored = source.fetch(lecture_senat)
    amendement = [
        amendement for amendement in amendements if amendement.num == 1
    ][0]
    assert len(amendement.events) == 5  # two more

    # An irrecevable event has been created
    assert any(
        isinstance(event, AmendementIrrecevable)
        for event in amendement.events)

    # An automatic transfer event has been created
    assert any(
        isinstance(event, AmendementTransfere) for event in amendement.events)
    transfer_event = next(event for event in amendement.events
                          if isinstance(event, AmendementTransfere))
    assert transfer_event.user is None
    assert transfer_event.data["old_value"] == "David ([email protected])"
    assert transfer_event.data["new_value"] == ""
    assert transfer_event.render_summary() == (
        "L’amendement a été remis automatiquement sur l’index")

    # The amendement is now on the index
    assert amendement.user_table is None
    assert user_david_table_an.amendements == []
Ejemplo n.º 8
0
def test_aspire_senat_again_with_irrecevable(app, lecture_senat):
    from zam_repondeur.fetch.senat.amendements import Senat
    from zam_repondeur.models import DBSession
    from zam_repondeur.models.events.amendement import AmendementIrrecevable

    sample_data = read_sample_data("jeu_complet_2017-2018_63.csv")

    responses.add(
        responses.GET,
        "https://www.senat.fr/amendements/2017-2018/63/jeu_complet_2017-2018_63.csv",
        body=sample_data,
        status=200,
    )
    # On second call we want an irrecevable.
    responses.add(
        responses.GET,
        "https://www.senat.fr/amendements/2017-2018/63/jeu_complet_2017-2018_63.csv",
        body=sample_data.decode("latin-1").replace(
            "Adopté\t//www.senat.fr/amendements/2017-2018/63/Amdt_1.html",
            "Irrecevable\t//www.senat.fr/amendements/2017-2018/63/Amdt_1.html",
        ).encode("latin-1"),
        status=200,
    )

    odsen_data = read_sample_data("ODSEN_GENERAL.csv")

    responses.add(
        responses.GET,
        "https://data.senat.fr/data/senateurs/ODSEN_GENERAL.csv",
        body=odsen_data,
        status=200,
    )

    json_data = json.loads(read_sample_data("liste_discussion_63.json"))

    responses.add(
        responses.GET,
        "https://www.senat.fr/enseance/2017-2018/63/liste_discussion.json",
        json=json_data,
        status=200,
    )

    DBSession.add(lecture_senat)

    source = Senat()

    amendements, created, errored = source.fetch(lecture_senat)
    amendement = [
        amendement for amendement in amendements if amendement.num == 1
    ][0]
    assert len(amendement.events) == 3

    amendements, created, errored = source.fetch(lecture_senat)
    amendement = [
        amendement for amendement in amendements if amendement.num == 1
    ][0]
    assert len(amendement.events) == 4

    assert isinstance(amendement.events[3], AmendementIrrecevable)
    assert amendement.events[3].created_at is not None
    assert amendement.events[3].user is None
    assert amendement.events[3].data["old_value"] == "Adopté"
    assert amendement.events[3].data["new_value"] == "Irrecevable"
    assert (amendement.events[3].render_summary() ==
            "L’amendement a été déclaré irrecevable par les services du Sénat")