def test_reload_devices(self): environment = yield self._logicLayer.add_environment(name="Test Environment", description="A test Environment", status="active") environment2 = yield self._logicLayer.add_environment(name="Test Environment2", description="A test Environment2", status="inactive") device = yield self._logicLayer.add_device(environmentId = environment.cid, name="Test Device",description = "A test description") device2 = yield self._logicLayer.add_device(environmentId = environment.cid, name="Test Device Two",description = "A test description too") device3 = yield self._logicLayer.add_device(environmentId = environment2.cid, name="Test Device Three") self._persistenceLayer.tearDown() self._persistenceLayer = None self._persistenceLayer = PersistenceLayer(pathManager = self._path_manager) self._logicLayer = LogicLayer(self._persistenceLayer) yield self._logicLayer.setup() lExpDevicesEnv1 = [device,device2] lObsDevicesEnv1 = yield self._logicLayer.get_devices(environmentId = environment.cid) lExpDevicesEnv1 = sorted(lExpDevicesEnv1,key=lambda device: device.name) lObsDevicesEnv1 = sorted(lObsDevicesEnv1,key=lambda device: device.name) self.assertEquals(lObsDevicesEnv1, lExpDevicesEnv1) lExpDevicesEnv2 = [device3] lObsDevicesEnv2 = yield self._logicLayer.get_devices(environmentId = environment2.cid) lExpDevicesEnv2 = sorted(lExpDevicesEnv2,key=lambda device: device.name) lObsDevicesEnv2 = sorted(lObsDevicesEnv2,key=lambda device: device.name) self.assertEquals(lObsDevicesEnv2, lExpDevicesEnv2) yield self._persistenceLayer.delete_environments([environment,environment2])
def setUp(self): self._path_manager = PathManager() self._path_manager.dataPath = "." self._persistenceLayer = PersistenceLayer(pathManager = self._path_manager) self.environmentManager=EnvironmentManager(self._persistenceLayer) #yield self._persistenceLayer.setup() yield self.environmentManager.setup()
def test_reload_tasks(self): environment = yield self._logicLayer.add_environment(name="Test Environment", description="A test Environment", status="active") environment2 = yield self._logicLayer.add_environment(name="Test Environment2", description="A test Environment2", status="inactive") task = yield self._logicLayer.add_task(environmentId = environment.cid, name="Test Task",description = "A test description") task2 = yield self._logicLayer.add_task(environmentId = environment.cid, name="Test Task Two",description = "A test description too") task3 = yield self._logicLayer.add_task(environmentId = environment2.cid, name="Test Task Three") self._persistenceLayer.tearDown() self._persistenceLayer = None self._persistenceLayer = PersistenceLayer(pathManager = self._path_manager) self._logicLayer = LogicLayer(self._persistenceLayer) yield self._logicLayer.setup() lExpTasksEnv1 = [task,task2] lObsTasksEnv1 = yield self._logicLayer.get_tasks(environmentId = environment.cid) lExpTasksEnv1 = sorted(lExpTasksEnv1,key=lambda task: task.name) lObsTasksEnv1 = sorted(lObsTasksEnv1,key=lambda task: task.name) self.assertEquals(lObsTasksEnv1, lExpTasksEnv1) lExpTasksEnv2 = [task3] lObsTasksEnv2 = yield self._logicLayer.get_tasks(environmentId = environment2.cid) lExpTasksEnv2 = sorted(lExpTasksEnv2,key=lambda task: task.name) lObsTasksEnv2 = sorted(lObsTasksEnv2,key=lambda task: task.name) self.assertEquals(lObsTasksEnv2, lExpTasksEnv2) yield self._persistenceLayer.delete_environments([environment,environment2])
def setUp(self): self._path_manager = PathManager() self._path_manager.dataPath = "." self._persistenceLayer = PersistenceLayer( pathManager=self._path_manager) self.deviceManager = DeviceManager(self._persistenceLayer) #yield self._persistenceLayer.setup() yield self.deviceManagers.setup()
class EnvironmentTest(unittest.TestCase): @defer.inlineCallbacks def setUp(self): self._path_manager = PathManager() self._path_manager.dataPath = "." self._persistenceLayer = PersistenceLayer(pathManager = self._path_manager) self.environmentManager=EnvironmentManager(self._persistenceLayer) #yield self._persistenceLayer.setup() yield self.environmentManager.setup() def tearDown(self): self.environmentManager.teardown() self._persistenceLayer.tearDown() if os.path.exists("pollapli.db"): os.remove("pollapli.db") @defer.inlineCallbacks def test_add_environment(self): exp = Environment(name="Test Environment", description="A test Environment", status="active") obs = yield self.environmentManager.add_environment(name="Test Environment", description="A test Environment", status="active") self.assertEquals(obs.name, exp.name) self.assertEquals(obs.description,exp.description) self.assertEquals(obs.status,exp.status) @defer.inlineCallbacks def test_get_environmment_byName(self): yield self.environmentManager.add_environment(name="Oh my an Environment", description="A test Environment", status="active") environment2 = yield self.environmentManager.add_environment(name="Test Environment", description="A test Environment", status="active") exp = environment2 obs = yield self.environmentManager.get_environments({"name":["Test Environment"]}) obs = obs[0] self.assertEquals(obs,exp) @defer.inlineCallbacks def test_remove_environment(self): environment = yield self.environmentManager.add_environment(name="Test Environment", description="A test Environment", status="active") yield self.environmentManager.remove_environment(id = environment.cid) self.assertRaises(EnvironmentNotFound,self.environmentManager.get_environment,id = environment.cid) @defer.inlineCallbacks def test_clear_environments(self): yield self.environmentManager.add_environment(name="Test Environment", description="A test Environment", status="active") yield self.environmentManager.add_environment(name="Test Environment2", description="A test Environment", status="active") yield self.environmentManager.clear_environments() obs = yield self.environmentManager.get_environments() exp = [] self.assertEquals(obs,exp)
def test_reload_complete(self): environment = yield self._logicLayer.add_environment(name="Test Environment", description="A test Environment", status="active") environment2 = yield self._logicLayer.add_environment(name="Test Environment2", description="A test Environment2", status="inactive") task = yield self._logicLayer.add_task(environmentId = environment.cid, name="Test Task",description = "A test description") task2 = yield self._logicLayer.add_task(environmentId = environment.cid, name="Test Task Two",description = "A test description too") task3 = yield self._logicLayer.add_task(environmentId = environment2.cid, name="Test Task Three") task4 = yield self._logicLayer.add_task(environmentId = environment2.cid, name="Test Task Four") device = yield self._logicLayer.add_device(environmentId = environment.cid, name="Test Device", description = "A test description", type="Test") device2 = yield self._logicLayer.add_device(environmentId = environment2.cid, name="Test Device Two", description = "Another test description", type="Test") device3 = yield self._logicLayer.add_device(environmentId = environment2.cid, name="Test Device Three", type="Test") """destroy current layer, restart and reload""" self._persistenceLayer.tearDown() self._persistenceLayer = None self._persistenceLayer = PersistenceLayer(pathManager = self._path_manager) self._logicLayer = LogicLayer(self._persistenceLayer) yield self._logicLayer.setup() lExpEnvs = [environment,environment2] lObsEnvs = yield self._logicLayer.get_environments() lObsEnvs = sorted(lObsEnvs,key=lambda environment: environment.name) lExpEnvs = sorted(lExpEnvs,key=lambda environment: environment.name) self.assertEquals(lObsEnvs,lExpEnvs) lExpTasksEnv1 = [task,task2] lObsTasksEnv1 = yield self._logicLayer.get_tasks(environmentId = environment.cid) lExpTasksEnv1 = sorted(lExpTasksEnv1,key=lambda task: task.name) lObsTasksEnv1 = sorted(lObsTasksEnv1,key=lambda task: task.name) self.assertEquals(lObsTasksEnv1, lExpTasksEnv1) lExpTasksEnv2 = [task3,task4] lObsTasksEnv2 = yield self._logicLayer.get_tasks(environmentId = environment2.cid) lExpTasksEnv2 = sorted(lExpTasksEnv2,key=lambda task: task.name) lObsTasksEnv2 = sorted(lObsTasksEnv2,key=lambda task: task.name) self.assertEquals(lObsTasksEnv2, lExpTasksEnv2) lExpDevicesEnv1 = [device] lObsDevicesEnv1 = yield self._logicLayer.get_devices(environmentId = environment.cid) lExpDevicesEnv1 = sorted(lExpDevicesEnv1,key=lambda device: device.name) lObsDevicesEnv1 = sorted(lObsDevicesEnv1,key=lambda device: device.name) self.assertEquals(lObsDevicesEnv1, lExpDevicesEnv1) lExpDevicesEnv2 = [device2,device3] lObsDevicesEnv2 = yield self._logicLayer.get_devices(environmentId = environment2.cid) lExpDevicesEnv2 = sorted(lExpDevicesEnv2,key=lambda device: device.name) lObsDevicesEnv2 = sorted(lObsDevicesEnv2,key=lambda device: device.name) self.assertEquals(lObsDevicesEnv2, lExpDevicesEnv2) yield self._persistenceLayer.delete_environments([environment,environment2])
def setUp(self): self._path_manager = PathManager() if not os.path.exists("tmp"): os.makedirs("tmp") if not os.path.exists("addons"): os.makedirs("addons") self._path_manager._addon_path = "addons" self._path_manager.tmpPath = "tmp" self._persistenceLayer = PersistenceLayer() self._packageManager = PackageManager(self._persistenceLayer, self._path_manager) yield self._packageManager.setup()
class Test_device_manager(unittest.TestCase): @defer.inlineCallbacks def setUp(self): self._path_manager = PathManager() self._path_manager.dataPath = "." self._persistenceLayer = PersistenceLayer( pathManager=self._path_manager) self.deviceManager = DeviceManager(self._persistenceLayer) #yield self._persistenceLayer.setup() yield self.deviceManagers.setup() def tearDown(self): self.deviceManager.teardown() self._persistenceLayer.tearDown() if os.path.exists("pollapli.db"): os.remove("pollapli.db")
def setUp(self): self._path_manager = PathManager() self._path_manager.dataPath = "." self._persistenceLayer = PersistenceLayer(pathManager = self._path_manager) self.deviceManager=DeviceManager(self._persistenceLayer) #yield self._persistenceLayer.setup() yield self.deviceManagers.setup()
class Test_device_manager(unittest.TestCase): @defer.inlineCallbacks def setUp(self): self._path_manager = PathManager() self._path_manager.dataPath = "." self._persistenceLayer = PersistenceLayer(pathManager = self._path_manager) self.deviceManager=DeviceManager(self._persistenceLayer) #yield self._persistenceLayer.setup() yield self.deviceManagers.setup() def tearDown(self): self.deviceManager.teardown() self._persistenceLayer.tearDown() if os.path.exists("pollapli.db"): os.remove("pollapli.db")
def test_reload_environments(self): environment = yield self._logicLayer.add_environment(name="Test Environment", description="A test Environment", status="active") environment2 = yield self._logicLayer.add_environment(name="Test Environment2", description="A test Environment2", status="inactive") self._persistenceLayer.tearDown() self._persistenceLayer = None self._persistenceLayer = PersistenceLayer(pathManager = self._path_manager) self._logicLayer = LogicLayer(self._persistenceLayer) yield self._logicLayer.setup() lExpEnvs = [environment,environment2] lObsEnvs = yield self._logicLayer.get_environments() lObsEnvs = sorted(lObsEnvs,key=lambda environment: environment.name) lExpEnvs = sorted(lExpEnvs,key=lambda environment: environment.name) self.assertEquals(lObsEnvs,lExpEnvs) yield self._persistenceLayer.delete_environments([environment,environment2])
def setUp(self): self._path_manager = PathManager() if not os.path.exists("tmp"): os.makedirs("tmp") if not os.path.exists("addons"): os.makedirs("addons") self._path_manager._addon_path = "addons" self._path_manager.tmpPath = "tmp" self._persistenceLayer = PersistenceLayer() self._packageManager = PackageManager(self._persistenceLayer,self._path_manager) yield self._packageManager.setup()
class PersistenceLayerTest(unittest.TestCase): def setUp(self): self._path_manager = PathManager() self._path_manager.dataPath = "." self._persistenceLayer = PersistenceLayer(pathManager = self._path_manager) def tearDown(self): self._persistenceLayer.tearDown() if os.path.exists('pollapli.db'): os.remove('pollapli.db') @defer.inlineCallbacks def test_save_and_load_environment(self): input = Environment(name="TestEnvironment",description = "A test description") yield self._persistenceLayer.save_environment(input) exp = input obs = yield self._persistenceLayer.load_environment(id = input.cid) self.assertEquals(obs,exp) yield self._persistenceLayer.delete_environment(input) @defer.inlineCallbacks def test_save_and_load_environments(self): input =[] input.append(Environment(name="TestEnvironmentOne",description = "A test description")) input.append(Environment(name="TestEnvironmentTwo",description = "Another test description",status="active")) yield self._persistenceLayer.save_environments(input) exp = input obs = yield self._persistenceLayer.load_environments() self.assertEquals(obs,exp) yield self._persistenceLayer.delete_environment(input[0]) yield self._persistenceLayer.delete_environment(input[1]) @defer.inlineCallbacks def test_update_environment(self): input = Environment(name="TestEnvironment",description = "A test description") yield self._persistenceLayer.save_environment(input) input.name = "TestEnvironmentModified" yield self._persistenceLayer.save_environment(input) exp = input obs = yield self._persistenceLayer.load_environment(id = input.cid) self.assertEquals(obs,exp) yield self._persistenceLayer.delete_environment(input) @defer.inlineCallbacks def test_delete_environment(self): input = Environment(name="TestEnvironment",description = "A test description") yield self._persistenceLayer.save_environment(input) exp = input obs = yield self._persistenceLayer.load_environment(id = input.cid) self.assertEquals(obs,exp) yield self._persistenceLayer.delete_environment(input) obs = self._persistenceLayer.load_environment(id = input.cid) self.assertFailure(obs ,EnvironmentNotFound ) def test_delete_environment_exception(self): input = Environment(name="TestEnvironment",description = "A test description") obs = self._persistenceLayer.delete_environment(input) self.assertFailure(obs ,EnvironmentNotFound ) @defer.inlineCallbacks def test_save_and_load_device(self): input = Device(name="TestDevice",description = "A test description") yield self._persistenceLayer.save_device(input) exp = input obs = yield self._persistenceLayer.load_device(id = input.cid) self.assertEquals(obs,exp) @defer.inlineCallbacks def test_save_and_load_devices(self): input =[] input.append(Device(name="TestDeviceOne",description = "A test description")) input.append(Device(name="TestDeviceTwo",description = "Another test description",status="active")) yield self._persistenceLayer.save_devices(input) exp = input obs = yield self._persistenceLayer.load_devices() self.assertEquals(obs,exp) @defer.inlineCallbacks def test_save_and_load_devices_one_by_one(self): input =[] input.append(Device(name="TestDeviceOne",description = "A test description")) input.append(Device(name="TestDeviceTwo",description = "Another test description",status="active")) yield self._persistenceLayer.save_device(input[0]) yield self._persistenceLayer.save_device(input[1]) exp = input obs = yield self._persistenceLayer.load_devices() self.assertEquals(obs,exp) @defer.inlineCallbacks def test_save_and_load_devices_of_environment(self): parentEnvironement = Environment(name="TestEnvironment",description = "A test description") device1 = Device(name="TestDeviceOne",description = "A test description") device1._parent = parentEnvironement device2 = Device(name="TestDeviceTwo",description = "Another test description",status="active") device2._parent = parentEnvironement input =[device1,device2] parentEnvironement2 = Environment(name="TestEnvironment2",description = "A test description") device3 = Device(name="TestDeviceThree",description = "A test description") device3._parent = parentEnvironement2 yield self._persistenceLayer.save_devices(input) yield self._persistenceLayer.save_device(device3) exp = input obs = yield self._persistenceLayer.load_devices(parentEnvironement.cid) self.assertEquals(obs,exp) exp = [device3] obs = yield self._persistenceLayer.load_devices(parentEnvironement2.cid) self.assertEquals(obs,exp) @defer.inlineCallbacks def test_update_device(self): input = Device(name="TestDevice",description = "A test description") yield self._persistenceLayer.save_device(input) input.name = "TestDeviceModified" yield self._persistenceLayer.save_device(input) exp = input obs = yield self._persistenceLayer.load_device(id = input.cid) self.assertEquals(obs,exp) @defer.inlineCallbacks def test_delete_device(self): input = Device(name="TestDevice",description = "A test description") yield self._persistenceLayer.save_device(input) exp = input obs = yield self._persistenceLayer.load_device(id = input.cid) self.assertEquals(obs,exp) yield self._persistenceLayer.delete_device(input) obs = self._persistenceLayer.load_device(id = input.cid) self.assertFailure(obs ,DeviceNotFound ) def test_delete_device_exception(self): input = Device(name="TestDevice",description = "A test description") obs = self._persistenceLayer.delete_device(input) self.assertFailure(obs ,DeviceNotFound ) """ #################################################################################### The following are the Task related tests """ @defer.inlineCallbacks def test_save_and_load_task(self): input = Task(name="TestTask",description = "A test description") yield self._persistenceLayer.save_task(input) exp = input obs = yield self._persistenceLayer.load_task(id = input.cid) self.assertEquals(obs,exp) @defer.inlineCallbacks def test_save_and_load_tasks(self): input =[] input.append(Task(name="TestTaskOne",description = "A test description")) input.append(Task(name="TestTaskTwo",description = "Another test description",status="active")) yield self._persistenceLayer.save_tasks(input) exp = input obs = yield self._persistenceLayer.load_tasks() self.assertEquals(obs,exp) @defer.inlineCallbacks def test_save_and_load_tasks_one_by_one(self): input =[] input.append(Task(name="TestTaskOne",description = "A test description")) input.append(Task(name="TestTaskTwo",description = "Another test description",status="active")) yield self._persistenceLayer.save_task(input[0]) yield self._persistenceLayer.save_task(input[1]) exp = input obs = yield self._persistenceLayer.load_tasks() self.assertEquals(obs,exp) @defer.inlineCallbacks def test_save_and_load_tasks_of_environment(self): parentEnvironement = Environment(name="TestEnvironment",description = "A test description") task1 = Task(name="TestTaskOne",description = "A test description") task1._parent = parentEnvironement task2 = Task(name="TestTaskTwo",description = "Another test description",status="active") task2._parent = parentEnvironement input =[task1,task2] parentEnvironement2 = Environment(name="TestEnvironment2",description = "A test description") task3 = Task(name="TestTaskThree",description = "A test description") task3._parent = parentEnvironement2 yield self._persistenceLayer.save_tasks(input) yield self._persistenceLayer.save_task(task3) exp = input obs = yield self._persistenceLayer.load_tasks(parentEnvironement.cid) self.assertEquals(obs,exp) exp = [task3] obs = yield self._persistenceLayer.load_tasks(parentEnvironement2.cid) self.assertEquals(obs,exp) @defer.inlineCallbacks def test_update_task(self): input = Task(name="TestTask",description = "A test description") yield self._persistenceLayer.save_task(input) input.name = "TestTaskModified" yield self._persistenceLayer.save_task(input) exp = input obs = yield self._persistenceLayer.load_task(id = input.cid) self.assertEquals(obs,exp) @defer.inlineCallbacks def test_delete_task(self): input = Task(name="TestTask",description = "A test description") yield self._persistenceLayer.save_task(input) exp = input obs = yield self._persistenceLayer.load_task(id = input.cid) self.assertEquals(obs,exp) yield self._persistenceLayer.delete_task(input) obs = self._persistenceLayer.load_task(id = input.cid) self.assertFailure(obs ,TaskNotFound ) def test_delete_task_exception(self): input = Task(name="TestTask",description = "A test description") obs = self._persistenceLayer.delete_task(input) self.assertFailure(obs ,TaskNotFound ) """ #################################################################################### The following are the Package related tests """ @defer.inlineCallbacks def test_save_and_load_update(self): input = Package(type ="update", name="TestPackage",description = "A test description",) yield self._persistenceLayer.save_update(input) exp = input obs = yield self._persistenceLayer.load_update(id = input.cid) self.assertEquals(obs,exp) @defer.inlineCallbacks def test_save_and_load_updates(self): input =[] input.append(Package(name="TestPackageOne",description = "A test description")) input.append(Package(name="TestPackageTwo",description = "Another test description",status="active")) yield self._persistenceLayer.save_updates(input) exp = input obs = yield self._persistenceLayer.load_updates() self.assertEquals(obs,exp) @defer.inlineCallbacks def test_update_update(self): input = Package(name="TestPackage",description = "A test description") yield self._persistenceLayer.save_update(input) input.name = "TestPackageModified" yield self._persistenceLayer.save_update(input) exp = input obs = yield self._persistenceLayer.load_update(id = input.cid) self.assertEquals(obs,exp)
class PackageSystemTest(unittest.TestCase): @defer.inlineCallbacks def setUp(self): self._path_manager = PathManager() if not os.path.exists("tmp"): os.makedirs("tmp") if not os.path.exists("addons"): os.makedirs("addons") self._path_manager._addon_path = "addons" self._path_manager.tmpPath = "tmp" self._persistenceLayer = PersistenceLayer() self._packageManager = PackageManager(self._persistenceLayer,self._path_manager) yield self._packageManager.setup() @defer.inlineCallbacks def tearDown(self): if os.path.exists("tmp"): shutil.rmtree("tmp") if os.path.exists("addons"): shutil.rmtree("addons") yield self._persistenceLayer.tearDown() if os.path.exists("pollapli.db"): os.remove("pollapli.db") self._stop_mock_file_server() def test_refresh_packageList(self): package1 = Package() package2 = Package() exp = [package1, package2] obs = self._packageManager._packages self.assertEquals(obs,exp) @defer.inlineCallbacks def test_setup_package(self): """Test for downloading and installing a package""" fileServePath = "fileserve" os.makedirs(fileServePath) self._write_mock_compressedPackage("TestAddOn", fileServePath) self._start_mock_file_server(fileServePath) addOn = Package(type = "addon", name = "TestAddOn", version = "0.0.1",file="TestAddOn.zip") addOn.downloadUrl = "http://*****:*****@gmail.com\n") f.write("License: GPL\n") f.write("Description: UNKNOWN\n") f.write("Keywords: web remote control remote monitoring reprap repstrap\n") f.write("Platform: UNKNOWN\n") f.write("Classifier: Development Status :: 1 - Planning\n") f.write("Classifier: Topic :: Utilities\n") f.write("Classifier: Natural Language :: English\n") f.write("Classifier: Operating System :: OS Independent\n") f.write("Classifier: Programming Language :: Python :: 2.6\n") f.close() def _write_mock_packageListFile(self, packageListPath): f = open(packageListPath,"w") f.write('''{ "packages": [ { "id": "23b0d813-a6b2-461a-88ad-a7020ae66742", "type": "addon", "name": "Test AddOn", "version": "0.0.1", "description": "A test Add on", "tags": [ "test", "something" ], "img": "testAddon.png", "file": "testAddon-0.0.1.egg", "fileHash": "80e157c0f10baef206ee2de03fae7449", "downloadUrl" : "http://kaosat.net/pollapli/testAddon-0.0.1.egg" }, { "id": "23b0d813-a6b2-461a-88ad-a7020ae64542", "type": "update", "name": "Test Update", "target": "pollapli", "targetId": "23b0d813-a6b2-461a-88ad-a7020ae67742", "fromVersion" : "0.5.0", "toVersion" : "0.6.0", "description": "A test Update", "tags": [ "update", "fish" ], "img": "testPackage.png", "file": "testPackage-0.2.1.egg", "fileHash": "80e157c0f10baef206ee2de03fae7449", "downloadUrl" : "http://kaosat.net/pollapli/testUpdate-0.2.1.egg" }]}''') f.close()
def setUp(self): self._path_manager = PathManager() self._path_manager.dataPath = "." self._persistenceLayer = PersistenceLayer(pathManager = self._path_manager)
def setUp(self): self._path_manager = PathManager() self._path_manager.dataPath = "." self._persistenceLayer = PersistenceLayer(pathManager = self._path_manager) self._logicLayer = LogicLayer(self._persistenceLayer) yield self._logicLayer.setup()
class LogicLayerTest(unittest.TestCase): @defer.inlineCallbacks def setUp(self): self._path_manager = PathManager() self._path_manager.dataPath = "." self._persistenceLayer = PersistenceLayer(pathManager = self._path_manager) self._logicLayer = LogicLayer(self._persistenceLayer) yield self._logicLayer.setup() def tearDown(self): self._persistenceLayer.tearDown() if os.path.exists("pollapli.db"): os.remove("pollapli.db") @defer.inlineCallbacks def test_add_environment(self): exp = Environment(name="Test Environment", description="A test Environment", status="active") obs = yield self._logicLayer.add_environment(name="Test Environment", description="A test Environment", status="active") self.assertEquals(obs.name, exp.name) self.assertEquals(obs.description,exp.description) self.assertEquals(obs.status,exp.status) yield self._persistenceLayer.delete_environment(obs) @defer.inlineCallbacks def test_reload_environments(self): environment = yield self._logicLayer.add_environment(name="Test Environment", description="A test Environment", status="active") environment2 = yield self._logicLayer.add_environment(name="Test Environment2", description="A test Environment2", status="inactive") self._persistenceLayer.tearDown() self._persistenceLayer = None self._persistenceLayer = PersistenceLayer(pathManager = self._path_manager) self._logicLayer = LogicLayer(self._persistenceLayer) yield self._logicLayer.setup() lExpEnvs = [environment,environment2] lObsEnvs = yield self._logicLayer.get_environments() lObsEnvs = sorted(lObsEnvs,key=lambda environment: environment.name) lExpEnvs = sorted(lExpEnvs,key=lambda environment: environment.name) self.assertEquals(lObsEnvs,lExpEnvs) yield self._persistenceLayer.delete_environments([environment,environment2]) @defer.inlineCallbacks def test_remove_environment(self): environment = yield self._logicLayer.add_environment(name="Test Environment", description="A test Environment", status="active") yield self._logicLayer.remove_environment(id = environment.cid) self.assertRaises(EnvironmentNotFound,self._logicLayer.get_environment,id = environment.cid) #self.assertFailure(self._logicLayer.get_environment(id = env.cid) ,EnvironmentNotFound) @defer.inlineCallbacks def test_add_devices_to_environment(self): environment = yield self._logicLayer.add_environment(name="Test Environment", description="A test Environment", status="active") environment2 = yield self._logicLayer.add_environment(name="Test EnvironmentTwo", description="A test Environment aswell", status="inactive") device = yield self._logicLayer.add_device(environmentId = environment.cid, name="Test Device", description = "A test description", type="Test") device2 = yield self._logicLayer.add_device(environmentId = environment.cid, name="Test Device Two", description = "Another test description", type="Test") device3 = yield self._logicLayer.add_device(environmentId = environment2.cid, name="Test Device Three", type="Test") lExpDevices = [device,device2] lObsDevices = yield self._logicLayer.get_devices(environmentId = environment.cid) lExpDevices = sorted(lExpDevices,key=lambda device: device.name) lObsDevices = sorted(lObsDevices,key=lambda device: device.name) self.assertEquals(lObsDevices,lExpDevices) lExpDevices = [device3] lObsDevices = yield self._logicLayer.get_devices(environmentId = environment2.cid) self.assertEquals(lObsDevices,lExpDevices) yield self._persistenceLayer.delete_environments([environment,environment2]) @defer.inlineCallbacks def test_clear_devices(self): # logger = logging.getLogger("pollapli.core") # logger.setLevel(logging.DEBUG) # formatter = logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s") # ch = logging.StreamHandler(sys.stdout) # ch.setLevel(logging.DEBUG) # ch.setFormatter(formatter) # logger.addHandler(ch) # observer = log.PythonLoggingObserver("pollapli.core") # observer.start() environment = yield self._logicLayer.add_environment(name="Test Environment", description="A test Environment", status="active") yield environment.add_device(name="Test Device",description = "A test description", type="Test") yield environment.add_device(name="Test Device",description = "A test description", type="Test") devices = yield environment.get_devices() self.assertTrue(len(devices)>0) yield environment.clear_devices() devices = yield environment.get_devices() self.assertTrue(len(devices)==0) yield self._persistenceLayer.delete_environment(environment) @defer.inlineCallbacks def test_add_tasks_to_environment(self): environment = yield self._logicLayer.add_environment(name="Test Environment", description="A test Environment", status="active") environment2 = yield self._logicLayer.add_environment(name="Test EnvironmentTwo", description="A test Environment aswell", status="inactive") task = yield self._logicLayer.add_task(environmentId = environment.cid, name="Test Task",description = "A test description") task2 = yield self._logicLayer.add_task(environmentId = environment.cid, name="Test Task Two",description = "A test description too") task3 = yield self._logicLayer.add_task(environmentId = environment2.cid, name="Test Task Three") lExpTasks = [task,task2] lObsTasks = yield self._logicLayer.get_tasks(environmentId = environment.cid) lExpTasks = sorted(lExpTasks,key=lambda task: task.name) lObsTasks = sorted(lObsTasks,key=lambda task: task.name) self.assertEquals(lObsTasks, lExpTasks) lExpTasks = [task3] lObsTasks = yield self._logicLayer.get_tasks(environmentId = environment2.cid) self.assertEquals(lObsTasks, lExpTasks) yield self._persistenceLayer.delete_environments([environment,environment2]) @defer.inlineCallbacks def test_reload_tasks(self): environment = yield self._logicLayer.add_environment(name="Test Environment", description="A test Environment", status="active") environment2 = yield self._logicLayer.add_environment(name="Test Environment2", description="A test Environment2", status="inactive") task = yield self._logicLayer.add_task(environmentId = environment.cid, name="Test Task",description = "A test description") task2 = yield self._logicLayer.add_task(environmentId = environment.cid, name="Test Task Two",description = "A test description too") task3 = yield self._logicLayer.add_task(environmentId = environment2.cid, name="Test Task Three") self._persistenceLayer.tearDown() self._persistenceLayer = None self._persistenceLayer = PersistenceLayer(pathManager = self._path_manager) self._logicLayer = LogicLayer(self._persistenceLayer) yield self._logicLayer.setup() lExpTasksEnv1 = [task,task2] lObsTasksEnv1 = yield self._logicLayer.get_tasks(environmentId = environment.cid) lExpTasksEnv1 = sorted(lExpTasksEnv1,key=lambda task: task.name) lObsTasksEnv1 = sorted(lObsTasksEnv1,key=lambda task: task.name) self.assertEquals(lObsTasksEnv1, lExpTasksEnv1) lExpTasksEnv2 = [task3] lObsTasksEnv2 = yield self._logicLayer.get_tasks(environmentId = environment2.cid) lExpTasksEnv2 = sorted(lExpTasksEnv2,key=lambda task: task.name) lObsTasksEnv2 = sorted(lObsTasksEnv2,key=lambda task: task.name) self.assertEquals(lObsTasksEnv2, lExpTasksEnv2) yield self._persistenceLayer.delete_environments([environment,environment2]) @defer.inlineCallbacks def test_reload_devices(self): environment = yield self._logicLayer.add_environment(name="Test Environment", description="A test Environment", status="active") environment2 = yield self._logicLayer.add_environment(name="Test Environment2", description="A test Environment2", status="inactive") device = yield self._logicLayer.add_device(environmentId = environment.cid, name="Test Device",description = "A test description") device2 = yield self._logicLayer.add_device(environmentId = environment.cid, name="Test Device Two",description = "A test description too") device3 = yield self._logicLayer.add_device(environmentId = environment2.cid, name="Test Device Three") self._persistenceLayer.tearDown() self._persistenceLayer = None self._persistenceLayer = PersistenceLayer(pathManager = self._path_manager) self._logicLayer = LogicLayer(self._persistenceLayer) yield self._logicLayer.setup() lExpDevicesEnv1 = [device,device2] lObsDevicesEnv1 = yield self._logicLayer.get_devices(environmentId = environment.cid) lExpDevicesEnv1 = sorted(lExpDevicesEnv1,key=lambda device: device.name) lObsDevicesEnv1 = sorted(lObsDevicesEnv1,key=lambda device: device.name) self.assertEquals(lObsDevicesEnv1, lExpDevicesEnv1) lExpDevicesEnv2 = [device3] lObsDevicesEnv2 = yield self._logicLayer.get_devices(environmentId = environment2.cid) lExpDevicesEnv2 = sorted(lExpDevicesEnv2,key=lambda device: device.name) lObsDevicesEnv2 = sorted(lObsDevicesEnv2,key=lambda device: device.name) self.assertEquals(lObsDevicesEnv2, lExpDevicesEnv2) yield self._persistenceLayer.delete_environments([environment,environment2]) @defer.inlineCallbacks def test_reload_complete(self): environment = yield self._logicLayer.add_environment(name="Test Environment", description="A test Environment", status="active") environment2 = yield self._logicLayer.add_environment(name="Test Environment2", description="A test Environment2", status="inactive") task = yield self._logicLayer.add_task(environmentId = environment.cid, name="Test Task",description = "A test description") task2 = yield self._logicLayer.add_task(environmentId = environment.cid, name="Test Task Two",description = "A test description too") task3 = yield self._logicLayer.add_task(environmentId = environment2.cid, name="Test Task Three") task4 = yield self._logicLayer.add_task(environmentId = environment2.cid, name="Test Task Four") device = yield self._logicLayer.add_device(environmentId = environment.cid, name="Test Device", description = "A test description", type="Test") device2 = yield self._logicLayer.add_device(environmentId = environment2.cid, name="Test Device Two", description = "Another test description", type="Test") device3 = yield self._logicLayer.add_device(environmentId = environment2.cid, name="Test Device Three", type="Test") """destroy current layer, restart and reload""" self._persistenceLayer.tearDown() self._persistenceLayer = None self._persistenceLayer = PersistenceLayer(pathManager = self._path_manager) self._logicLayer = LogicLayer(self._persistenceLayer) yield self._logicLayer.setup() lExpEnvs = [environment,environment2] lObsEnvs = yield self._logicLayer.get_environments() lObsEnvs = sorted(lObsEnvs,key=lambda environment: environment.name) lExpEnvs = sorted(lExpEnvs,key=lambda environment: environment.name) self.assertEquals(lObsEnvs,lExpEnvs) lExpTasksEnv1 = [task,task2] lObsTasksEnv1 = yield self._logicLayer.get_tasks(environmentId = environment.cid) lExpTasksEnv1 = sorted(lExpTasksEnv1,key=lambda task: task.name) lObsTasksEnv1 = sorted(lObsTasksEnv1,key=lambda task: task.name) self.assertEquals(lObsTasksEnv1, lExpTasksEnv1) lExpTasksEnv2 = [task3,task4] lObsTasksEnv2 = yield self._logicLayer.get_tasks(environmentId = environment2.cid) lExpTasksEnv2 = sorted(lExpTasksEnv2,key=lambda task: task.name) lObsTasksEnv2 = sorted(lObsTasksEnv2,key=lambda task: task.name) self.assertEquals(lObsTasksEnv2, lExpTasksEnv2) lExpDevicesEnv1 = [device] lObsDevicesEnv1 = yield self._logicLayer.get_devices(environmentId = environment.cid) lExpDevicesEnv1 = sorted(lExpDevicesEnv1,key=lambda device: device.name) lObsDevicesEnv1 = sorted(lObsDevicesEnv1,key=lambda device: device.name) self.assertEquals(lObsDevicesEnv1, lExpDevicesEnv1) lExpDevicesEnv2 = [device2,device3] lObsDevicesEnv2 = yield self._logicLayer.get_devices(environmentId = environment2.cid) lExpDevicesEnv2 = sorted(lExpDevicesEnv2,key=lambda device: device.name) lObsDevicesEnv2 = sorted(lObsDevicesEnv2,key=lambda device: device.name) self.assertEquals(lObsDevicesEnv2, lExpDevicesEnv2) yield self._persistenceLayer.delete_environments([environment,environment2]) @defer.inlineCallbacks def test_task_schedule(self): environment = yield self._logicLayer.add_environment(name="Test Environment", description="A test Environment", status="active") task = yield self._logicLayer.add_task(environmentId = environment.cid, name="Test Task",description = "A test description") # task.add_action() # task.add_condtion() yield self._persistenceLayer.delete_environment(environment)
class PackageSystemTest(unittest.TestCase): @defer.inlineCallbacks def setUp(self): self._path_manager = PathManager() if not os.path.exists("tmp"): os.makedirs("tmp") if not os.path.exists("addons"): os.makedirs("addons") self._path_manager._addon_path = "addons" self._path_manager.tmpPath = "tmp" self._persistenceLayer = PersistenceLayer() self._packageManager = PackageManager(self._persistenceLayer, self._path_manager) yield self._packageManager.setup() @defer.inlineCallbacks def tearDown(self): if os.path.exists("tmp"): shutil.rmtree("tmp") if os.path.exists("addons"): shutil.rmtree("addons") yield self._persistenceLayer.tearDown() if os.path.exists("pollapli.db"): os.remove("pollapli.db") self._stop_mock_file_server() def test_refresh_packageList(self): package1 = Package() package2 = Package() exp = [package1, package2] obs = self._packageManager._packages self.assertEquals(obs, exp) @defer.inlineCallbacks def test_setup_package(self): """Test for downloading and installing a package""" fileServePath = "fileserve" os.makedirs(fileServePath) self._write_mock_compressedPackage("TestAddOn", fileServePath) self._start_mock_file_server(fileServePath) addOn = Package(type="addon", name="TestAddOn", version="0.0.1", file="TestAddOn.zip") addOn.downloadUrl = "http://*****:*****@gmail.com\n") f.write("License: GPL\n") f.write("Description: UNKNOWN\n") f.write( "Keywords: web remote control remote monitoring reprap repstrap\n") f.write("Platform: UNKNOWN\n") f.write("Classifier: Development Status :: 1 - Planning\n") f.write("Classifier: Topic :: Utilities\n") f.write("Classifier: Natural Language :: English\n") f.write("Classifier: Operating System :: OS Independent\n") f.write("Classifier: Programming Language :: Python :: 2.6\n") f.close() def _write_mock_packageListFile(self, packageListPath): f = open(packageListPath, "w") f.write('''{ "packages": [ { "id": "23b0d813-a6b2-461a-88ad-a7020ae66742", "type": "addon", "name": "Test AddOn", "version": "0.0.1", "description": "A test Add on", "tags": [ "test", "something" ], "img": "testAddon.png", "file": "testAddon-0.0.1.egg", "fileHash": "80e157c0f10baef206ee2de03fae7449", "downloadUrl" : "http://kaosat.net/pollapli/testAddon-0.0.1.egg" }, { "id": "23b0d813-a6b2-461a-88ad-a7020ae64542", "type": "update", "name": "Test Update", "target": "pollapli", "targetId": "23b0d813-a6b2-461a-88ad-a7020ae67742", "fromVersion" : "0.5.0", "toVersion" : "0.6.0", "description": "A test Update", "tags": [ "update", "fish" ], "img": "testPackage.png", "file": "testPackage-0.2.1.egg", "fileHash": "80e157c0f10baef206ee2de03fae7449", "downloadUrl" : "http://kaosat.net/pollapli/testUpdate-0.2.1.egg" }]}''') f.close()