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()
Beispiel #2
0
class LogicLayer(object):
    def __init__(self, persistenceLayer=None):
        self._persistenceLayer = persistenceLayer
        self._environmentManager = EnvironmentManager(self._persistenceLayer)
        #self._driverManager = DriverManager()

    @defer.inlineCallbacks
    def setup(self):
        yield self._environmentManager.setup()

    def __getattr__(self, attr_name):
        if hasattr(self._environmentManager, attr_name):
            return getattr(self._environmentManager, attr_name)
        else:
            raise AttributeError(attr_name)

    @defer.inlineCallbacks
    def add_task(self, environmentId, *args, **kwargs):
        env = self._environmentManager.get_environment(environmentId, *args,
                                                       **kwargs)
        task = yield env.add_task(*args, **kwargs)
        defer.returnValue(task)

    @defer.inlineCallbacks
    def get_tasks(self, environmentId=None, *args, **kwargs):
        env = self._environmentManager.get_environment(environmentId, *args,
                                                       **kwargs)
        tasks = yield env.get_tasks(*args, **kwargs)
        defer.returnValue(tasks)

    @defer.inlineCallbacks
    def add_device(self, environmentId, *args, **kwargs):
        env = self._environmentManager.get_environment(environmentId)
        device = yield env.add_device(*args, **kwargs)
        defer.returnValue(device)

    @defer.inlineCallbacks
    def get_devices(self, environmentId=None, *args, **kwargs):
        env = self._environmentManager.get_environment(environmentId, *args,
                                                       **kwargs)
        devices = yield env.get_devices(*args, **kwargs)
        defer.returnValue(devices)
Beispiel #3
0
class LogicLayer(object):
    def __init__(self, persistenceLayer=None):
        self._persistenceLayer = persistenceLayer
        self._environmentManager = EnvironmentManager(self._persistenceLayer)
        # self._driverManager = DriverManager()

    @defer.inlineCallbacks
    def setup(self):
        yield self._environmentManager.setup()

    def __getattr__(self, attr_name):
        if hasattr(self._environmentManager, attr_name):
            return getattr(self._environmentManager, attr_name)
        else:
            raise AttributeError(attr_name)

    @defer.inlineCallbacks
    def add_task(self, environmentId, *args, **kwargs):
        env = self._environmentManager.get_environment(environmentId, *args, **kwargs)
        task = yield env.add_task(*args, **kwargs)
        defer.returnValue(task)

    @defer.inlineCallbacks
    def get_tasks(self, environmentId=None, *args, **kwargs):
        env = self._environmentManager.get_environment(environmentId, *args, **kwargs)
        tasks = yield env.get_tasks(*args, **kwargs)
        defer.returnValue(tasks)

    @defer.inlineCallbacks
    def add_device(self, environmentId, *args, **kwargs):
        env = self._environmentManager.get_environment(environmentId)
        device = yield env.add_device(*args, **kwargs)
        defer.returnValue(device)

    @defer.inlineCallbacks
    def get_devices(self, environmentId=None, *args, **kwargs):
        env = self._environmentManager.get_environment(environmentId, *args, **kwargs)
        devices = yield env.get_devices(*args, **kwargs)
        defer.returnValue(devices)
Beispiel #4
0
 def __init__(self, persistenceLayer=None):
     self._persistenceLayer = persistenceLayer
     self._environmentManager = EnvironmentManager(self._persistenceLayer)
Beispiel #5
0
 def __init__(self, persistenceLayer=None):
     self._persistenceLayer = persistenceLayer
     self._environmentManager = EnvironmentManager(self._persistenceLayer)
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)