def test_get_password(self): """Password gleaned correctly from config file""" c = Configurator() c.fromString(configdata) self.assertEqual(len(c), 2) self.assertEqual(c.getPassword(), 'password123')
def test_case_insensitivity(self): """Authentication section name should be case insensitive""" c = Configurator() c.fromString(configdata2) self.assertEqual(len(c), 2) self.assertEqual(c.getPassword(), 'password123')
class DeviceServer: implements(IDeviceServer) def __init__(self, config): self.config = config if not isinstance(config,Configurator): self.loadConfig(config) #dictionary of devices, keyed by a Container with relevant info in it. self.devices = {} # each device has a command queue self.queues = {} # dictionary of device containers, keyed by type. self._devicemap = {} for device in self.config.sections(): con = Container() key, instance = self.config.createDevice(device) con.name = key con.type = instance.getDeviceType() try: self._devicemap[instance.getDeviceType()].append(con) except KeyError: self._devicemap[instance.getDeviceType()] = [con] self.devices[con] = instance self.queues[con] = DeviceQueue() def loadConfig(self, config): self.config = Configurator(config) def getPassword(self): return self.config.getPassword() def deviceExecute(self, device, command, param=None): if device in self.getDeviceList(): if command in self.getCommandList(device): # bound method of desired device device_method = getattr(self.devices[device], command) # convenient reference queue = self.queues[device] # add to device queue d = queue.submit(device_method, param) return d def getDeviceList(self): return self.devices.keys() def getDeviceType(self, device): return self.devices[device].getDeviceType() def getCommandList(self, device): return self.devices[device].getCommandList() def getDeviceMap(self): return self._devicemap
def test_no_password(self): """Anonymous password gleaned correctly from config file""" c = Configurator() self.assertEqual(c.getPassword(), '')
class DeviceServer: implements(IDeviceServer) def __init__(self, config): self.config = config if not isinstance(config,Configurator): self.loadConfig(config) # dictionary of device instances keyed by name self.devices = {} # each device has a command queue self.queues = {} self._devicemap = {} for device in self.config.sections(): key, instance = self.config.createDevice(device) try: self._devicemap[instance.getDeviceType()].append(device) except KeyError: self._devicemap[instance.getDeviceType()] = [device] self.devices[key] = instance self.queues[key] = DeviceQueue() self.message = "MESSAGE::TO::PASS" def loadConfig(self, config): self.config = Configurator(config) def setMessage(self, message): self.message = message def getPassword(self): return self.config.getPassword() def deviceExecute(self, device, command, param=None): if device in self.getDeviceList(): if command in self.getCommandList(device): # bound method of desired device device_method = getattr(self.devices[device], command) # convenient reference queue = self.queues[device] # add to device queue d = queue.submit(device_method, param) return d def getDeviceList(self): return self.devices.keys() def getDeviceType(self, device): return self.devices[device].getDeviceType() def getCommandList(self, device): return self.devices[device].getCommandList() def getDeviceMap(self): return self._devicemap