예제 #1
0
def amendements_an_batch(amendements_an):
    from zam_repondeur.models import Batch, DBSession

    with transaction.manager:
        batch = Batch.create()
        amendements_an[0].location.batch = batch
        amendements_an[1].location.batch = batch
        DBSession.add_all(amendements_an)

    return amendements_an
예제 #2
0
def test_amendement_batches(amendements_an):
    from zam_repondeur.models import Amendement, Batch, DBSession

    a, b = DBSession.query(Amendement).all()

    assert a.location.batch is None
    assert b.location.batch is None

    batch = Batch.create()
    a.location.batch = batch
    b.location.batch = batch

    a, b = DBSession.query(Amendement).all()
    assert a.location.batch == b.location.batch == batch
예제 #3
0
def test_column_filtering_by_value_with_batches(
    wsgi_server,
    driver,
    lecture_an,
    lecture_an_url,
    article7bis_an,
    amendements_an,
    user_david_table_an,
    user_david,
    column_index,
    selector,
    input_text,
    kind,
    initial,
    filtered,
):
    from zam_repondeur.models import Amendement, Batch, DBSession

    with transaction.manager:
        DBSession.add(user_david_table_an)
        DBSession.add_all(amendements_an)

        batch = Batch.create()
        amendements_an[0].location.batch = batch
        amendements_an[1].location.batch = batch

        user_david_table_an.add_amendement(amendements_an[0])
        user_david_table_an.add_amendement(amendements_an[1])
        amendement = Amendement.create(lecture=lecture_an,
                                       article=article7bis_an,
                                       num=777)
        user_david_table_an.add_amendement(amendement)

    driver.get(f"{lecture_an_url}/tables/{user_david.email}")
    trs = driver.find_elements_by_css_selector(f"tbody tr:not(.hidden-{kind})")
    assert extract_item_text(selector, trs) == initial
    driver.find_element_by_link_text("Filtrer").click()
    input_field = driver.find_element_by_css_selector(
        f"thead tr.filters th:nth-child({column_index}) input")
    input_field.send_keys(input_text)
    trs = driver.find_elements_by_css_selector(f"tbody tr:not(.hidden-{kind})")
    assert extract_item_text(selector, trs) == filtered
    assert (driver.current_url ==
            f"{lecture_an_url}/tables/{user_david.email}?{kind}={input_text}")
    # Restore initial state.
    input_field.send_keys(Keys.BACKSPACE * len(input_text))
    trs = driver.find_elements_by_css_selector(f"tbody tr:not(.hidden-{kind})")
    assert extract_item_text(selector, trs) == initial
예제 #4
0
def another_amendements_an_batch(lecture_an, article1_an):
    from zam_repondeur.models import Amendement, Batch, DBSession

    with transaction.manager:
        batch = Batch.create()
        amendements = [
            Amendement.create(
                lecture=lecture_an,
                article=article1_an,
                num=num,
                position=position,
                batch=batch,
            ) for position, num in enumerate((555, 888), 3)
        ]
        DBSession.add_all(amendements)

    return amendements
예제 #5
0
    def post(self) -> Response:
        # Special case: unbatch (TODO: move to a separate route)
        if len(self.get_nums(self.request.POST)) == 1:
            amendement = self.get_amendements_from(self.request.POST)[0]
            BatchUnset.create(amendement=amendement, request=self.request)
            return HTTPFound(location=self.my_table_url)

        amendements = list(
            Batch.expanded_batches(self.get_amendements_from(
                self.request.POST)))

        self.check_amendements_are_all_on_my_table(amendements)
        self.check_amendements_have_all_same_reponse_or_empty(amendements)
        self.check_amendements_are_all_from_same_article(amendements)

        batch = Batch.create()
        shared_reponse: Optional[ReponseTuple] = None
        to_be_updated: List[Amendement] = []
        for amendement in amendements:
            if amendement.location.batch:
                BatchUnset.create(amendement=amendement, request=self.request)
            BatchSet.create(
                amendement=amendement,
                batch=batch,
                amendements_nums=[
                    amendement.num for amendement in amendements
                ],
                request=self.request,
            )
            reponse = amendement.user_content.as_tuple()
            if not reponse.is_empty:
                shared_reponse = reponse
            else:
                to_be_updated.append(amendement)

        if shared_reponse is not None and to_be_updated:
            for amendement in to_be_updated:
                if (amendement.user_content.avis or "") != shared_reponse.avis:
                    AvisAmendementModifie.create(
                        amendement=amendement,
                        avis=shared_reponse.avis,
                        request=self.request,
                    )
                if (amendement.user_content.objet
                        or "") != shared_reponse.objet:
                    ObjetAmendementModifie.create(
                        amendement=amendement,
                        objet=shared_reponse.objet,
                        request=self.request,
                    )
                if (amendement.user_content.reponse
                        or "") != shared_reponse.content:
                    ReponseAmendementModifiee.create(
                        amendement=amendement,
                        reponse=shared_reponse.content,
                        request=self.request,
                    )
                if (amendement.user_content.comments
                        or "") != shared_reponse.comments:
                    CommentsAmendementModifie.create(
                        amendement=amendement,
                        comments=shared_reponse.comments,
                        request=self.request,
                    )

        return HTTPFound(location=self.my_table_url)
예제 #6
0
def test_column_filtering_by_value_with_batches(
    wsgi_server,
    driver,
    lecture_an,
    lecture_an_url,
    article1_an,
    amendements_an,
    user_david_table_an,
    user_ronan_table_an,
    user_daniel_table_an,
    column_index,
    input_text,
    kind,
    initial,
    filtered,
):
    from zam_repondeur.models import Amendement, Batch, DBSession

    with transaction.manager:
        DBSession.add(user_ronan_table_an)
        DBSession.add(user_david_table_an)
        DBSession.add(user_daniel_table_an)

        batch = Batch.create()
        amendements_an[0].location.batch = batch
        amendements_an[1].location.batch = batch

        user_ronan_table_an.add_amendement(amendements_an[0])
        user_david_table_an.add_amendement(amendements_an[1])
        amendement = Amendement.create(lecture=lecture_an,
                                       article=article1_an,
                                       num=777,
                                       position=3)
        user_daniel_table_an.add_amendement(amendement)

    driver.get(f"{lecture_an_url}/amendements/")
    trs = driver.find_elements_by_css_selector(f"tbody tr:not(.hidden-{kind})")
    assert extract_column_text(column_index, trs) == initial
    input_field = driver.find_element_by_css_selector(
        f"thead tr.filters th:nth-child({column_index}) input")
    input_field.send_keys(input_text)
    trs = driver.find_elements_by_css_selector(f"tbody tr:not(.hidden-{kind})")
    assert extract_column_text(column_index, trs) == filtered
    assert driver.current_url == f"{lecture_an_url}/amendements/?{kind}={input_text}"

    # Restore initial state.
    input_field.send_keys(Keys.BACKSPACE * len(input_text))
    trs = driver.find_elements_by_css_selector(f"tbody tr:not(.hidden-{kind})")
    assert extract_column_text(column_index, trs) == initial
    assert driver.current_url == f"{lecture_an_url}/amendements/"

    # Check filters are active on URL (re)load.
    driver.get(f"{lecture_an_url}/amendements/?{kind}={input_text}")
    trs = driver.find_elements_by_css_selector(f"tbody tr:not(.hidden-{kind})")
    assert extract_column_text(column_index, trs) == filtered
    input_field = driver.find_element_by_css_selector(
        f"thead tr.filters th:nth-child({column_index}) input")
    input_field.send_keys(Keys.BACKSPACE * len(input_text))
    trs = driver.find_elements_by_css_selector(f"tbody tr:not(.hidden-{kind})")
    assert extract_column_text(column_index, trs) == initial
    assert driver.current_url == f"{lecture_an_url}/amendements/"