Beispiel #1
0
    def idSwiped(self,user):
        # Swap the current user.
        lastUser = self.currentUser
        self.currentUser = user.getId()

        # Set the access type if the swiped user hasn't changed. The first swipe is used to show the current status.
        accessType = user.getAccessType()
        if self.currentUser == lastUser:
            if accessType == "UNAUTHORIZED":
                accessType = "AUTHORIZED"
            elif accessType == "AUTHORIZED":
                accessType = "ADMIN"
            else:
                accessType = "UNAUTHORIZED"
            DatabaseManager.setUserAccessType(self.currentUser,accessType)

        # Invoke the observers.
        self.notify(self.currentUser,accessType)
 def setUp(self):
     DatabaseManager.staticDatabaseManager = DatabaseManager.DatabaseManager(
         ":memory:")
     DatabaseManager.setUserAccessType("000000000", "AUTHORIZED")
     DatabaseManager.setUserAccessType("000000001", "UNAUTHORIZED")
     DatabaseManager.setUserAccessType("000000002", "ADMIN")
     self.testUser = User.User("000000000", 1, "AUTHORIZED")
     self.testUnauthorizedUser = User.User("000000001", 0, "UNAUTHORIZED")
     self.testAdminUser = User.User("000000002", 1, "ADMIN")
    def test_setUserAccessType(self):
        # Initialize and close the initial database.
        self.initialDatabase.execute(
            "CREATE TABLE Users (Id char(9),AccessType STRING);")
        self.initialDatabase.execute(
            "CREATE TABLE Sessions (Id char(9),StartTime BIGINT,EndTime BIGINT);"
        )
        self.initialDatabase.commit()
        self.initialDatabase.close()

        # Set a new user type and assert the entries are correct.
        DatabaseManager.staticDatabaseManager = DatabaseManager.DatabaseManager(
            self.databaseFile)
        DatabaseManager.setUserAccessType("000000001", "AUTHORIZED")
        users = DatabaseManager.staticDatabaseManager.database.execute(
            "SELECT * FROM Users;").fetchall()
        self.assertEqual(users[0], ("000000001", "AUTHORIZED"),
                         "User is incorrect.")

        # Set a new user type and assert the entries are correct.
        DatabaseManager.setUserAccessType("000000002", "ADMIN")
        users = DatabaseManager.staticDatabaseManager.database.execute(
            "SELECT * FROM Users;").fetchall()
        self.assertEqual(users[0], ("000000001", "AUTHORIZED"),
                         "User is incorrect.")
        self.assertEqual(users[1], ("000000002", "ADMIN"),
                         "User is incorrect.")

        # Set a new user type and assert the entries are correct.
        DatabaseManager.setUserAccessType("000000001", "ADMIN")
        users = DatabaseManager.staticDatabaseManager.database.execute(
            "SELECT * FROM Users;").fetchall()
        self.assertEqual(users[0], ("000000001", "ADMIN"),
                         "User is incorrect.")
        self.assertEqual(users[1], ("000000002", "ADMIN"),
                         "User is incorrect.")

        # Set a new user type and assert the entries are correct.
        DatabaseManager.setUserAccessType("000000001", "UNAUTHORIZED")
        users = DatabaseManager.staticDatabaseManager.database.execute(
            "SELECT * FROM Users;").fetchall()
        self.assertEqual(users[0], ("000000002", "ADMIN"),
                         "User is incorrect.")
Beispiel #4
0
		newLEDColor = self.mockLEDs.getColor()
		if newLEDColor != self.lastLEDColor:
			self.lastLEDColor = newLEDColor
			self.window.drawRectangle(-310,-40,300,80,"#FFFFFF",newLEDColor)

		# Update the buzzer.
		newBuzzerState = (Time.getCurrentTimestamp() - self.mockBuzzer.lastTime) < 0.1
		if newBuzzerState != self.buzzerOn:
			self.buzzerOn = newBuzzerState
			if self.buzzerOn:
				self.window.drawRectangle(330,-130,60,60,"#FFFFFF","#00FF00")
			else:
				self.window.drawRectangle(330,-130,60,60,"#FFFFFF","#FF0000")

		# Update the display.
		self.window.update()

	"""
	Continuously updates the display.
	"""
	def startUpdateLoop(self):
		while True:
			self.updateDisplay()
			time.sleep(1/60)



if __name__ == '__main__':
	DatabaseManager.setUserAccessType("000000001","ADMIN")
	DatabaseManager.setUserAccessType("000000002","AUTHORIZED")
	Emulator()