parent
1fca6884ea
commit
59730b4cec
@ -1,88 +0,0 @@
|
||||
import uuid
|
||||
|
||||
# Classes
|
||||
#
|
||||
class Manager():
|
||||
# Manager class to manage a notiframe session.
|
||||
def __init__(self):
|
||||
self.devices = []
|
||||
self.manager_id = gen_id()
|
||||
|
||||
def add_device(self, name): #add parameters for Device class constructor
|
||||
self.devices.append(Device(name))
|
||||
|
||||
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, name):
|
||||
self.name = name
|
||||
self.device_id = gen_id()
|
||||
self.widgets = []
|
||||
|
||||
class Test():
|
||||
# Test class to test other classes and their functions.
|
||||
def __init__(self):
|
||||
#instantiate manager class
|
||||
self.manager = Manager()
|
||||
|
||||
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.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):
|
||||
try:
|
||||
uuid.UUID(str(val))
|
||||
return True
|
||||
except ValueError:
|
||||
return False
|
||||
|
||||
def add_device(self):
|
||||
len1 = len(self.manager.devices)
|
||||
self.manager.add_device("test")
|
||||
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.test_all()
|
||||
Loading…
Reference in new issue