def test_add_new_entry(self): # node = NewNode('alice', 'dough!', 'example.com', # 'lorem impsum') node = NewNode() node.username = '******' node.password = '******' node.url = 'example.com' node.notes = 'somenotes' node.tags = 'lorem ipsum' tags = self.tester.cli.get_tags(reader=lambda: u'looking glass') node.tags = tags self.tester.cli._db.addnodes([node]) self.tester.cli._db._cur.execute( "SELECT ID FROM NODES ORDER BY ID ASC", []) rows = self.tester.cli._db._cur.fetchall() # by now the db should have 2 new nodes # the first one was added by test_create_node in DBTests # the second was added just now. # This will pass only when running all the tests then ... self.assertEqual(len(rows), 2) node = NewNode() node.username = '******' node.password = '******' node.url = 'example.com' node.notes = 'somenotes' node.tags = 'lorem ipsum' tags = self.tester.cli.get_tags(reader=lambda: u'looking glass') node.tags = tags self.tester.cli._db.addnodes([node])
def test_create_node(self): "test that a node can be successfuly created" # this method does not test do_new # which is a UI method, rather we test # _db.addnodes username = '******' password = '******' url = 'example.org' notes = 'some notes' #node = NewNode(username, password, url, notes) node = NewNode() node.username = username node.password = password node.url = url node.notes = notes #node = NewNode(username, password, url, notes) tags = [TagNew(tn) for tn in ['testing1', 'testing2']] node.tags = tags self.db.open() self.db.addnodes([node]) idx_created = node._id new_node = self.db.getnodes([idx_created])[0] for key, attr in {'password': password, 'username': username, 'url': url, 'notes': notes}.iteritems(): self.assertEquals(attr, getattr(new_node, key)) self.db.close()
def node_factory(username, password, url, notes, tags=None): node = NewNode() node.username = username node.password = password node.url = url node.notes = notes tags = [TagNew(tn) for tn in tags] node.tags = tags return node
def test_db_remove_node(self): node = self.tester.cli._db.getnodes([1]) self.tester.cli._db.removenodes(node) # create the removed node again node = NewNode() node.username = '******' node.password = '******' node.url = 'example.org' node.notes = 'some notes' tags = [TagNew(tn) for tn in ['testing1', 'testing2']] node.tags = tags self.db.open() self.db.addnodes([node])
def do_new(self, args): """ can override default config settings the following way: Pwman3 0.2.1 (c) visit: http://github.com/pwman3/pwman3 pwman> n {'leetify':False, 'numerics':True, 'special_chars':True} Password (Blank to generate): """ errmsg = """could not parse config override, please input some"""\ + """ kind of dictionary, e.g.: n {'leetify':False, """\ + """'numerics':True, 'special_chars':True}""" try: username = self.get_username() if args: try: args = ast.literal_eval(args) except Exception: raise Exception(errmsg) if not isinstance(args, dict): raise Exception(errmsg) password = self.get_password(1, **args) else: numerics = config.get_value( "Generator", "numerics").lower() == 'true' # TODO: allow custom leetifying through the config leetify = config.get_value( "Generator", "leetify").lower() == 'true' special_chars = config.get_value( "Generator", "special_chars").lower() == 'true' password = self.get_password(0, numerics=numerics, symbols=leetify, special_signs=special_chars) url = self.get_url() notes = self.get_notes() node = NewNode() node.username = username node.password = password node.url = url node.notes = notes tags = self.get_tags() node.tags = tags self._db.addnodes([node]) print("Password ID: %d" % (node._id)) # when done with node erase it zerome(password) except Exception as e: self.error(e)
def convert_nodes(self): """convert old nodes instances to new format""" self.NewNodes = [] for node in self.oldnodes: username = node.get_username() password = node.get_password() url = node.get_url() notes = node.get_notes() tags = node.get_tags() tags_strings = [tag._name for tag in tags] newNode = NewNode() newNode.username = username newNode.password = password newNode.url = url newNode.notes = notes newNode.tags = tags_strings self.NewNodes.append(newNode)
def do_new(self, args): """ can override default config settings the following way: Pwman3 0.2.1 (c) visit: http://github.com/pwman3/pwman3 pwman> n {'leetify':False, 'numerics':True, 'special_chars':True} Password (Blank to generate): """ errmsg = ("could not parse config override, please input some" " kind of dictionary, e.g.: n {'leetify':False, " " numerics':True, 'special_chars':True}") try: username = self.get_username() if args: try: args = ast.literal_eval(args) except Exception: raise Exception(errmsg) if not isinstance(args, dict): raise Exception(errmsg) password = self.get_password(argsgiven=1, **args) else: numerics, leet, s_chars = get_pass_conf() password = self.get_password(argsgiven=0, numerics=numerics, leetify=leet, special_signs=s_chars) url = self.get_url() notes = self.get_notes() node = NewNode() node.username = username node.password = password node.url = url node.notes = notes # node = NewNode(username, password, url, notes) node.tags = self.get_tags() self._db.addnodes([node]) print ("Password ID: %d" % (node._id)) # when done with node erase it zerome(password) except Exception as e: self.error(e)
def getnodes(self, ids): """ object should always be: (ipwman.data.nodes """ nodes = [] for i in ids: sql = "SELECT DATA FROM NODES WHERE ID = ?" self._cur.execute(sql, [i]) row = self._cur.fetchone() if row is not None: nodestring = str(row[0]) args, tags = self.parse_node_string(nodestring) node = NewNode() node._password = args['password'] node._username = args['username'] node._url = args['url'] node._notes = args['notes'] node.tags = tags node._id = i nodes.append(node) return nodes