newField checks its input is a str

Indeed, it takes as input a name (str). For some reason in some test
it was given a model. This actually led to some strange failed test.
This commit is contained in:
Arthur Milchior 2019-11-25 00:15:20 +01:00
parent 48c1e668d4
commit 556ef5d34b
2 changed files with 3 additions and 4 deletions

View File

@ -231,6 +231,7 @@ and notes.mid = ? and cards.ord = ?""", m['id'], ord)
##################################################
def newField(self, name):
assert(isinstance(name, str))
f = defaultField.copy()
f['name'] = name
return f

View File

@ -39,8 +39,7 @@ def test_fields():
assert "{{NewFront}}" in m['tmpls'][0]['qfmt']
h = d.models.scmhash(m)
# add a field
f = d.models.newField(m)
f['name'] = "foo"
f = d.models.newField("foo")
d.models.addField(m, f)
assert d.getNote(d.models.nids(m)[0]).fields == ["1", "2", ""]
assert d.models.scmhash(m) != h
@ -57,8 +56,7 @@ def test_fields():
d.models.moveField(m, m['flds'][1], 0)
assert d.getNote(d.models.nids(m)[0]).fields == ["1", ""]
# add another and put in middle
f = d.models.newField(m)
f['name'] = "baz"
f = d.models.newField("baz")
d.models.addField(m, f)
f = d.getNote(d.models.nids(m)[0])
f['baz'] = "2"