示例#1
0
文件: db.py 项目: jab/lektor
 def edit(self, path, is_attachment=None, datamodel=None):
     """Edits a record by path."""
     path = cleanup_path(path)
     return make_editor_session(self,
                                path,
                                is_attachment=is_attachment,
                                datamodel=datamodel)
示例#2
0
def test_deprecated_data_proxy_methods(pad):
    editor = make_editor_session(pad, "/")

    with pytest.deprecated_call(
            match=r"EditorSession\.__contains__ .* deprecated"):
        assert "arbitrary" not in editor

    with pytest.deprecated_call(
            match=r"EditorSession\.__setitem__ .* deprecated"):
        editor["test"] = "value"
    assert editor.data["test"] == "value"
    with pytest.deprecated_call(
            match=r"EditorSession\.__getitem__ .* deprecated"):
        assert editor["test"] == "value"

    with pytest.deprecated_call(match=r"EditorSession\.update .* deprecated"):
        editor.update({"test": "another"})
    assert editor.data["test"] == "another"

    items = set(editor.data.items())
    with pytest.deprecated_call(match=r"EditorSession\.__len__ .* deprecated"):
        assert len(editor) == len(items)
    with pytest.deprecated_call(match=r"EditorSession\.items .* deprecated"):
        assert set(editor.items()) == items
    with pytest.deprecated_call(
            match=r"EditorSession\.__iter__ .* deprecated"):
        assert set(editor) == set(key for key, val in items)
    with pytest.deprecated_call(match=r"EditorSession\.keys .* deprecated"):
        assert set(editor.keys()) == set(key for key, val in items)
    with pytest.deprecated_call(match=r"EditorSession\.values .* deprecated"):
        assert set(editor.values()) == set(val for key, val in items)

    with pytest.deprecated_call(
            match=r"EditorSession\.iteritems .*\.data\.items "):
        assert set(editor.iteritems()) == items
    with pytest.deprecated_call(
            match=r"EditorSession\.iterkeys .*\.data\.keys "):
        assert set(editor.iterkeys()) == set(key for key, val in items)
    with pytest.deprecated_call(
            match=r"EditorSession\.itervalues .*\.data\.values "):
        assert set(editor.itervalues()) == set(val for key, val in items)

    with pytest.deprecated_call(
            match=r"EditorSession\.revert_key .* deprecated"):
        editor.revert_key("test")
    assert "test" not in editor.data
示例#3
0
def test_make_editor_session_raises_bad_edit(pad, path, kwargs, expect):
    with pytest.raises(BadEdit) as excinfo:
        make_editor_session(pad, path, **kwargs)
    assert expect in str(excinfo.value)
示例#4
0
def test_make_editor_session(pad, path, kwargs, expect):
    sess = make_editor_session(pad, path, **kwargs)
    if "exists" in expect:
        assert sess.exists == expect["exists"]
    if "datamodel" in expect:
        assert sess.datamodel.id == expect["datamodel"]
示例#5
0
 def edit(self, path, is_attachment=None, alt=PRIMARY_ALT, datamodel=None):
     """Edits a record by path."""
     return make_editor_session(self.pad, cleanup_path(path), alt=alt,
                                is_attachment=is_attachment,
                                datamodel=datamodel)
示例#6
0
文件: db.py 项目: jab/lektor
 def edit(self, path, is_attachment=None, datamodel=None):
     """Edits a record by path."""
     path = cleanup_path(path)
     return make_editor_session(self, path, is_attachment=is_attachment,
                                datamodel=datamodel)