Exemplo n.º 1
0
	def addRoom(self, groupId, roomName, buildingName):
		checkData(locals())

		group = Group(buildingName = buildingName, id = groupId)
		group.retrieve()

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


		if group.crossRoomsValidation:
			print "\t\t\t\t\t\t\t\tTODO (" + self.__class__.__name__ + ":" + sys._getframe().f_code.co_name + ")  This part of the method as not been tested"
			# In this case we have to check that the room doesn't belong to another CrossRoomValidatioGroup
			from app.backend.model.building import Building
			building = Building(buildingName = buildingName)
			building.retrieve()
			crvgList = building.getCrossRoomValidationGroups(roomName = roomName, validationCategories = group.crossRoomsValidationCategories)

			if len(crvgList) > 0:
				raise WrongBuildingGroupRipartitionError("A room can belong to only one cross validation group per category. Room " + str(roomName) + " in already in group " + str(crvgList[0]))

		group.addRoom(room)

		return room.getDict()
Exemplo n.º 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()