Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_add_delete_move_group(self):
notes_text = "this is a note for a group!"
base_group = self.kp.add_group(self.kp.root_group, 'base_group', notes=notes_text)
sub_group = self.kp.add_group(base_group, 'sub_group')
sub_group2 = self.kp.add_group(base_group, 'sub_group2')
self.assertEqual(base_group.notes, notes_text)
base_group.notes = ''
self.assertEqual(base_group.notes, '')
results = self.kp.find_groups(path='base_group/sub_group/', first=True)
self.assertIsInstance(results, Group)
self.assertEqual(results.name, sub_group.name)
self.assertTrue(results.uuid != None)
self.kp.move_group(sub_group2, sub_group)
results = self.kp.find_groups(path='base_group/sub_group/sub_group2/', first=True)
self.assertEqual(results.name, sub_group2.name)
self.kp.delete_group(sub_group)
results = self.kp.find_groups(path='base_group/sub_group/', first=True)
self.assertIsNone(results)
def test_find_groups_by_path(self):
results = self.kp.find_groups_by_path('/foobar_group/subgroup/')
self.assertIsInstance(results, Group)
results = self.kp.find_groups(path='/foobar_group/subgroup/', first=True)
self.assertEqual(results.name, 'subgroup')
results = self.kp.find_groups(path='foobar_group/group_entry')
self.assertEqual(results, None)
import pykeepass
from pykeepass import PyKeePass
import pykeepass.group
from pykeepass.group import Group
class ExtendedGroup(Group):
name = ""
group_path = ""
icon = ""
parent_group_uuid = ""
uuid = ""
def __init__(self, name, group_path, icon, parent_group_uuid, uuid):
self.name = name
self.group_path = group_path
self.icon = icon
self.parent_group_uuid = parent_group_uuid
self.uuid = uuid
#
# Setter
#
if tree is None:
tree = self.tree
logger.debug(xpath_str)
elements = tree.xpath(
xpath_str, namespaces={'re': 'http://exslt.org/regular-expressions'}
)
res = []
for e in elements:
if history or e.getparent().tag != 'History':
if cast:
if e.tag == 'Entry':
res.append(Entry(element=e, kp=self))
elif e.tag == 'Group':
res.append(Group(element=e, kp=self))
elif e.tag == 'Binary' and e.getparent().tag == 'Entry':
res.append(Attachment(element=e, kp=self))
else:
raise Exception('Could not cast element {}'.format(e))
else:
res.append(e)
# return first object in list or None
if first:
res = res[0] if res else None
return res
def add_group(self, destination_group, group_name, icon=None, notes=None):
logger.debug('Creating group {}'.format(group_name))
if icon:
group = Group(name=group_name, icon=icon, notes=notes, kp=self)
else:
group = Group(name=group_name, notes=notes, kp=self)
destination_group.append(group)
return group
def add_group(self, destination_group, group_name, icon=None, notes=None):
logger.debug('Creating group {}'.format(group_name))
if icon:
group = Group(name=group_name, icon=icon, notes=notes, kp=self)
else:
group = Group(name=group_name, notes=notes, kp=self)
destination_group.append(group)
return group