def testHasProxy(self): """ModelTest: Test hasProxy()""" # Create proxies model1 = Model.getInstance(self.KEY1) model2 = Model.getInstance(self.KEY2) proxy1 = Proxy("aces", ["clubs", "spades", "hearts", "diamonds"]) proxy2 = Proxy("directions", ["north", "south", "east", "west"]) # Register proxies model1.registerProxy(proxy1) model2.registerProxy(proxy2) self.assertEqual(True, model1.hasProxy('aces')) self.assertEqual(False, model2.hasProxy('aces')) self.assertEqual(True, model2.hasProxy('directions')) self.assertEqual(False, model1.hasProxy('directions')) # Remove proxies model1.removeProxy('aces') model2.removeProxy('directions') self.assertEqual(False, model1.hasProxy('aces')) self.assertEqual(False, model2.hasProxy('directions'))
def __init__(self, data=None): Proxy.__init__(self, self.NAME, _prefs.prefs) # load saved config self.load('config.xml') # export prefs instance into model module model.prefs = self
def testDataAccessors(self): """ProxyTest: Test Data Accessors""" prxy = Proxy('colors') prxy.setData(['red', 'green', 'blue']) data = prxy.getData() self.assertEqual(True, len(data) == 3) self.assertEqual(True, data[0] == 'red') self.assertEqual(True, data[1] == 'green') self.assertEqual(True, data[2] == 'blue')
def testConstructor(self): """ProxyTest: Test Constructor""" prxy = Proxy('colors', ['red', 'green', 'blue']) data = prxy.getData() self.assertEqual(True, prxy is not None) self.assertEqual(True, prxy.getProxyName() == 'colors') self.assertEqual(True, len(data) == 3) self.assertEqual(True, data[0] == 'red') self.assertEqual(True, data[1] == 'green') self.assertEqual(True, data[2] == 'blue')
def testEmptyData(self): """ProxyTest: Test Constructor with not-null empty data""" values = ["", (), []] for value in values: proxy = Proxy("empty", value) self.assertEqual(proxy.data, value)
def testRegisterAndRemoveProxy(self): """ModelTest: Test registerProxy() and removeProxy()""" model = Model.getInstance(self.KEY1) testProxy = Proxy('sizes', ['7', '13', '21']) model.registerProxy(testProxy) removedProxy = model.removeProxy('sizes') self.assertEqual(True, removedProxy.getProxyName() == 'sizes') testProxy = model.retrieveProxy('sizes') self.assertEqual(None, testProxy)
def testRegisterAndRetrieveProxy(self): """ModelTest: Test registerProxy() and retrieveProxy()""" model = Model.getInstance(self.KEY1) model.registerProxy(Proxy('colors', ['red', 'green', 'blue'])) testProxy = model.retrieveProxy('colors') data = testProxy.getData() self.assertNotEqual(None, data) self.assertEqual(True, isinstance(data, list)) self.assertEqual(True, len(data) == 3) self.assertEqual(True, data[0] == 'red') self.assertEqual(True, data[1] == 'green') self.assertEqual(True, data[2] == 'blue')
def testNameAccessor(self): """ProxyTest: Test Name Accessor""" prxy = Proxy('TestProxy') self.assertEqual(True, prxy.getProxyName() == 'TestProxy')
def testHasMultitonKey(self): """ProxyTest: has multiton key""" prxy = Proxy("multitonKey") self.assertTrue(hasattr(prxy, "multitonKey"))
def __init__(self): Proxy.__init__(self, PrefsProxy.NAME, model.Prefs)
def __init__(self): Proxy.__init__(self, EnvProxy.NAME)
def __getattr__(self, name): try: return self.data.__getattribute__(name) except: return Proxy.__getattribute__(self, name)