Exemplo n.º 1
0
class TestDB(unittest.TestCase):
    """Exercise the DB wrapper/adapter class.

    This test case contains a number of general methods for analysing
    a sqlite3 database, comparing schema to a known one, etc. This
    class depends on an easily configurable database path to avoid
    wiping out a "production" database, load reference dataset(s),
    etc.
    """

    # TODO: Use mock for this!
    # TODO: Move to memory?
    DB.path_db = PATH_TESTDB

    def setUp(self):
        # Create a connection to the reference database.
        self.db = DB()

    def test_select_from_quota_vw(self):
        """Returns contents of `quota_vw` as a DataFrame."""
        df = self.db.select_from_quota_vw()
        self.assertIsInstance(df, pandas.DataFrame)
        self.assertEqual(len(df), 68)

    def test_select_last_from_quota_vw(self):
        """Return the latest timestamp and percent value."""
        t = self.db.select_last_from_quota_vw()
        self.assertIsInstance(t, tuple)
        self.assertEqual(len(t), 2)
        self.assertEqual(t[0], datetime(2002, 1, 1, 18))
        self.assertEqual(t[1], 98)
Exemplo n.º 2
0
 def setUp(self):
     # Create a connection to the reference database.
     self.db = DB()