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 testGetInstance(self): """ModelTest: Test get model instance""" model1 = Model.getInstance(self.KEY1) model2 = Model.getInstance(self.KEY2) self.assertNotEqual(None, model1) self.assertNotEqual(None, model2) self.assertNotEqual(model1, model2)
def initializeModel(self): """ Initialize the C{Model}. Called by the C{initializeFacade} method. Override this method in your subclass of C{Facade} if one or both of the following are true: You wish to initialize a different C{IModel}. You have C{Proxy}s to register with the Model that do not retrieve a reference to the Facade at construction time. If you don't want to initialize a different C{IModel}, call C{super.initializeModel()} at the beginning of your method, then register C{Proxy}s. Note: This method is <i>rarely</i> overridden; in practice you are more likely to use a C{Command} to create and register C{Proxy}s with the C{Model}, since C{Proxy}s with mutable data will likely need to send C{INotification}s and thus will likely want to fetch a reference to the C{Facade} during their construction. """ if self.model is None: from puremvc.core import Model self.model = Model.getInstance(self.multitonKey)
def removeCore(cls, key): """ Remove a Core. Remove the Model, View, Controller and Facade instances for the given key. @param key: of the Core to remove """ if cls.instanceMap.get(key): from puremvc.core import Controller, Model, View Model.removeModel(key) View.removeView(key) Controller.removeController(key) cls.instanceMap.pop(key)
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 testOnRegisterAndOnRemove(self): """ModelTest: Test onRegister() and onRemove()""" model = Model.getInstance(self.KEY1) testProxy = ModelTestProxy() model.registerProxy(testProxy) self.assertEqual( True, testProxy.getData() == ModelTestProxy.ON_REGISTER_CALLED) model.removeProxy(ModelTestProxy.NAME) self.assertEqual( True, testProxy.getData() == ModelTestProxy.ON_REMOVE_CALLED)
def testErrorSameKey(self): """ModelTest: raise error if create controller with same key""" model = Model(self.KEY1) self.assertRaises(MultitonError, Model, self.KEY1)
def testIsIModel(self): """ModelTest: Test instance implements IModel""" model = Model.getInstance(self.KEY1) self.assertEqual(True, isinstance(model, IModel))