Skip to content

Commit 1977c3b

Browse files
authored
add_entry: Allow None for title, username, password (#430)
* tests: Add a test with `None` as title, username, password According to the docs, these parameters can also be passed None, in practice that failed. Add a test that passed in None parameters, which fails before the next commit that will allow these and passes after. * add_entry: Allow `None` for title, username, password Our docs allow None, so make it so. None gets translated to an empty string in the XML. There is a corresponding test which tests this case. Fixes: #416
1 parent a3ad4f9 commit 1977c3b

2 files changed

Lines changed: 16 additions & 3 deletions

File tree

pykeepass/entry.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,10 @@ def __init__(self, title=None, username=None, password=None, url=None,
3939
expiry_time=expiry_time,
4040
icon=icon
4141
)
42-
self._element.append(E.String(E.Key('Title'), E.Value(title)))
43-
self._element.append(E.String(E.Key('UserName'), E.Value(username)))
42+
self._element.append(E.String(E.Key('Title'), E.Value(title or "")))
43+
self._element.append(E.String(E.Key('UserName'), E.Value(username or "")))
4444
self._element.append(
45-
E.String(E.Key('Password'), E.Value(password, Protected="True"))
45+
E.String(E.Key('Password'), E.Value(password or "", Protected="True"))
4646
)
4747
if url:
4848
self._element.append(E.String(E.Key('URL'), E.Value(url)))

tests/tests.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -511,6 +511,19 @@ def test_fields(self):
511511
self.kp.root_group
512512
)
513513

514+
def test_null_values(self):
515+
"""Set title, username, password to `None` as the docs allow"""
516+
entry = Entry(
517+
None,
518+
None,
519+
None,
520+
kp=self.kp
521+
)
522+
self.assertEqual(entry.title, '')
523+
self.assertEqual(entry.username, '')
524+
self.assertEqual(entry.password, '')
525+
526+
514527
def test_references(self):
515528
original_entry = self.kp.find_entries(title='foobar_entry', first=True)
516529
original_entry_duplicate = self.kp.find_entries(title='foobar_entry', first=True)

0 commit comments

Comments
 (0)