Exemplo n.º 1
0
 def setUp(self):
     config = {}
     db = SQLite('test-importer.db')
     Args = namedtuple('args', 'file_delim')
     args = Args(file_delim=['import_file.csv', ';'])
     self.importer = CSVImporter(args,
                                 config, db)
Exemplo n.º 2
0
 def setUp(self):
     config = {}
     db = SQLite('test-importer.db')
     Args = namedtuple('args', 'import_file')
     args = Args(import_file=open('import_file.csv'))
     self.importer = CSVImporter(args,
                                 config, db)
Exemplo n.º 3
0
class TestImporter(unittest.TestCase):

    @classmethod
    def setUpClass(cls):
        f = open('import_file.csv', 'w')
        f.write(import_example)
        f.close()

    @classmethod
    def tearDownClass(cls):
        for item in ('import_file.csv', 'test-importer.db',
                     'testfile.conf', 'importdummy.db'):
            try:
                os.unlink(item)
            except OSError:
                continue

    def setUp(self):
        config = {}
        db = SQLite('test-importer.db')
        Args = namedtuple('args', 'file_delim')
        args = Args(file_delim=['import_file.csv', ';'])
        self.importer = CSVImporter(args,
                                    config, db)

    def test_1_read_file(self):
        lines = self.importer._read_file()
        self.assertNotIn(["Username", "URL", "Password", "Notes", " Tags"],
                         lines)

    def test_2_create_node(self):
        # create a node , should be encrypted, but not yet inserted to db
        n = "alice;wonderland.com;secert;scratch;foo,bar".split(";")
        node = self.importer._create_node(n)
        ce = CryptoEngine.get()
        self.assertEqual(ce.decrypt(node._username).decode(), u'alice')
        self.assertEqual([b'foo', b'bar'], [t for t in node.tags])

    def test_3_insert_node(self):
        self.importer._open_db()
        n = "alice;wonderland.com;secert;scratch;foo,bar".split(";")
        node = self.importer._create_node(n)
        # do the actual insert of the node to the databse
        self.importer._insert_node(node)

    def test_4_runner(self):
        # test the whole procees:
        """
          open csv
          open db
          for line in csv:
              create node
              insert node

          close db
        """

        # args need import_file , db,
        Args = namedtuple('Args', 'file_delim, db')
        if os.path.exists('importdummy.db'):
            os.unlink('importdummy.db')
        args = Args(file_delim=['import_file.csv', ';'], db='importdummy.db')
        p = os.getcwd()
        if sys.platform.startswith("win"):
            p = p.strip("C:\\")
            print(os.getcwd())

        db = pwman.data.factory.createdb('sqlite:///' + p +
                                         '/importdummy.db', 0.6)
        importer = Importer((args, '', db))
        importer.importer.run(callback=DummyCallback)
Exemplo n.º 4
0
 def setUp(self):
     config = {}
     db = SQLite('test-importer.db')
     Args = namedtuple('args', 'file_delim')
     args = Args(file_delim=['import_file.csv', ';'])
     self.importer = CSVImporter(args, config, db)
Exemplo n.º 5
0
class TestImporter(unittest.TestCase):
    @classmethod
    def setUpClass(cls):
        f = open('import_file.csv', 'w')
        f.write(import_example)
        f.close()

    @classmethod
    def tearDownClass(cls):
        for item in ('import_file.csv', 'test-importer.db', 'testfile.conf',
                     'importdummy.db'):
            try:
                os.unlink(item)
            except OSError:
                continue

    def setUp(self):
        config = {}
        db = SQLite('test-importer.db')
        Args = namedtuple('args', 'file_delim')
        args = Args(file_delim=['import_file.csv', ';'])
        self.importer = CSVImporter(args, config, db)

    def test_1_read_file(self):
        lines = self.importer._read_file()
        self.assertNotIn(["Username", "URL", "Password", "Notes", " Tags"],
                         lines)

    def test_2_create_node(self):
        # create a node , should be encrypted, but not yet inserted to db
        n = "alice;wonderland.com;secert;scratch;foo,bar".split(";")
        node = self.importer._create_node(n)
        ce = CryptoEngine.get()
        self.assertEqual(ce.decrypt(node._username).decode(), u'alice')
        self.assertEqual([b'foo', b'bar'], [t for t in node.tags])

    def test_3_insert_node(self):
        self.importer._open_db()
        n = "alice;wonderland.com;secert;scratch;foo,bar".split(";")
        node = self.importer._create_node(n)
        # do the actual insert of the node to the databse
        self.importer._insert_node(node)

    def test_4_runner(self):
        # test the whole procees:
        """
          open csv
          open db
          for line in csv:
              create node
              insert node

          close db
        """

        # args need import_file , db,
        Args = namedtuple('Args', 'file_delim, db')
        if os.path.exists('importdummy.db'):
            os.unlink('importdummy.db')
        args = Args(file_delim=['import_file.csv', ';'], db='importdummy.db')
        p = os.getcwd()
        if sys.platform.startswith("win"):
            p = p.strip("C:\\")
            print(os.getcwd())

        db = pwman.data.factory.createdb('sqlite:///' + p + '/importdummy.db',
                                         0.6)
        importer = Importer((args, '', db))
        importer.importer.run(callback=DummyCallback)