示例#1
0
 def test_state_tables(self):
     states = dict(gather_installed("turberfield.utils.states"))
     con = Connection(**Connection.options())
     with con as db:
         rv = Creation(*schema.values()).run(db)
         tables = self.get_tables(db)
         self.assertIn("state", [t.get("name") for t in tables])
示例#2
0
 def setUp(self):
     self.db = Connection(**Connection.options())
     with self.db as con:
         with con as change:
             rv = Creation(
                 *SchemaBase.tables.values()
             ).run(change)
示例#3
0
 def test_not_null(self):
     con = Connection(**Connection.options())
     with con as db:
         rv = Creation(schema["entity"]).run(db)
         self.assertRaises(
             sqlite3.IntegrityError,
             Insertion(
                 schema["entity"],
                 data=dict(
                     session=uuid.uuid4().hex
                 )
             ).run,
             db
         )
示例#4
0
 def test_creation_sql(self):
     table = Table(
         "records",
         cols=[
           Table.Column("id", int, True, False, None, None, None),
           Table.Column("ts", datetime.datetime, False, False, None, None, None),
           Table.Column("valid", bool, False, True, None, None, None),
           Table.Column("data", str, False, True, None, None, None),
         ]
     )
     con = Connection(**Connection.options())
     with con as db:
         rv = Creation(table).run(db)
         n = len(self.get_tables(db))
         self.assertEqual(1, n)
示例#5
0
 def test_insertion_keys(self):
     con = Connection(**Connection.options())
     with con as db:
         rv = Creation(schema["touch"]).run(db)
         session=uuid.uuid4().hex
         self.assertRaises(
             sqlite3.OperationalError,
             Insertion(
                 schema["touch"],
                 data=dict(
                     sbjct=1,
                     objct=1
                 )
             ).run,
             db
         )
示例#6
0
 def test_one_db_in_memory(self):
     rv = Connection.options()
     self.assertIsInstance(rv, dict)
     self.assertEqual(1, len(rv["attach"]))
     self.assertIn(
         Connection.CacheOptions.shared,
         list(rv["attach"].values())[0]
     )
示例#7
0
 def test_insertion_entity(self):
     con = Connection(**Connection.options())
     with con as db:
         rv = Creation(schema["entity"]).run(db)
         session=uuid.uuid4().hex
         Insertion(
             schema["entity"],
             data=dict(
                 session=session,
                 name="test"
             )
         ).run(db)
         cur = db.cursor()
         cur.execute("select * from entity")
         rv = cur.fetchall()
         self.assertEqual(1, len(rv))
         self.assertEqual(rv[0]["id"], 1)
         self.assertEqual(rv[0]["name"], "test")
示例#8
0
    def __init__(self,
                 terminal,
                 dbPath=None,
                 pause=pause,
                 dwell=dwell,
                 log=None):
        self.terminal = terminal
        self.dbPath = dbPath
        self.pause = pause
        self.dwell = dwell

        self.log_manager = LogManager()
        self.log = log or self.log_manager.clone(
            self.log_manager.get_logger("main"), "turberfield.dialogue.handle")

        self.shot = None
        self.con = Connection(**Connection.options(
            paths=[dbPath] if dbPath else []))
        self.handle_creation()
示例#9
0
 def test_insertion_entities(self):
     con = Connection(**Connection.options())
     session = uuid.uuid4().hex
     with con as db:
         rv = Creation(schema["entity"]).run(db)
         Insertion(
             schema["entity"],
             data=[
                 {"name": "test_one", "session": session},
                 {"name": "test_two", "session": session}
             ]
         ).run(db)
         cur = db.cursor()
         cur.execute("select * from entity")
         rv = cur.fetchall()
         self.assertEqual(2, len(rv))
         self.assertEqual(rv[0]["id"], 1)
         self.assertEqual(rv[0]["name"], "test_one")
         self.assertEqual(rv[1]["id"], 2)
         self.assertEqual(rv[1]["name"], "test_two")
示例#10
0
 def test_one_db_from_file(self):
     fd, path = next(OptionTests.make_db_files(self.drcty, 1))
     paths = glob.glob(os.path.join(self.drcty.name, "*.db"))
     self.assertEqual(1, len(paths)) 
     OptionTests.close_db_files((fd, path))
     rv = Connection.options(paths=paths)
     self.assertIsInstance(rv, dict)
     self.assertEqual(1, len(rv["attach"]))
     self.assertIn(
         Connection.ModeOptions.read_write_create,
         list(rv["attach"].values())[0]
     )
示例#11
0
 def test_primary_keys(self):
     con = Connection(**Connection.options())
     with con as db:
         rv = Creation(schema["entity"]).run(db)
         session=uuid.uuid4().hex
         rv = Insertion(
             schema["entity"],
             data=dict(
                 name="test",
                 session=session
             )
         ).run(db)
         self.assertRaises(
             sqlite3.IntegrityError,
             Insertion(
                 schema["entity"],
                 data=dict(
                     session=session
                 )
             ).run,
             db
         )
示例#12
0
 def test_ten_db_from_file(self):
     items = list(OptionTests.make_db_files(self.drcty, 10))
     paths = glob.glob(os.path.join(self.drcty.name, "*.db"))
     self.assertEqual(10, len(paths)) 
     OptionTests.close_db_files(*items)
     rv = Connection.options(paths=paths)
     self.assertIsInstance(rv, dict)
     self.assertEqual(11, len(rv["attach"]))
     name, options = rv["attach"].popitem(last=False)
     self.assertEqual(":memory:", name)
     self.assertIn(Connection.ModeOptions.memory, options)
     self.assertTrue(all(
         Connection.ModeOptions.read in i
         for i in rv["attach"].values())
     )
示例#13
0
    def test_selection_entity(self):
        class Selection(SQLOperation):

            @property
            def sql(self):
                return ("select * from {0.name}".format(self.tables[0]) , {})

        con = Connection(**Connection.options())
        with con as db:
            rv = Creation(schema["entity"]).run(db)
            session = uuid.uuid4().hex
            cur = Insertion(
                schema["entity"],
                data=dict(
                    session=session,
                    name="test"
                )
            ).run(db)

            rv = Selection(schema["entity"]).run(db)
            rows = rv.fetchall()
            self.assertEqual(1, len(rows))
            self.assertEqual(rows[0]["id"], 1)
            self.assertEqual(rows[0]["name"], "test")
示例#14
0
 def test_one_db_in_memory(self):
     con = Connection(**Connection.options())
     self.assertIsNone(con.db)
     with con as db:
         self.assertTrue(con.db)