Esempio n. 1
0
	def setUp(self):
		# We set up a test connection to an in-memory sqlite database, and then we
		# make a dBizobj against the test table, and then we create a dForm with some
		# dTextBox's to test the interaction.
		self.con = dabo.db.dConnection(DbType="SQLite", Database=":memory:")
		biz = self.biz = dabo.biz.dBizobj(self.con)
		uniqueName = getRandomUUID().replace("-", "")[-20:]
		self.temp_table_name = "unittest%s" % uniqueName
		self.temp_child_table_name = "ut_child%s" % uniqueName
		self.createSchema()
		biz.UserSQL = "select * from %s" % self.temp_table_name
		biz.KeyField = "pk"
		biz.DataSource = self.temp_table_name
		biz.requery()

		## set up the ui elements:
		app = self.app = dApp(MainFormClass=None)
		app.setup()
		frm = self.frm = dabo.ui.dForm(Caption="test_dForm")
		frm.addObject(dabo.ui.dTextBox, DataSource=biz.DataSource, DataField="cField", RegID="cField")
		frm.addObject(dabo.ui.dTextBox, DataSource=biz.DataSource, DataField="nField", RegID="nField")
		frm.addObject(dabo.ui.dTextBox, DataSource=biz.DataSource, DataField="iField", RegID="iField")

		## connect the biz to the frm:
		frm.addBizobj(biz)

		## force the frm to get the first record:
		frm.first()
		frm.update(interval=0)  ## need to force the update here because it is delayed by default, which doesn't work for scripted tests.
Esempio n. 2
0
	def setUp(self):
		# We set up a test connection to an in-memory sqlite database, and then we
		# make a dBizobj against the test table, and then we create a dForm with some
		# dTextBox's to test the interaction.
		self.con = dabo.db.dConnection(DbType="SQLite", Database=":memory:")
		biz = self.biz = dabo.biz.dBizobj(self.con)
		uniqueName = getRandomUUID().replace("-", "")[-20:]
		self.temp_table_name = "unittest%s" % uniqueName
		self.temp_child_table_name = "ut_child%s" % uniqueName
		self.createSchema()
		biz.UserSQL = "select * from %s" % self.temp_table_name
		biz.KeyField = "pk"
		biz.DataSource = self.temp_table_name
		biz.requery()

		## set up the ui elements:
		app = self.app = dApp(MainFormClass=None)
		app.setup()
		frm = self.frm = dabo.ui.dForm(Caption="test_dForm")
		frm.addObject(dabo.ui.dTextBox, DataSource=biz.DataSource, DataField="cField", RegID="cField")
		frm.addObject(dabo.ui.dTextBox, DataSource=biz.DataSource, DataField="nField", RegID="nField")
		frm.addObject(dabo.ui.dTextBox, DataSource=biz.DataSource, DataField="iField", RegID="iField")

		## connect the biz to the frm:
		frm.addBizobj(biz)

		## force the frm to get the first record:
		frm.first()
		frm.update(interval=0)  ## need to force the update here because it is delayed by default, which doesn't work for scripted tests.
Esempio n. 3
0
			def addControls(self):
				conn = dabo.db.dConnection(MinesweeperCI())
				biz = self.biz = MinesweeperBO_gamedefs(conn)
				biz.requery()

				g = self.grid = self.addObject(Browse)
				g.FieldSpecs = biz.getGameDefFieldSpecs()
				g.DataSource = biz.DataSource
				self.Sizer.append1x(g)
Esempio n. 4
0
            def addControls(self):
                conn = dabo.db.dConnection(MinesweeperCI())
                biz = self.biz = MinesweeperBO_gamedefs(conn)
                biz.requery()

                g = self.grid = self.addObject(Browse)
                g.FieldSpecs = biz.getGameDefFieldSpecs()
                g.DataSource = biz.DataSource
                self.Sizer.append1x(g)
Esempio n. 5
0
	def testNullRecord(self):
		biz = self.biz
		self.createNullRecord()
		biz.requery()
		self.assertEqual(biz.RowCount, 4)
		biz.last()
		self.assertEqual(biz.RowNumber, 3)
		self.assertEqual(biz.Record.cField, None)
		self.assertEqual(biz.Record.iField, None)
		self.assertEqual(biz.Record.nField, None)
Esempio n. 6
0
	def test_UserSQL(self):
		biz = self.biz
		testSQL = "select * from %s where nField = 23.23" % self.temp_table_name
		biz.UserSQL = testSQL
		biz.requery()
		self.assertEqual(biz.LastSQL, biz.UserSQL)
		self.assertEqual(biz.UserSQL, testSQL)
		self.assertEqual(biz.RowCount, 1)
		self.assertEqual(biz.RowNumber, 0)
		self.assertEqual(biz.Record.cField, "Paul Keith McNett")
Esempio n. 7
0
	def setUp(self):
		self.con = dabo.db.dConnection(DbType="SQLite", Database=":memory:")
		biz = self.biz = dabo.biz.dBizobj(self.con)
		self.temp_table_name = "parent"
		self.temp_child_table_name = "child"
		self.temp_child2_table_name = "grandchild"
		self.createSchema()
		biz.KeyField = "pk"
		biz.DataSource = self.temp_table_name
		biz.requery()
Esempio n. 8
0
 def testNullRecord(self):
     biz = self.biz
     self.createNullRecord()
     biz.requery()
     self.assertEqual(biz.RowCount, 4)
     biz.last()
     self.assertEqual(biz.RowNumber, 3)
     self.assertEqual(biz.Record.cField, None)
     self.assertEqual(biz.Record.iField, None)
     self.assertEqual(biz.Record.nField, None)
Esempio n. 9
0
 def test_UserSQL(self):
     biz = self.biz
     testSQL = "select * from %s where nField = 23.23" % self.temp_table_name
     biz.UserSQL = testSQL
     biz.requery()
     self.assertEqual(biz.LastSQL, biz.UserSQL)
     self.assertEqual(biz.UserSQL, testSQL)
     self.assertEqual(biz.RowCount, 1)
     self.assertEqual(biz.RowNumber, 0)
     self.assertEqual(biz.Record.cField, "Paul Keith McNett")
Esempio n. 10
0
 def setUp(self):
     self.con = dabo.db.dConnection(DbType="SQLite", Database=":memory:")
     biz = self.biz = dabo.biz.dBizobj(self.con)
     self.temp_table_name = "parent"
     self.temp_child_table_name = "child"
     self.temp_child2_table_name = "grandchild"
     self.createSchema()
     biz.KeyField = "pk"
     biz.DataSource = self.temp_table_name
     biz.requery()
Esempio n. 11
0
    def testMementos(self):
        biz = self.biz
        cur = biz._CurrentCursor

        priorVal = biz.Record.cField

        # Make a change that is the same as the prior value:
        biz.Record.cField = priorVal
        self.assertEqual(priorVal, biz.Record.cField)

        # Make a change that is different:
        biz.Record.cField = "New test value"
        self.assertEqual(cur._mementos, {biz.Record.pk: {"cField": priorVal}})
        self.assertEqual(biz.isChanged(), True)

        # Change it back:
        biz.Record.cField = priorVal
        self.assertEqual(cur._mementos, {})
        self.assertEqual(biz.isChanged(), False)

        # Make a change that is different and cancel:
        biz.Record.cField = "New test value"
        biz.cancel()
        self.assertEqual(cur._mementos, {})
        self.assertEqual(biz.isChanged(), False)

        # Add a record:
        biz.new()

        self.assertEqual(biz.RowCount, 4)
        self.assertEqual(biz.RowNumber, 3)
        self.assertEqual(cur._newRecords, {-1: None})
        self.assertEqual(biz.isChanged(),
                         False)  ## (because no field changed in new record)
        self.assertEqual(cur.Record.pk, -1)
        self.assertEqual(biz.Record.cField, "")
        self.assertEqual(biz.Record.iField, 0)
        self.assertEqual(biz.Record.nField, 0)
        biz.save()
        self.assertEqual(
            biz.RowCount,
            4)  ## still have 4 rows, even though the last one wasn't saved
        biz.requery()
        # We only have 3 rows, because one of the prior 4 rows was new with no changed fields:
        self.assertEqual(biz.RowCount, 3)
        # ...and RowNumber went to 0, because the previous row number (3) doesn't exist anymore:
        self.assertEqual(biz.RowNumber, 0)
        self.assertEqual(cur._newRecords, {})
        self.assertEqual(biz.isChanged(), False)
        self.assertEqual(biz.Record.pk, 1)
Esempio n. 12
0
	def testMementos(self):
		biz = self.biz
		cur = biz._CurrentCursor

		priorVal = biz.Record.cField

		# Make a change that is the same as the prior value:
		biz.Record.cField = priorVal
		self.assertEqual(priorVal, biz.Record.cField)

		# Make a change that is different:
		biz.Record.cField = "New test value"
		self.assertEqual(cur._mementos, {biz.Record.pk: {"cField": priorVal}})
		self.assertEqual(biz.isChanged(), True)

		# Change it back:
		biz.Record.cField = priorVal
		self.assertEqual(cur._mementos, {})
		self.assertEqual(biz.isChanged(), False)

		# Make a change that is different and cancel:
		biz.Record.cField = "New test value"
		biz.cancel()
		self.assertEqual(cur._mementos, {})
		self.assertEqual(biz.isChanged(), False)

		# Add a record:
		biz.new()

		self.assertEqual(biz.RowCount, 4)
		self.assertEqual(biz.RowNumber, 3)
		self.assertEqual(cur._newRecords, {-1: None})
		self.assertEqual(biz.isChanged(), False)  ## (because no field changed in new record)
		self.assertEqual(cur.Record.pk, -1)
		self.assertEqual(biz.Record.cField, "")
		self.assertEqual(biz.Record.iField, 0)
		self.assertEqual(biz.Record.nField, 0)
		biz.save()
		self.assertEqual(biz.RowCount, 4)  ## still have 4 rows, even though the last one wasn't saved
		biz.requery()
		# We only have 3 rows, because one of the prior 4 rows was new with no changed fields:
		self.assertEqual(biz.RowCount, 3)
		# ...and RowNumber went to 0, because the previous row number (3) doesn't exist anymore:
		self.assertEqual(biz.RowNumber, 0)
		self.assertEqual(cur._newRecords, {})
		self.assertEqual(biz.isChanged(), False)
		self.assertEqual(biz.Record.pk, 1)
Esempio n. 13
0
	def onViewHighScores(self, evt):
		# ToDo: put in a window. For now, echo to terminal.
		gameId = self.preset["Id"]
		if gameId < 0 or gameId is None:
			dabo.ui.stop("Please select a preset game in Preferences first.")
			return
		if dabo.ui.areYouSure("Viewing the high scores requires an internet connection. Continue?"):
			conn = dabo.db.dConnection(MinesweeperCI())
			biz = MinesweeperBO_scores(conn)
			biz.GameId = gameId
			biz.requery()
			if biz.RowCount > 0:
				ds = biz.getDataSet()
				print("\nTop %d Scores for %s:" % (biz.Limit, biz.Record.gamename))
				for idx, r in enumerate(ds):
					r["row"] = idx+1
					print("\t%(row)d) %(playername)s: %(timestamp)s: %(time).3f sec." % r)
				print("\n")
			else:
				print("No high scores for this game yet.")
Esempio n. 14
0
 def onViewHighScores(self, evt):
     # ToDo: put in a window. For now, echo to terminal.
     gameId = self.preset["Id"]
     if gameId < 0 or gameId is None:
         dabo.ui.stop("Please select a preset game in Preferences first.")
         return
     if dabo.ui.areYouSure(
             "Viewing the high scores requires an internet connection. Continue?"
     ):
         conn = dabo.db.dConnection(MinesweeperCI())
         biz = MinesweeperBO_scores(conn)
         biz.GameId = gameId
         biz.requery()
         if biz.RowCount > 0:
             ds = biz.getDataSet()
             print "\nTop %d Scores for %s:" % (biz.Limit,
                                                biz.Record.gamename)
             for idx, r in enumerate(ds):
                 r["row"] = idx + 1
                 print "\t%(row)d) %(playername)s: %(timestamp)s: %(time).3f sec." % r
             print "\n"
         else:
             print "No high scores for this game yet."
Esempio n. 15
0
	def test_LastSQL(self):
		biz = self.biz
		self.assertEqual(biz.LastSQL, biz.AutoSQL)
		biz.UserSQL = "select * from %s limit 23" % (self.temp_table_name)
		biz.requery()
		self.assertEqual(biz.LastSQL, biz.UserSQL)
Esempio n. 16
0
 def test_LastSQL(self):
     biz = self.biz
     self.assertEqual(biz.LastSQL, biz.AutoSQL)
     biz.UserSQL = "select * from %s limit 23" % (self.temp_table_name)
     biz.requery()
     self.assertEqual(biz.LastSQL, biz.UserSQL)