From 61b9567e3a8a5d53e0241f39aea4bf463151565c Mon Sep 17 00:00:00 2001 From: "Veronica K. B. Olsen" <1619840+vkbo@users.noreply.github.com> Date: Thu, 10 Sep 2020 22:40:45 +0200 Subject: [PATCH] Added test for document meta --- nw/core/document.py | 4 ++-- tests/test_project.py | 21 ++++++++++++++++++++- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/nw/core/document.py b/nw/core/document.py index 9aec16f6..6c859168 100644 --- a/nw/core/document.py +++ b/nw/core/document.py @@ -230,13 +230,13 @@ class NWDoc(): for aClass in nwItemClass: if theMeta.startswith(aClass.name): theClass = aClass - theMeta = theMeta.lstrip(aClass.name+":") + theMeta = theMeta[len(aClass.name)+1:] theLayout = nwItemLayout.NO_LAYOUT for aLayout in nwItemLayout: if theMeta.startswith(aLayout.name): theLayout = aLayout - theMeta = theMeta.lstrip(aLayout.name+":") + theMeta = theMeta[len(aLayout.name)+1:] return theMeta, thePath, theClass, theLayout diff --git a/tests/test_project.py b/tests/test_project.py index 4e90a8c4..2354fa08 100644 --- a/tests/test_project.py +++ b/tests/test_project.py @@ -9,8 +9,9 @@ from shutil import copyfile from nwtools import cmpFiles from nw.core.project import NWProject +from nw.core.document import NWDoc from nw.core.index import NWIndex -from nw.constants import nwItemClass +from nw.constants import nwItemClass, nwItemLayout @pytest.mark.project def testProjectNewOpenSave(nwFuncTemp, nwTempProj, nwRef, nwTemp, nwDummy): @@ -295,3 +296,21 @@ def testProjectNewSample(nwFuncTemp, nwRef, nwConf, nwDummy): assert theProject.projName == "Sample Project" assert theProject.saveProject() assert theProject.closeProject() + +@pytest.mark.project +def testDocMeta(nwDummy, nwLipsum): + theProject = NWProject(nwDummy) + theProject.projTree.setSeed(42) + assert theProject.openProject(nwLipsum) + + aDoc = NWDoc(theProject, nwDummy) + assert aDoc.openDocument("47666c91c7ccf") + theMeta, thePath, theClass, theLayout = aDoc.getMeta() + + assert theMeta == "Scene Five" + assert len(thePath) == 3 + assert thePath[0] == "47666c91c7ccf" + assert thePath[1] == "6bd935d2490cd" + assert thePath[2] == "b3643d0f92e32" + assert theClass == nwItemClass.NOVEL + assert theLayout == nwItemLayout.SCENE