Exemplo n.º 1
0
 def test_delete(self):
     # arrange
     self._make_synthetic_data()
     self.assertTrue(os.path.exists(self.directory))
     dbdriver = DbDriver(db_directory=self.directory)
     dbdriver.create_table("foo")
     dbdriver.dump_tables()
     dbdriver.delete_table("foo")
     # act
     deleting_access_code = dbdriver.get_deleting_access()
     deleting_access_code = deleting_access_code[43:53]
     dbdriver.delete(deleting_access_code)
     # assert
     self.assertFalse(os.path.exists(self.directory))
Exemplo n.º 2
0
    def test_delete_table(self):
        """ Unit test """
        # arrange
        table_name = "labada"
        mock_table = MagicMock()
        mock_table_2 = MagicMock()

        mock_db = MagicMock()
        mock_db._DbDriver__read_only = False
        mock_db._DbDriver__tables = {
            table_name: mock_table,
            "other": mock_table_2
        }
        mock_db._DbDriver__dropped_tables = []

        # act
        DbDriver.delete_table(mock_db, table_name)

        # assert
        self.assertDictEqual(mock_db._DbDriver__tables,
                             {"other": mock_table_2})
        self.assertListEqual(mock_db._DbDriver__dropped_tables, [table_name])
Exemplo n.º 3
0
    def test_read_only_errors(self):
        # arrange
        self._make_synthetic_data()
        db = DbDriver(self.directory, read_only=True)

        # saving to harddrive
        with self.assertRaises(IOError) as e:
            db.dump_tables()
        self.assertEqual(e.exception.args[0], "DB is for reading only.")

        # adding table
        with self.assertRaises(IOError) as e:
            db.create_table("test_table")
        self.assertEqual(e.exception.args[0], "DB is for reading only.")

        # puting records
        with self.assertRaises(IOError) as e:
            db["first_table"].put({"c": 5})
        self.assertEqual(e.exception.args[0], "Table is for read only.")

        # dropping table
        with self.assertRaises(IOError) as e:
            db.delete_table("first_table")
        self.assertEqual(e.exception.args[0], "DB is for reading only.")

        # obtaining deleting access code
        with self.assertRaises(IOError) as e:
            db.get_deleting_access()
        self.assertEqual(e.exception.args[0], "DB is for reading only.")

        # deleting db
        with self.assertRaises(IOError) as e:
            db.delete(access_code="something")
        self.assertEqual(e.exception.args[0], "DB is for reading only.")

        # clean up
        self._clean_synthetic_data()