Пример #1
0
def login():
	error = None

	if request.method == 'POST':

		username = request.form['username']
		password = request.form['password']

		response = rest.request("/api/users/<username>/login", {'username' : username, 'password' : password})

		if successResponse(response):
			session["logged_in"] = True
			session["sessionKey"] = response["sessionKey"]
			session["userUuid"] = response["userUuid"]
			session["username"] = username
			

			response = rest.request("/api/users/<username>", {'username' : session["username"], 'sessionKey' : session["sessionKey"], 'userUuid' : session["userUuid"]})
			if not successResponse(response): render_template('error.html', error = response['request-errorDescription'])
			session["userLevel"] = response["level"]
			session["userEmail"] = response["email"]
			session["maxRoomPriority"] = response["maxRoomPriority"]
			session["maxGroupPriority"] = response["maxGroupPriority"]

			response = rest.request("/api/users/<username>/buildings", {'username' : session["username"], 'sessionKey' : session["sessionKey"], 'userUuid' : session["userUuid"]})
			if not successResponse(response): render_template('error.html', error = response['request-errorDescription'])
			session["buildings"] = response["buildings"]

			return redirect(url_for('gui.index'))
		else:
			error = response['request-errorDescription']

	currentDatetime = str(time.strftime("%Y-%m-%d %H:%M:%S"))
	return render_template('login.html', error=error, currentDatetime = currentDatetime)	
Пример #2
0
def test_create(testname):
    status, headers, data = request('POST', BASE_URL + testname)
    assert status == 201
    data = json.loads(data)
    assert 'object' in data
    assert data['object'] == testname
    return True
Пример #3
0
def test_action_addattr(testname):
    status, headers, data = request('GET', BASE_URL + testname + '/addattr?key=testkey&value=testvalue')
    assert status == 200
    data = json.loads(data)
    assert type(data) == dict
    assert data['attrs'] == [{'key': 'testkey', 'value': 'testvalue', 'subkey': None, 'number': None, 'datatype': 'string'}]
    return True
Пример #4
0
def deleteGroup(buildingName = None, groupId = None, ruleId = None):

	if not loggedIn():	return redirect(url_for('gui.login'))


	if int(session["userLevel"]) < 100:
		return render_template('error.html', error = "You cannot enter this page.")


	response = rest.request("/api/users/<username>/buildings/<buildingName>/groups/<groupId>/delete", {
				'username' : session["username"],
				'buildingName' : buildingName,
				'groupId' : groupId,
				'ruleId' : ruleId,
				'sessionKey' : session["sessionKey"], 
				'userUuid' : session["userUuid"]
				})

	if not successResponse(response):
		return render_template('error.html', error = response['request-errorDescription'])

	rule = response


	return redirect(url_for('gui.groups', buildingName = buildingName))
Пример #5
0
def test_action_show(testname):
    status, headers, data = request('GET', BASE_URL + testname + '/show')
    assert status == 200
    data = json.loads(data)
    for field in ('object', 'attrs', 'contents', 'parents', 'actions'):
        assert field in data.keys()
    return True
Пример #6
0
def test_types_delegate():
    status, headers, data = request('GET', BASE_URL + '/server')
    assert status == 200
    data = json.loads(data)
    assert type(data) == list
    if len(data) > 0:
        assert type(data[0]) == str
    return True
Пример #7
0
def start():

    global sessionKey
    global userUuid
    global username
    global password

    response = rest.request("/api/test", {"username": username, "password": password})
Пример #8
0
def groupDetail(buildingName = None, groupId = None):

	if not loggedIn():	return redirect(url_for('gui.login'))


	if int(session["userLevel"]) < 100:
		return render_template('error.html', error = "You cannot enter this page.")

	
	response = rest.request("/api/users/<username>/buildings/<buildingName>/groups/<groupId>", {'groupId' : groupId, 'username' : session["username"], 'buildingName' : buildingName, 'sessionKey' : session["sessionKey"], 'userUuid' : session["userUuid"]})
	if not successResponse(response): return render_template('error.html', error = response['request-errorDescription'])
	groupInfo = response

	response = rest.request("/api/users/<username>/buildings/<buildingName>/groups/<groupId>/rooms", {'groupId' : groupId, 'username' : session["username"], 'buildingName' : buildingName, 'sessionKey' : session["sessionKey"], 'userUuid' : session["userUuid"]})
	if not successResponse(response): return render_template('error.html', error = response['request-errorDescription'])
	rooms = response["rooms"]
	
	return render_template('groupInfo.html', groupInfo = groupInfo, rooms = rooms)	
Пример #9
0
def login():

	global sessionKey
	global userUuid
	global username
	global password

	response = rest.request("/api/users/<username>/login", {'username' : username, 'password' : password})
	sessionKey = response["sessionKey"]
	userUuid = response["userUuid"]
Пример #10
0
def getRuleConsequentActionInfo(ruleConsequent):
	global sessionKey
	global userUuid

	response = rest.request("/api/tools/actions/translate", {
			'sessionKey' : sessionKey,
			'userUuid' : userUuid,
			'consequent' : ruleConsequent
			})

	return response["action"]
Пример #11
0
def getRuleAntecedentTriggerInfo(ruleAntecedent):
	global sessionKey
	global userUuid

	response = rest.request("/api/tools/triggers/translate", {
			'sessionKey' : sessionKey,
			'userUuid' : userUuid,
			'antecedent' : ruleAntecedent
			})

	return response["triggers"]
Пример #12
0
def login():
	
	global brules_username
	global brules_userUuid
	global brules_password
	global brules_sessionKey

	response = rest.request("/api/users/<username>/login", {'username' : brules_username, 'password' : brules_password})
	brules_sessionKey = response["sessionKey"]
	brules_userUuid = response["userUuid"]

	if response['request-error']: logerror(response)
Пример #13
0
def buildingDetail(buildingName = None):

	if not loggedIn():	return redirect(url_for('gui.login'))

	if int(session["userLevel"]) < 100:
		return redirect(url_for('gui.rooms', buildingName = buildingName))
		
	response = rest.request("/api/users/<username>/buildings/<buildingName>", {'username' : session["username"], 'buildingName' : buildingName, 'sessionKey' : session["sessionKey"], 'userUuid' : session["userUuid"]})

	if successResponse(response):
		return render_template('buildingInfo.html', buildingInfo = response)	
	else:
		return render_template('error.html', error = response['request-errorDescription'])
Пример #14
0
def buildings():

	if not loggedIn():	return redirect(url_for('gui.login'))
		
	response = rest.request("/api/users/<username>/buildings", {'username' : session["username"], 'sessionKey' : session["sessionKey"], 'userUuid' : session["userUuid"]})

	if not successResponse(response):
		return render_template('error.html', error = response['request-errorDescription'])

	if "buildings" not in response.keys():
		return render_template('error.html', error = response['request-errorDescription'])		

	if len(response["buildings"]) == 1:
		buildingName = response["buildings"][0]["buildingName"]
		return redirect(url_for('gui.buildingDetail', buildingName = buildingName))		

	return render_template('buildings.html', buildings = response["buildings"])	
Пример #15
0
def cleanRoom():

	response = rest.request("/api/users/<username>/buildings/<buildingName>/rooms/<roomName>/rules", 
			{
			'username' : brules_username,
			'buildingName' : brules_buildingName,
			'roomName' : brules_roomName,
			'sessionKey' : brules_sessionKey, 
			'userUuid' : brules_userUuid,
			'filterByAuthor' : False,
			'includeGroupsRules' : True,
			'orderByPriority' : False,
			'categoriesFilter' : None
			})

	if response['request-error']: logerror(response)

	for rule in response["rules"]:
		deleteRule(rule["id"])
Пример #16
0
def deleteRule(ruleId):

	global brules_username
	global brules_buildingName
	global brules_userUuid
	global brules_sessionKey
	global brules_roomName


	response = rest.request("/api/users/<username>/buildings/<buildingName>/rooms/<roomName>/rules/<ruleId>/delete", {
			'username' : brules_username,
			'buildingName' : brules_buildingName,
			'roomName' : brules_roomName,
			'ruleId' : ruleId,
			'sessionKey' : brules_sessionKey, 
			'userUuid' : brules_userUuid
			})

	if response['request-error']: logerror(response)
Пример #17
0
def register(source = None):
	error = None

	if request.method == 'POST':

		username = request.form['username']
		password = request.form['password']
		personName = request.form['personName']
		email = request.form['email']

		response = rest.request("/api/users/<username>/register", {'username' : username, 'password' : password, 'personName' : personName, 'email' : email})

		if successResponse(response):

			userUuid = response["uuid"]

			return render_template('registrationOk.html', userUuid=userUuid)	
		else:
			error = response['request-errorDescription']

	return render_template('registerUser.html', error=error, source = source)	
Пример #18
0
def logout():
	
	if loggedIn():

		response = rest.request("/api/users/<username>/logout", {'username' : session["username"]})

		del session["logged_in"]
		del session["sessionKey"]
		if "alreadyLoggedIn" in session.keys(): 
			del session["alreadyLoggedIn"]


		if successResponse(response):
			del session["userUuid"]
			del session["username"]
			del session["maxRoomPriority"]
			del session["maxGroupPriority"]
		else:
			return render_template('error.html', error = response['request-errorDescription'])

	return render_template('home.html')	
Пример #19
0
def storeAndCheckRule(ruleBody, priority):

	global brules_username
	global brules_buildingName
	global brules_userUuid
	global brules_sessionKey
	global brules_roomName

	response = rest.request("/api/users/<username>/buildings/<buildingName>/rooms/<roomName>/rules/add", {
			'username' : brules_username,
			'buildingName' : brules_buildingName,
			'roomName' : brules_roomName,
			'priority' : priority, 
			'ruleBody' : ruleBody, 
			'sessionKey' : brules_sessionKey, 
			'userUuid' : brules_userUuid
			})

	if response['request-error']: logerror(response)

	return response
Пример #20
0
def deleteRoomRule(buildingName = None, roomName = None, ruleId = None):

	if not loggedIn():	return redirect(url_for('gui.login'))


	response = rest.request("/api/users/<username>/buildings/<buildingName>/rooms/<roomName>/rules/<ruleId>/delete", {
				'username' : session["username"],
				'buildingName' : buildingName,
				'roomName' : roomName,
				'ruleId' : ruleId,
				'sessionKey' : session["sessionKey"], 
				'userUuid' : session["userUuid"]
				})

	if not successResponse(response):
		return render_template('error.html', error = response['request-errorDescription'])

	rule = response


	#return redirect(url_for('gui.rooms', buildingName = buildingName))
	return redirect('/buildings/' + buildingName + '/rooms' + '#roomMenu_' + roomName)
Пример #21
0
def sendFeedback():

	if not loggedIn():	return redirect(url_for('gui.login'))

	if request.method == 'POST':

		alternativeContact = request.form['alternativeContact']
		score = request.form['score']
		message = request.form['message']

		response = rest.request("/api/users/<username>/feedbacks/store", {
					'sessionKey' : session["sessionKey"], 
					'userUuid' : session["userUuid"],
					'alternativeContact' : alternativeContact,
					'score' : score,
					'message' : message
					})

		if not successResponse(response):
			return render_template('error.html', error = response['request-errorDescription'])

		flash("Thanks for your feedback!")

	return redirect(url_for('gui.index'))
Пример #22
0
def logout():

	global brules_username
	response = rest.request("/api/users/<username>/logout", {'username' : brules_username})

	if response['request-error']: logerror(response)
Пример #23
0
rulesToAdd.append({'priority' : 0,  'ruleBody' : "if today is Saturday then turn off the audio system", 'roomCategory' : ["MEETING", "CONFERENCE"]})
rulesToAdd.append({'priority' : 0,  'ruleBody' : "if today is Saturday then turn off the exhaust fan", 'roomCategory' : ["KITCHEN"]})
rulesToAdd.append({'priority' : 0,  'ruleBody' : "if today is Saturday then turn off the fume hoods", 'roomCategory' : ["LABORATORY"]})
rulesToAdd.append({'priority' : 1,  'ruleBody' : "if today is Sunday then turn off the room light", 'roomCategory' : ["ALL"]})
rulesToAdd.append({'priority' : 1,  'ruleBody' : "if today is Sunday then turn off the coffee machine", 'roomCategory' : ["KITCHEN"]})
rulesToAdd.append({'priority' : 1,  'ruleBody' : "if today is Sunday then turn off the printer", 'roomCategory' : ["OFFICE"]})
rulesToAdd.append({'priority' : 1,  'ruleBody' : "if today is Sunday then put to sleep my computer", 'roomCategory' : ["OFFICE"]})
rulesToAdd.append({'priority' : 1,  'ruleBody' : "if today is Sunday then turn off my desk light", 'roomCategory' : ["OFFICE"]})
rulesToAdd.append({'priority' : 1,  'ruleBody' : "if today is Sunday then turn off display monitors", 'roomCategory' : ["OFFICE"]})
rulesToAdd.append({'priority' : 1,  'ruleBody' : "if today is Sunday then turn off the projector", 'roomCategory' : ["MEETING", "CONFERENCE"]})
rulesToAdd.append({'priority' : 1,  'ruleBody' : "if today is Sunday then turn off the audio system", 'roomCategory' : ["MEETING", "CONFERENCE"]})
rulesToAdd.append({'priority' : 1,  'ruleBody' : "if today is Sunday then turn off the exhaust fan", 'roomCategory' : ["KITCHEN"]})
rulesToAdd.append({'priority' : 1,  'ruleBody' : "if today is Sunday then turn off the fume hoods", 'roomCategory' : ["LABORATORY"]})

# login ##########################################
response = rest.request("/api/users/<username>/login", {'username' : username, 'password' : password})
sessionKey = response["sessionKey"]
userUuid = response["userUuid"]


# getting room list ##########################################
response = rest.request("/api/users/<username>/buildings/<buildingName>/rooms", {
			'username' : username,
			'buildingName' : buildingName,
			'sessionKey' : sessionKey,
			'userUuid' : userUuid
			})

roomList = response["rooms"]

Пример #24
0
def test_default_delegate():
    status, headers, data = request('GET', BASE_URL + '/')
    assert status == 200
    assert type(json.loads(data)) == list
    return True
Пример #25
0
def test_delete(testname):
    status, headers, data = request('DELETE', BASE_URL + testname)
    assert status in (200, 202, 204)
    return True
Пример #26
0
def test_action_remove(testname):
    status, headers, data = request('GET', BASE_URL + testname + '/remove?object=/pool/api_test_child')
    assert status == 200
    data = json.loads(data)
    assert data['contents'] == []
    return True
Пример #27
0
def editRoomRule(buildingName = None, roomName = None, ruleId = None, groupId = None):

	if not loggedIn():	return redirect(url_for('gui.login'))

	if request.method == 'POST':

		ruleBody = request.form['ruleBody']
		priority = request.form['priority']

	
		response = rest.request("/api/users/<username>/buildings/<buildingName>/rooms/<roomName>/rules/<ruleId>/edit", {
					'username' : session["username"],
					'buildingName' : buildingName,
					'roomName' : roomName,
					'groupId' : groupId,
					'ruleId' : ruleId,
					'priority' : priority, 
					'ruleBody' : ruleBody, 
					'sessionKey' : session["sessionKey"], 
					'userUuid' : session["userUuid"]
					})
		
		
		if successResponse(response):
			flash("The rule has been saved correctly!")
			#return redirect(url_for('gui.rooms', buildingName = buildingName))
			return redirect('/buildings/' + buildingName + '/rooms' + '#roomMenu_' + roomName)
		else:

			if response["request-errorName"] == "RuleValidationError":
				return redirect(url_for('gui.editRoomRule', buildingName = buildingName, roomName = roomName, ruleId = ruleId, ruleBody = ruleBody, priority = priority, conflictFound = True))
			
			return render_template('ruleForm.html', error = response['request-errorDescription'], insertionForRoom = True)

	else:


		conflictingRuleList = []
		conflictFound = request.args['conflictFound'] if 'conflictFound' in request.args.keys() else False
		
		if bool(conflictFound):

			ruleBody = request.args['ruleBody'] if 'ruleBody' in request.args.keys() else None
			priority = request.args['priority'] if 'priority' in request.args.keys() else None

			response = rest.request("/api/users/<username>/buildings/<buildingName>/rooms/<roomName>/conflictingRules", 
				{
				'username' : session["username"],
				'buildingName' : buildingName, 
				'roomName' : roomName,
				'sessionKey' : session["sessionKey"],
				'userUuid' : session["userUuid"],
				'ruleBody' : ruleBody
				})

			if successResponse(response):
				conflictingRuleList = response["conflictingRules"]
			else:
				return render_template('error.html', error = response['request-errorDescription'])


		response = rest.request("/api/users/<username>/buildings/<buildingName>/rooms/<roomName>/rules/<ruleId>", {
					'username' : session["username"],
					'buildingName' : buildingName,
					'roomName' : roomName,
					'ruleId' : ruleId,
					'sessionKey' : session["sessionKey"], 
					'userUuid' : session["userUuid"]
					})

		if not successResponse(response):
			return render_template('ruleForm.html', error = response['request-errorDescription'], insertionForRoom = True)

		rule = response

		response = rest.request("/api/users/<username>/buildings/<buildingName>/rooms/<roomName>/triggers", 
			{
			'username' : session["username"],
			'buildingName' : buildingName, 
			'roomName' : roomName,
			'sessionKey' : session["sessionKey"],
			'userUuid' : session["userUuid"]
			})

		if successResponse(response):
			triggerList = response["triggers"]
		else:
			return render_template('error.html', error = response['request-errorDescription'])



		response = rest.request("/api/users/<username>/buildings/<buildingName>/rooms/<roomName>/actions", 
			{
			'username' : session["username"],
			'buildingName' : buildingName, 
			'roomName' : roomName,
			'sessionKey' : session["sessionKey"],
			'userUuid' : session["userUuid"]
			})

		if successResponse(response):
			actionList = response["actions"]
		else:
			return render_template('error.html', error = response['request-errorDescription'])


		availableTriggers = []
		for trigger in triggerList:
			availableTriggers.append( trigger["ruleAntecedent"].split("@val")[0].strip() )


		availableActions = []
		for action in actionList:
			availableActions.append( action["ruleConsequent"].split("@val")[0].strip() )

		availableTriggers = sorted(availableTriggers)
		availableActions = sorted(availableActions)

		return render_template('ruleForm.html', rule = rule, insertionForRoom = True, availableTriggers = availableTriggers, availableActions = availableActions, conflictingRuleList = conflictingRuleList, conflictFound = conflictFound, roomName = roomName, buildingName = buildingName)
Пример #28
0
	if roomName == 2144:	return "STORAGE"
	if roomName == 3208:	return "CONFERENCE"
	if roomName == 3208:	return "LOBBY"
	if roomName == 2140:	return "MEETING"
	if roomName == 2154:	return "MEETING"
	if roomName == 3113:	return "LABORATORY"
	
	return "OFFICE"


username = "******"
password = "******"
buildingName = "CSE"

# login ##########################################
response = rest.request("/api/users/<username>/login", {'username' : username, 'password' : password})
sessionKey = response["sessionKey"]
userUuid = response["userUuid"]


# starting simulation ##########################################
response = rest.request("/api/test", {
			'username' : username,
			'buildingName' : buildingName,
			'sessionKey' : sessionKey,
			'userUuid' : userUuid
			})

roomList = response["rooms"]

response = rest.request("/api/users/<username>/logout", {'username' : username})
Пример #29
0
from rest import request

BASE_URL = 'http://localhost:9999'

status, headers, data = request('DELETE', BASE_URL + '/pool/api_test_pool')
print 'DELETE /pool/api_test_pool (%i)' % status
status, headers, data = request('DELETE', BASE_URL + '/pool/api_test_child')
print 'DELETE /pool/api_test_child (%i)' % status
Пример #30
0
def test_action_delattr(testname):
    status, headers, data = request('GET', BASE_URL + testname + '/delattr?key=testkey')
    assert status == 200
    data = json.loads(data)
    assert len(data['attrs']) == 0
    return True