def test_retrieved_switches_can_be_updated(self): switch = Switch('foo') self.manager.register(switch) switch.name = 'steve' switch.save() self.assertRaises(ValueError, self.manager.switch, 'foo') self.assertEquals(self.manager.switch('steve').name, 'steve') switch.name = 'bob' switch.state = Switch.states.GLOBAL switch.save() self.assertEquals(self.manager.switch('bob').name, 'bob') self.assertEquals( self.manager.switch('bob').state, Switch.states.GLOBAL) self.assertRaises(ValueError, self.manager.switch, 'steve')
def test_retrieved_switches_can_be_updated(self): switch = Switch('foo') self.manager.register(switch) switch.name = 'steve' switch.save() self.assertRaises(ValueError, self.manager.switch, 'foo') self.assertEquals(self.manager.switch('steve').name, 'steve') switch.name = 'bob' switch.state = Switch.states.GLOBAL switch.save() self.assertEquals(self.manager.switch('bob').name, 'bob') self.assertEquals( self.manager.switch('bob').state, Switch.states.GLOBAL ) self.assertRaises(ValueError, self.manager.switch, 'steve')
def test_can_register_signals_and_get_notified(self): signals.switch_registered.connect(self.callback.switch_added) signals.switch_unregistered.connect(self.callback.switch_removed) signals.switch_updated.connect(self.callback.switch_updated) eq_(self.callback.register_calls, []) eq_(self.callback.unregister_calls, []) eq_(self.callback.update_calls, []) switch = Switch('foo') self.manager.register(switch) eq_(self.callback.register_calls, [switch]) self.manager.unregister(switch.name) eq_(self.callback.unregister_calls, [switch]) self.manager.register(switch) eq_(self.callback.register_calls, [switch, switch]) switch.name = 'a new name' switch.state = Switch.states.GLOBAL self.manager.update(switch) change = self.callback.update_calls[0] eq_(change[0], switch) changes = change[1] eq_(changes['name'], dict(current='a new name', previous='foo')) eq_( changes['state'], dict(current=Switch.states.GLOBAL, previous=Switch.states.DISABLED)) switch.name = 'from save() call' switch.save() change = self.callback.update_calls[1] eq_(change[0], switch) changes = change[1] eq_(changes['name'], dict(current='from save() call', previous='a new name'))
def test_can_register_signals_and_get_notified(self): signals.switch_registered.connect(self.callback.switch_added) signals.switch_unregistered.connect(self.callback.switch_removed) signals.switch_updated.connect(self.callback.switch_updated) eq_(self.callback.register_calls, []) eq_(self.callback.unregister_calls, []) eq_(self.callback.update_calls, []) switch = Switch('foo') self.manager.register(switch) eq_(self.callback.register_calls, [switch]) self.manager.unregister(switch.name) eq_(self.callback.unregister_calls, [switch]) self.manager.register(switch) eq_(self.callback.register_calls, [switch, switch]) switch.name = 'a new name' switch.state = Switch.states.GLOBAL self.manager.update(switch) change = self.callback.update_calls[0] eq_(change[0], switch) changes = change[1] eq_(changes['name'], dict(current='a new name', previous='foo')) eq_(changes['state'], dict(current=Switch.states.GLOBAL, previous=Switch.states.DISABLED)) switch.name = 'from save() call' switch.save() change = self.callback.update_calls[1] eq_(change[0], switch) changes = change[1] eq_(changes['name'], dict(current='from save() call', previous='a new name'))
def test_switch_name_is_immutable(self): switch = Switch("foo") with self.assertRaises(AttributeError): switch.name = "bar"
def test_switch_name_is_immutable(self): switch = Switch('foo') with self.assertRaises(AttributeError): switch.name = 'bar'