Procházet zdrojové kódy

Add test skeleton to importer

oz123 před 10 roky
rodič
revize
6a1aaafe93

+ 1 - 0
pwman/exchange/importer.py

@@ -19,6 +19,7 @@
 '''
 A module to hold the importer class
 '''
+import csv
 
 
 class BaseImporter(object):

+ 55 - 0
pwman/tests/test_importer.py

@@ -0,0 +1,55 @@
+# ============================================================================
+# This file is part of Pwman3.
+#
+# Pwman3 is free software; you can redistribute iut and/or modify
+# it under the terms of the GNU General Public License, version 2
+# as published by the Free Software Foundation;
+#
+# Pwman3 is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with Pwman3; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+# ============================================================================
+# Copyright (C) 2012, 2013, 2014 Oz Nahum Tiram <nahumoz@gmail.com>
+# ============================================================================
+import os
+import unittest
+from pwman.util.crypto_engine import CryptoEngine
+from collections import namedtuple
+from .test_crypto_engine import give_key, DummyCallback
+from pwman.exchange.importer import CSVImporter
+
+import_example = """
+Username;URL;Password;Notes;Tags
+alice;wonderland.com;secert;scratch;foo,bar
+hatman;behindthemirror.com;pa33w0rd;scratch;foo,bar
+"""
+
+with open('import_file.csv', 'w') as f:
+    f.write(import_example)
+
+
+class TestImporter(unittest.TestCase):
+
+    def setUp(self):
+        config = {}
+        Args = namedtuple('args', 'import_file')
+        self.importer = CSVImporter(Args(import_file='foo'), config)
+
+    def test_fail(self):
+        self.assertTrue(True)
+
+if __name__ == '__main__':
+
+    ce = CryptoEngine.get()
+    ce.callback = DummyCallback()
+    ce.changepassword(reader=give_key)
+
+    try:
+        unittest.main(verbosity=2, failfast=True)
+    except SystemExit:
+        os.remove('import_file.csv')

+ 2 - 0
pwman/tests/test_pwman.py

@@ -30,6 +30,7 @@ from .db_tests import (DBTests, SetupTester, CLITests,
 from .test_crypto_engine import CryptoEngineTest
 from .test_config import TestConfig
 from .test_sqlite import TestSQLite
+from .test_importer import TestImporter
 
 if 'win' not in sys.platform:
     from .test_complete_ui import (Ferrum, NEW_DB_PATH)
@@ -57,6 +58,7 @@ def suite():
     suite.addTest(loader.loadTestsFromTestCase(CryptoEngineTest))
     suite.addTest(loader.loadTestsFromTestCase(TestConfig))
     suite.addTest(loader.loadTestsFromTestCase(TestSQLite))
+    suite.addTest(loader.loadTestsFromTestCase(TestImporter))
     #if 'win' not in sys.platform:
     #    suite.addTest(loader.loadTestsFromTestCase(Ferrum))
     return suite

+ 4 - 3
scripts/pwman3

@@ -26,6 +26,7 @@ from pwman import parser_options
 from pwman.ui import get_ui_platform
 from pwman.ui.tools import CLICallback
 import pwman.data.factory
+from pwman.exchange.importer import Importer
 from pwman.util.crypto_engine import CryptoEngine
 
 if sys.version_info.major > 2:
@@ -39,9 +40,9 @@ def main(args):
     CryptoEngine.get(dbver)
 
     if args.import_file:
-       importer = Importer(args, config)
-       importer.run()
-       sys.exit(0)
+        importer = Importer(args, config)
+        importer.run()
+        sys.exit(0)
 
     fname = config.get_value('Database', 'filename')
     db = pwman.data.factory.create(dbtype, dbver, fname)