|
|
|
|
@ -1,23 +1,55 @@
|
|
|
|
|
import uuid
|
|
|
|
|
|
|
|
|
|
# Classes
|
|
|
|
|
#
|
|
|
|
|
class Manager():
|
|
|
|
|
# Manager class to manage a notiframe session.
|
|
|
|
|
def __init__(self):
|
|
|
|
|
self.devices = {}
|
|
|
|
|
self.devices = []
|
|
|
|
|
self.manager_id = gen_id()
|
|
|
|
|
|
|
|
|
|
def add_device(self): #add parameters for Device class constructor
|
|
|
|
|
self.devices.append(Device())
|
|
|
|
|
|
|
|
|
|
def gen_id(self):
|
|
|
|
|
return uuid.uuid4()
|
|
|
|
|
def remove_device(self, dev_id):
|
|
|
|
|
for dev in self.devices:
|
|
|
|
|
if dev.device_id == dev_id:
|
|
|
|
|
self.devices.remove(dev)
|
|
|
|
|
break
|
|
|
|
|
|
|
|
|
|
class Device():
|
|
|
|
|
# Device class to contain a device's properties, layout and widgets
|
|
|
|
|
def __init__(self):
|
|
|
|
|
self.widgets = []
|
|
|
|
|
self.device_id = gen_id()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Test():
|
|
|
|
|
# Test class to test other classes and their functions.
|
|
|
|
|
def __init__(self):
|
|
|
|
|
#instantiate manager class
|
|
|
|
|
self.manager = Manager()
|
|
|
|
|
self.device = Device()
|
|
|
|
|
|
|
|
|
|
def test_all(self):
|
|
|
|
|
manager_uuid = self.manager_uuid()
|
|
|
|
|
device_uuid = self.device_uuid()
|
|
|
|
|
add_device = self.add_device()
|
|
|
|
|
remove_device = self.remove_device()
|
|
|
|
|
|
|
|
|
|
print("manager id is valid: " + str(manager_uuid))
|
|
|
|
|
print("device id is valid: " + str(device_uuid))
|
|
|
|
|
print("added device: " + str(add_device))
|
|
|
|
|
print("removed device: " + str(remove_device))
|
|
|
|
|
|
|
|
|
|
# Note: Do function wrapper here for tests functions, to say "test_function_name" success/failure
|
|
|
|
|
def manager_uuid(self):
|
|
|
|
|
uuid_test = self.manager.gen_id()
|
|
|
|
|
print(self.is_valid_uuid(uuid_test))
|
|
|
|
|
uuid_test = self.manager.manager_id
|
|
|
|
|
return self.is_valid_uuid(uuid_test)
|
|
|
|
|
|
|
|
|
|
def device_uuid(self):
|
|
|
|
|
uuid_test = self.device.device_id
|
|
|
|
|
return self.is_valid_uuid(uuid_test)
|
|
|
|
|
|
|
|
|
|
# Test if manager class's gen_id function produces a valid uuid
|
|
|
|
|
def is_valid_uuid(self, val):
|
|
|
|
|
@ -26,6 +58,32 @@ class Test():
|
|
|
|
|
return True
|
|
|
|
|
except ValueError:
|
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
|
def add_device(self):
|
|
|
|
|
len1 = len(self.manager.devices)
|
|
|
|
|
self.manager.add_device()
|
|
|
|
|
len2 = len(self.manager.devices)
|
|
|
|
|
if len2 == len1 + 1:
|
|
|
|
|
return True
|
|
|
|
|
else:
|
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
|
def remove_device(self):
|
|
|
|
|
id = self.manager.devices[0].device_id
|
|
|
|
|
len1 = len(self.manager.devices)
|
|
|
|
|
self.manager.remove_device(id)
|
|
|
|
|
len2 = len(self.manager.devices)
|
|
|
|
|
if len2 == len1 - 1:
|
|
|
|
|
return True
|
|
|
|
|
else:
|
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Global Functions
|
|
|
|
|
#
|
|
|
|
|
def gen_id():
|
|
|
|
|
return uuid.uuid4()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
test = Test()
|
|
|
|
|
test.manager_uuid()
|
|
|
|
|
test.test_all()
|
|
|
|
|
|