Example #1
0
def test_subclassing(fk, bridge):
    ac = fk.f_activite()
    x = Page.new(activite=ac.id, parent=bridge)
    y = Page.get(x.id, parent=bridge)
    assert x == y
    assert x.delete()
    with disable_log():
        assert Page.get(y.id) is None
Example #2
0
def test_add_remove_column(fk, bridge, qtbot, fn, lignes, colonnes, args):
    x = fk.f_tableauSection(2, 2)
    p = Page.get(x.page.id, parent=bridge)
    t = p.get_section(0)
    with qtbot.waitSignal(t.colonnesChanged):
        getattr(t, fn)(*args)
    with db_session:
        x = fk.db.TableauSection[x.id]
        assert t.lignes == x.lignes == lignes
        assert t.colonnes == x.colonnes == colonnes
        base_res = x.get_cells()

    with qtbot.waitSignal(t.colonnesChanged):
        t.undoStack.undo()
    with db_session:
        x = fk.db.TableauSection[x.id]
        assert t.lignes == x.lignes == 2
        assert t.colonnes == x.colonnes == 2
        assert x.cells.count() == 4
        assert len(x.get_cells()) == 4

    with qtbot.waitSignal(t.colonnesChanged):
        t.undoStack.redo()
        with db_session:
            x = fk.db.TableauSection[x.id]
            assert t.lignes == x.lignes == lignes
            assert t.colonnes == x.colonnes == colonnes
            res_apres_redo = x.get_cells()

    exclude = [("style", "styleId")] if "remove" not in fn else []
    compare_dict_list(base_res, res_apres_redo, exclude=exclude)
Example #3
0
def test_removeRows(fk, bridge, qtbot, idx, res, lastpos, position_after, caplogger):
    pg = fk.f_page(lastPosition=0)
    ids = [
        "00000000-0000-0000-0000-000000000000",
        "11111111-1111-1111-1111-111111111111",
        "22222222-2222-2222-2222-222222222222",
    ]
    [fk.f_section(id=x, page=pg.id) for x in ids]
    p = Page.get(str(pg.id), parent=bridge)
    a = p.model
    # with qtbot.waitSignal(a.rowsRemoved):
    p.removeSection(idx)

    # instance dans le bon ordre
    assert [b.id for b in a._sections] == res

    # la position des Section instance est mise aussi à jour.
    assert [b.position for b in a._sections] == position_after

    with db_session:
        new_secs_dict = [
            s.to_dict()
            for s in fk.db.Page[pg.id].sections.order_by(lambda x: x.position)
        ]
    new_secs_ids = [s["id"] for s in new_secs_dict]
    assert [b.id for b in a._sections] == new_secs_ids
    assert position_after == [s["position"] for s in new_secs_dict]
    assert a.page.lastPosition == lastpos
Example #4
0
def test_addSection(fk, bridge, args, kwargs, res, lastpos, qtbot):
    pg = fk.f_page()
    ids = [
        "00000000-0000-0000-0000-000000000000",
        "11111111-1111-1111-1111-111111111111",
        "22222222-2222-2222-2222-222222222222",
    ]
    new_id = "33333333-3333-3333-3333-333333333333"
    [fk.f_section(id=x, page=pg.id) for x in ids]
    p = Page.get(str(pg.id), parent=bridge)
    a = p.model
    kwargs.update({"id": new_id})
    with qtbot.waitSignal(a.rowsInserted):
        p.addSection(*args, kwargs)

    # les ids correspondent
    assert [b.id for b in a._sections] == res
    # la position des Section instance est mise aussi à jour.
    assert [b.position for b in a._sections] == [0, 1, 2, 3]
    with db_session:
        new_secs_dict = [
            s.to_dict()
            for s in fk.db.Page[pg.id].sections.order_by(lambda x: x.position)
        ]
    new_secs_ids = [s["id"] for s in new_secs_dict]
    assert [b.id for b in a._sections] == new_secs_ids
    assert a.page.lastPosition == lastpos
Example #5
0
def test_rowCount(fk, bridge):
    pg = fk.f_page()
    fk.b_section(3, page=pg.id)
    p = Page.get(str(pg.id), parent=bridge)
    a = p.model
    assert a.rowCount(QModelIndex()) == 3
    assert a.count == 3
Example #6
0
def test_update_cell(qtbot, fk, bridge):
    tab = fk.f_tableauSection(4, 4)
    page = Page.get(tab.page.id, parent=bridge)
    t: TableauSection = page.get_section(0)

    # set by app no emit first
    with qtbot.assertNotEmitted(t.cellUpdated):
        t.updateCell(3, 2, {"texte": "bla"}, 5, 12)
    with db_session:
        assert fk.db.TableauCell[tab.id, 3, 2].texte == "bla"

    with qtbot.waitSignal(t.cellUpdated) as blocker:
        t.undoStack.undo()
    assert blocker.args == [{"_cursor": 5, "_index": 14, "texte": ""}]

    with qtbot.waitSignal(t.cellUpdated) as blocker:
        t.undoStack.redo()
    assert blocker.args == [{"_cursor": 12, "_index": 14, "texte": "bla"}]

    with qtbot.waitSignal(t.cellUpdated) as blocker:
        t.undoStack.undo()
    assert blocker.args == [{
        "_cursor": 5,
        "_index": 14,
        "texte": ""
    }]  # test not crash
Example #7
0
def test_exportTo(fk, bridge, func, format, ext):
    pg = fk.f_page()
    p = Page.get(str(pg.id), parent=bridge)
    with patch("mycartable.classeur.convert.partial") as w:
        getattr(p, func)()

        assert w.called
        assert w.call_args.args[1:] == (format, ext)
Example #8
0
def test_base_init(fk, bridge):
    pg = fk.f_page(td=True)
    sections = pg.pop("sections")
    p = Page.get(pg["id"], parent=bridge)
    assert p.model._data == pg
    assert p.model.rowCount(QModelIndex()) == 0
    assert p.matiereId == p.matiere.id == pg["matiere"]
    assert [b.id for b in p.model._sections] == sections
    def wrapped(nb):

        x = fk.f_friseSection()
        _zones = fk.b_zoneFrise(nb, frise=x.id, td=True)
        p = Page.get(x.page.id, parent=bridge)
        f = p.get_section(0)
        f._zones = _zones
        return f
 def test_update_titre(self, fk, bridge):
     l = ListOfPageModel()
     p = fk.f_page()
     l._data = [{"titre": "aaa", "id": str(p.id), "matiereBgColor": "#111111"}]
     p_obj = Page.get(p.id, parent=bridge)
     p_obj.titre = "bbb"
     assert l.update_titre(p_obj)
     assert l._data == [
         {"titre": "bbb", "id": str(p.id), "matiereBgColor": "#111111"}
     ]
def test_undo_redo_apres_efface_section(fk, bridge):
    p = fk.f_page()
    qp = Page.get(p.id, parent=bridge)
    qp.addSection(classtype="FriseSection", params={"height": 300})
    assert qp.undoStack.canUndo()
    qp.get_section(0).model.add()
    qp.undoStack.undo()
    qp.undoStack.undo()
    qp.undoStack.redo()
    qp.undoStack.redo()
Example #12
0
    def test_RemoveSectionCommand(
        self, fk, setup_page, qtbot, section, kwargs, after_redo, new_res
    ):

        # tweak for image
        img = None
        if "path" in kwargs:
            img = new_res(kwargs["path"])
            kwargs["path"] = str(img)
        p, secs, c, po = setup_page()
        im = Section.new_sub(page=p["id"], **kwargs, classtype=section, parent=po)
        po = Page.get(p["id"], parent=c)
        stack = po.undoStack
        entity = getattr(fk.db, section)

        backup1 = po.get_section(3).backup()
        # redo at init
        po.removeSection(3)
        assert (
            stack.command(stack.count() - 1).text()
            == RemoveSectionCommand.formulations[section]
        )
        assert po.model.count == 3
        with db_session:
            assert entity.select().count() == 0

        # undo
        stack.undo()
        assert po.model.count == 4
        with db_session:
            assert entity.select().count() == 1
            assert compare_dict_list(
                [x.to_dict() for x in fk.db.Section.select()],
                secs,
                exclude=["modified"],
            )
            item = entity.select().first()
            if "path" in after_redo:
                assert (import_FILES() / item.path).read_bytes() == img.read_bytes()
            else:
                for k, v in after_redo.items():
                    assert getattr(item, k) == v

        backup1.pop("modified")
        backup2 = po.get_section(3).backup()
        backup2.pop("modified")
        assert backup1 == backup2

        # redo
        stack.redo()
        assert po.model.count == 3
        with db_session:
            assert entity.select().count() == 0
Example #13
0
 def test_undo(self, fk, qtbot, bridge):
     f = fk.f_equationSection(content="bla", curseur=99)
     p = Page.get(f.page.id, parent=bridge)
     sec = p.get_section(0)
     c = UpdateEquationSectionCommand(section=sec,
                                      content="aaa",
                                      curseur=33)
     c.redo()
     assert sec.content == "aaa"
     assert sec.curseur == 33
     assert c.text() == "frappe"
     c.undo()
     assert sec.content == "bla"
     assert sec.curseur == 99
Example #14
0
def test_data_role(fk, bridge, nom, sectionclass):
    sec = getattr(fk, "f_" + nom)(td=True)
    p = Page.get(sec["page"], parent=bridge)
    a = p.model
    res = a.data(a.index(0, 0), SectionRole)
    assert isinstance(res, sectionclass)
    res2 = a.data(a.index(0, 0), SectionRole)
    assert res is res2
    assert res.id == sec["id"]
    assert res.classtype == sec["classtype"]
    # invalid index
    assert a.data(a.index(99, 99), SectionRole) is None
    # no good role
    assert a.data(a.index(0, 0), 99999) is None
def test_base(fk, bridge, qtbot):
    x = fk.f_friseSection(height=3, titre="aaa")
    p = Page.get(x.page.id, parent=bridge)
    a = p.get_section(0)
    assert a.id == str(x.id)
    assert a.height == 3
    assert a.titre == "aaa"
    with qtbot.waitSignals([a.heightChanged, a.titreChanged]):
        a.height = 5
        a.titre = "bbb"
    with db_session:
        it = fk.db.FriseSection[x.id]
        assert it.titre == "bbb"
        assert it.height == 5

    assert isinstance(a.model, FriseModel)
Example #16
0
 def test_undo(self, fk, qtbot, bridge):
     f = fk.f_textSection(text="bla")
     page = Page.get(f.page.id, parent=bridge)
     sec = page.get_section(0)
     c = UpdateTextSectionCommand(
         section=sec, b_text="avant", b_cursor=0, new_text="apres", cursorPosition=1
     )
     with qtbot.waitSignal(sec.forceUpdate):
         c.redo()
     assert sec.text == "apres"
     assert sec.cursor == 1
     assert c.text() == "frappe"
     with qtbot.waitSignal(sec.forceUpdate):
         c.undo()
     assert sec.text == "avant"
     assert sec.cursor == 0
Example #17
0
 def test_update(self, fk, qtbot, bridge):
     p = fk.f_page()
     eq = fk.f_equationSection(content=" \n1\n ", page=p.id)
     page = Page.get(p.id, parent=bridge)
     e = page.get_section(0)
     event = json.dumps({
         "key": int(Qt.Key_2),
         "text": "2",
         "modifiers": None
     })
     with qtbot.waitSignals([e.contentChanged, e.curseurChanged]):
         e.update(3, event)
     assert e.content == "  \n12\n  "
     assert e.curseur == 5
     with db_session:
         item = fk.db.EquationSection[e.id]
         assert item.content == e.content
         assert item.curseur == e.curseur
Example #18
0
 def factory(nb):
     page = fk.f_page()
     p = fk.f_imageSection(page=page.id)
     annots = []
     if isinstance(nb, int):
         for i in range(nb):
             x = fk.f_annotationText(section=p.id, td=True)
             annots.append(x)
     else:
         for i in nb:
             if i == "t":
                 x = fk.f_annotationText(section=p.id, td=True)
                 annots.append(x)
             elif i == "d":
                 x = fk.f_annotationDessin(section=p.id, td=True)
                 annots.append(x)
     pageobj = Page.get(page.id, parent=bridge)
     a = pageobj.get_section(0)
     a.f_annots = annots
     return a
Example #19
0
def test_move(fk, bridge, source, target, lastposition):
    pg = fk.f_page(lastPosition=9)
    secs_ids_pre = [str(x.id) for x in fk.b_section(3, page=pg.id)]
    p = Page.get(str(pg.id), parent=bridge)
    a = p.model
    new_order = shift_list(secs_ids_pre, source, 1, target)
    res = a.move(source, target)
    with db_session:
        new_secs_dict = [
            s.to_dict()
            for s in fk.db.Page[pg.id].sections.order_by(lambda x: x.position)
        ]
        new_secs_ids = [s["id"] for s in new_secs_dict]
        assert [b.id for b in a._sections] == new_secs_ids
    if res:
        assert new_secs_ids != secs_ids_pre
        assert new_secs_ids == new_order
    else:
        assert new_secs_ids == secs_ids_pre
    assert [s["position"] for s in new_secs_dict] == [0, 1, 2]
    assert [s.position for s in a._sections] == [0, 1, 2]
    assert a.page.lastPosition == lastposition
Example #20
0
 def wrapped(genre, **kwargs):
     page = fk.f_page()
     f_genre = f"f_{genre[0].lower()+genre[1:]}"
     x = getattr(fk, f_genre)(page=page.id, **kwargs)
     p = Page.get(page.id, parent=bridge)
     return p.get_section(0)
Example #21
0
def test_properties(fk, bridge):
    it = fk.f_section(td=True)
    p = Page.get(it["page"], parent=bridge)
    sec = Section.get(it["id"], parent=p)
    assert sec.page == p
Example #22
0
 def wrap():
     p = fk.f_page(td=True)
     secs = fk.b_section(3, page=p["id"], td=True)
     c = Classeur()
     po = Page.get(p["id"], parent=c)
     return p, secs, c, po
Example #23
0
def new_page(fk):
    c = Classeur()
    p = fk.f_page()
    po = Page.get(p.id, parent=c)
    model = po.model
    return p, po, model, c
Example #24
0
def test_roleNames(fk, bridge):
    pg = fk.f_page()
    p = Page.get(str(pg.id), parent=bridge)
    a = p.model
    assert SectionRole in a.roleNames()