Пример #1
0
	def deleteRoom(self, buildingName, roomName):
		checkData(locals())

		print "\t\t\t\t\t\t\t\tTODO (" + self.__class__.__name__ + ":" + sys._getframe().f_code.co_name + ")  not yet tested"
		print "\t\t\t\t\t\t\t\tTODO (" + self.__class__.__name__ + ":" + sys._getframe().f_code.co_name + ")  table rules_priority not correctly updated"

		from app.backend.model.room import Room
		room = Room(roomName = roomName,  buildingName = buildingName)
		room.retrieve()

		ruleList = room.getRules()
		triggerList = room.getTriggers()
		actionList = room.getActions()

		for rule in ruleList:
			rule.delete()

		for trigger in triggerList:
			room.deleteTrigger(trigger)

		for action in actionList:
			room.deleteAction(action)

		room.delete()

		return {}
Пример #2
0
	def test0(self):

		from app.backend.commons.database import Database
		from app.backend.model.building import Building
		from app.backend.model.group import Group
		from app.backend.model.room import Room
		from app.backend.model.user import User
		from app.backend.model.rule import Rule

		print "Starting test..."
		print "Cleaning database..."

		database = Database()
		database.open()
		database.executeWriteQuery("TRUNCATE TABLE buildings")
		database.executeWriteQuery("TRUNCATE TABLE groups")
		database.executeWriteQuery("TRUNCATE TABLE rooms")
		database.executeWriteQuery("TRUNCATE TABLE users")
		database.executeWriteQuery("TRUNCATE TABLE users_rooms")
		database.executeWriteQuery("TRUNCATE TABLE rooms_groups")
		database.executeWriteQuery("TRUNCATE TABLE rules")
		database.close()

		print "Testing model..."

		building = Building(buildingName = "CSE", label = "Computer Science", description = "This is a nice place")
		building.store()

		building = Building(buildingName = "CSE", label = "Computer Science", description = "This is a great place")
		building.store()

 		building = Building(buildingName = "CSE")
 		building.retrieve()
 		print building

 		group = Group(buildingName = "CSE", description = "Questo gruppo eheh")
 		group.store()
 		print group

 		group = Group(id=1, buildingName = "CSE")
 		group.retrieve()
 		print group

 		group = Group(id=1, buildingName = "CSE", description = "we ciao ciao")
 		group.store()

 		group = Group(id=1, buildingName = "CSE")
 		group.retrieve()
 		print group

		room = Room(roomName = "200",  buildingName = "CSE", description = "Bella 3333")
		room.store()

		room = Room(roomName = "200",  buildingName = "CSE")
		room.retrieve()
		print room

		print "room.getBuilding() test"
		print room.getBuilding()

		user = User(username = "******", email = "*****@*****.**", password = "******", personName = "Alessandro Nacci", level = 10)
		user.store()

		room.addUser(user)

		print "user.getRooms() test"
		for room in user.getRooms():
			print room

		print "group.addRoom(room) test"
		group.addRoom(room)
		
		print group

		print "User test 1"
		user = User(username = "******")
		user.retrieve()
		print user

		print "User test 2"
		user = User(username = "******", password="******")
		user.retrieve()
		print user

		print "User test 3"
		user = User(uuid = 1)
		user.retrieve()
		print user

		

		rule = Rule(priority = 1, category = "ELECTRICT222", buildingName = "CSE", groupId = 1, roomName = "200", 
				authorUuid = 1, antecedent = "the ligjt is on", consequent = "turn off the light", enabled = 1, deleted = 0)

		rule.store()

		rule = Rule(id = 1)
		rule.retrieve()

		print rule
		print rule.getBuilding()
		print rule.getGroup()
		print rule.getAuthor()

		print "test group.getRules()"
		ruleList = group.getRules()
		for r in ruleList:
			print r

		print "test room.getRules()"
		ruleList = room.getRules()
		for r in ruleList:
			print r

		print "test room.getRules(author)"
		ruleList = room.getRules(author = user, includeGroupsRules = None)
		for r in ruleList:
			print r

		print "test room.getRules(includeGroupsRules)"
		ruleList = room.getRules(includeGroupsRules = True)
		for r in ruleList:
			print r

		print "test user.getCreatedRules()"
		ruleList = user.getCreatedRules()
		for r in ruleList:
			print r

		group.deleteRoom(room)
		room.deleteUser(user)
		rule.delete()
		user.delete()
		group.delete()
		building.delete()
		room.delete()

		user = User(username = "******")
		user.retrieve()