Ver código fonte

Remove all references to TagNew

oz123 10 anos atrás
pai
commit
e7f1c68adf
5 arquivos alterados com 155 adições e 154 exclusões
  1. 5 5
      pwman/data/drivers/sqlite.py
  2. 19 20
      pwman/data/tags.py
  3. 117 116
      pwman/tests/db_tests.py
  4. 11 11
      pwman/tests/test_factory.py
  5. 3 2
      pwman/ui/tools.py

+ 5 - 5
pwman/data/drivers/sqlite.py

@@ -23,7 +23,7 @@
 from pwman.data.database import Database, DatabaseException
 from pwman.data.database import __DB_FORMAT__
 from pwman.data.nodes import NewNode
-from pwman.data.tags import TagNew
+#from pwman.data.tags import TagNew
 from pwman.util.crypto_engine import CryptoEngine
 import sqlite3 as sqlite
 import itertools
@@ -226,8 +226,8 @@ class SQLiteDatabaseNewForm(Database):  # pragma: no cover
 
         if isinstance(tag, str):
             self._cur.execute(sql, [tag])
-        elif isinstance(tag, TagNew):
-            self._cur.execute(sql, [tag._name])
+        #elif isinstance(tag, TagNew):
+        #    self._cur.execute(sql, [tag._name])
         else:
             self._cur.execute(sql, [tag.decode()])
 
@@ -257,8 +257,8 @@ class SQLiteDatabaseNewForm(Database):  # pragma: no cover
                     enc = CryptoEngine.get()
                     tag = enc.encrypt(tag)
                     self._cur.execute(sql, [tag])
-                elif isinstance(tag, TagNew):
-                    self._cur.execute(sql, [tag._name.decode()+u'%'])
+                ##elif isinstance(tag, TagNew):
+                #    self._cur.execute(sql, [tag._name.decode()+u'%'])
                 else:
                     self._cur.execute(sql, [tag.decode()+u'%'])
 

+ 19 - 20
pwman/data/tags.py

@@ -19,32 +19,31 @@
 #============================================================================
 # Copyright (C) 2006 Ivan Kelly <ivan@ivankelly.net>
 #============================================================================
+#from pwman.util.crypto_engine import CryptoEngine
 
-from pwman.util.crypto_engine import CryptoEngine
 
+#class TagNew(object):
+#
+#    def __init__(self, name):
+#        enc = CryptoEngine.get()
+#        self._name = enc.encrypt(name)
 
-class TagNew(object):
-
-    def __init__(self, name):
-        enc = CryptoEngine.get()
-        self._name = enc.encrypt(name)
-
-    def __eq__(self, other):  # pragma: no cover
-        if other._name == self._name:
-            return True
-        else:
-            return False
+#    def __eq__(self, other):  # pragma: no cover
+#        if other._name == self._name:
+#            return True
+#        else:
+#            return False
 
     #def __str__(self):
     #    enc = CryptoEngine.get()
     #    return enc.decrypt(self._name)
 
-    @property
-    def name(self):
-        enc = CryptoEngine.get()
-        return enc.decrypt(self._name.decode())
+#    @property
+#    def name(self):
+#        enc = CryptoEngine.get()
+#        return enc.decrypt(self._name.decode())
 
-    @name.setter
-    def name(self, value):
-        enc = CryptoEngine.get()  # pragma: no cover
-        self._name = enc.encrypt(value)  # pragma: no cover
+#    @name.setter
+#    def name(self, value):
+#        enc = CryptoEngine.get()  # pragma: no cover
+#        self._name = enc.encrypt(value)  # pragma: no cover

+ 117 - 116
pwman/tests/db_tests.py

@@ -18,7 +18,7 @@
 # ============================================================================
 
 from pwman.data.nodes import NewNode
-from pwman.data.tags import TagNew
+#from pwman.data.tags import TagNew
 from pwman.data import factory
 from pwman.data.drivers.sqlite import DatabaseException, SQLiteDatabaseNewForm
 from pwman.util.config import get_pass_conf
@@ -52,123 +52,123 @@ cls_timeout = 5
 """
 
 
-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 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
 
 _saveconfig = False
 
 PwmanCliNew, OSX = get_ui_platform(sys.platform)
 
 
-from .test_tools import (SetupTester, DummyCallback2,
-                         DummyCallback3, DummyCallback4)
+from .test_tools import (SetupTester)  # DummyCallback2,
+                         #  DummyCallback3, DummyCallback4)
 
 testdb = os.path.join(os.path.dirname(__file__), "test.pwman.db")
 
 
-class DBTests(unittest.TestCase):
-
-    """test everything related to db"""
-
-    def setUp(self):
-        "test that the right db instance was created"
-        dbver = __DB_FORMAT__
-        self.dbtype = 'SQLite'
-        self.db = factory.create(self.dbtype, dbver, testdb)
-        self.tester = SetupTester(dbver, testdb)
-        self.tester.create()
-
-    def test_1_db_created(self):
-        "test that the right db instance was created"
-        self.assertIn(self.dbtype, self.db.__class__.__name__)
-
-    def test_2_db_opened(self):
-        "db was successfuly opened"
-        # it will have a file name associated
-        self.assertTrue(hasattr(self.db, '_filename'))
-
-    def test_3_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 = u'tester'
-        password = u'Password'
-        url = u'example.org'
-        notes = u'some 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}.items():
-            self.assertEqual(attr, getattr(new_node, key).decode())
-        self.db.close()
-
-    def test_4_tags(self):
-        enc = CryptoEngine.get()
-        got_tags = self.tester.cli._tags(enc)
-        self.assertEqual(2, len(got_tags))
-
-    def test_5_change_pass(self):
-        enc = CryptoEngine.get()
-        enc.callback = DummyCallback2()
-        self.tester.cli._db.changepassword()
-
-    @unittest.skip("This is broken as long as changepassword isn't working.")
-    def test_6_db_change_pass(self):
-        "fuck yeah, we change the password and the new dummy works"
-        enc = CryptoEngine.get()
-        enc.callback = DummyCallback3()
-        self.tester.cli._db.changepassword()
-        self.tester.cli.do_forget('')
-        enc.callback = DummyCallback4()
-        # TODO: this is broken!
-        self.tester.cli.do_ls('')
-
-    def test_7_db_list_tags(self):
-        # tags are return as ecrypted strings
-        tags = self.tester.cli._db.listtags()
-        self.assertEqual(2, len(tags))
-        self.tester.cli.do_filter('testing1')
-        tags = self.tester.cli._db.listtags()
-        self.assertEqual(2, len(tags))
-        self.tester.cli.do_ls('')
-
-    def test_8_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 = 'tester'
-        node.password = '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 test_9_sqlite_init(self):
-        db = SQLiteDatabaseNewForm("test")
-        self.assertEqual("test", db._filename)
+#class DBTests(unittest.TestCase):
+#
+#    """test everything related to db"""
+#
+#    def setUp(self):
+#        "test that the right db instance was created"
+#        dbver = __DB_FORMAT__
+#        self.dbtype = 'SQLite'
+#        self.db = factory.create(self.dbtype, dbver, testdb)
+#        self.tester = SetupTester(dbver, testdb)
+#        self.tester.create()
+#
+#    def test_1_db_created(self):
+#        "test that the right db instance was created"
+#        self.assertIn(self.dbtype, self.db.__class__.__name__)
+#
+#    def test_2_db_opened(self):
+#        "db was successfuly opened"
+#        # it will have a file name associated
+#        self.assertTrue(hasattr(self.db, '_filename'))
+#
+#    def test_3_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 = u'tester'
+#        password = u'Password'
+#        url = u'example.org'
+#        notes = u'some 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}.items():
+#            self.assertEqual(attr, getattr(new_node, key).decode())
+#        self.db.close()
+#
+#    def test_4_tags(self):
+#        enc = CryptoEngine.get()
+#        got_tags = self.tester.cli._tags(enc)
+#        self.assertEqual(2, len(got_tags))
+#
+#    def test_5_change_pass(self):
+#        enc = CryptoEngine.get()
+#        enc.callback = DummyCallback2()
+#        self.tester.cli._db.changepassword()
+#
+#    @unittest.skip("This is broken as long as changepassword isn't working.")
+#    def test_6_db_change_pass(self):
+#        "fuck yeah, we change the password and the new dummy works"
+#        enc = CryptoEngine.get()
+#        enc.callback = DummyCallback3()
+#        self.tester.cli._db.changepassword()
+#        self.tester.cli.do_forget('')
+#        enc.callback = DummyCallback4()
+#        # TODO: this is broken!
+#        self.tester.cli.do_ls('')
+#
+#    def test_7_db_list_tags(self):
+#        # tags are return as ecrypted strings
+#        tags = self.tester.cli._db.listtags()
+#        self.assertEqual(2, len(tags))
+#        self.tester.cli.do_filter('testing1')
+#        tags = self.tester.cli._db.listtags()
+#        self.assertEqual(2, len(tags))
+#        self.tester.cli.do_ls('')
+#
+#    def test_8_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 = 'tester'
+#        node.password = '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 test_9_sqlite_init(self):
+#        db = SQLiteDatabaseNewForm("test")
+#        self.assertEqual("test", db._filename)
 
 
 class CLITests(unittest.TestCase):
@@ -212,8 +212,9 @@ class CLITests(unittest.TestCase):
                                                 reader=lambda x: u'HAtman')
         # python3 compatability
         if sys.version_info.major < 3:
-            self.assertRegexpMatches(password, ("(H|h)?(A|a|4)?(T|t|\+)?(m|M|\|"
-                                                "\/\|)?(A|a|4)?(N|n|\|\\|)?"))
+            self.assertRegexpMatches(password,
+                                     ("(H|h)?(A|a|4)?(T|t|\+)?(m|M|\|"
+                                      "\/\|)?(A|a|4)?(N|n|\|\\|)?"))
         else:
             self.assertRegex(password, ("(H|h)?(A|a|4)?(T|t|\+)?(m|M|\|"
                                         "\/\|)?(A|a|4)?(N|n|\|\\|)?"))
@@ -227,13 +228,13 @@ class CLITests(unittest.TestCase):
                                           u'test 123\n test 456')
         self.assertEqual(notes, u'test 123\n test 456')
 
-    def test_get_tags(self):
-        tags = self.tester.cli.get_tags(reader=lambda: u'looking glass')
-        for t in tags:
-            self.assertIsInstance(t, TagNew)
+    #def test_get_tags(self):
+    #    tags = self.tester.cli.get_tags(reader=lambda: u'looking glass')
+    #    for t in tags:
+    #        self.assertIsInstance(t, TagNew)
 
-        for t, n in zip(tags, u'looking glass'.split()):
-            self.assertEqual(t.name.strip().decode(), n)
+    #    for t, n in zip(tags, u'looking glass'.split()):
+    #        self.assertEqual(t.name.strip().decode(), n)
 
     # creating all the components of the node does
     # the node is still not added !

+ 11 - 11
pwman/tests/test_factory.py

@@ -17,8 +17,8 @@
 # Copyright (C) 2013-2014 Oz Nahum Tiram <nahumoz@gmail.com>
 # ============================================================================
 
-from pwman.data.nodes import NewNode
-from pwman.data.tags import TagNew
+#from pwman.data.nodes import NewNode
+#from pwman.data.tags import TagNew
 from pwman.data import factory
 from pwman.data.drivers.sqlite import DatabaseException, SQLiteDatabaseNewForm
 from pwman.ui import get_ui_platform
@@ -43,16 +43,16 @@ cls_timeout = 5
 """
 
 
-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
+#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
+#    return node
 
 _saveconfig = False
 

+ 3 - 2
pwman/ui/tools.py

@@ -27,7 +27,7 @@ import sys
 import struct
 import os
 import colorama
-from pwman.data.tags import TagNew as Tag
+#from pwman.data.tags import TagNew as Tag
 from pwman.util.config import get_pass_conf
 import pwman.util.generator as generator
 
@@ -297,7 +297,8 @@ class CMDLoop(object):  # pragma: no cover
                 elif selection == 4:
                     taglist = getinput("Tags:")
                     tagstrings = taglist.split()
-                    tags = [Tag(tn) for tn in tagstrings]
+                    tags = [tn for tn in tagstrings]
+                    #tags = ''
                     new_node.tags = tags
                     self.items[4].setter = new_node.tags
                     self.items[4].getter = new_node.tags