def test_api_check_returns_field_boolean_value(self): api = BdfCallbacks(Registry()) a_object = api.register('a_object', Object) a_object_instance = api.registry.get_instance(a_object) a_object_instance.boolean_field = False self.assertFalse(api.check(a_object, 'boolean_field')) a_object_instance.boolean_field = True self.assertTrue(api.check(a_object, 'boolean_field'))
def test_api_prepare_object_prepare_is_called(self): class AObject(Object): prepare = MagicMock() api = BdfCallbacks(Registry()) a_object = api.register('a_object', AObject) a_object_instance = api.registry.get_instance(a_object) api.prepare(a_object) a_object_instance.prepare.assert_called_once()
def test_api_activate_object_activate_called(self): class AObject(Object): activate = MagicMock() api = BdfCallbacks(Registry()) a_object = api.register('a_object', AObject) a_object_instance = api.registry.get_instance(a_object) api.activate(a_object) a_object_instance.activate.assert_called_once()
def test_api_is_prepared_object_is_prepared_boolean_is_returned(self): class AObject(Object): pass api = BdfCallbacks(Registry()) a_object = api.register('a_object', AObject) a_object_instance = api.registry.get_instance(a_object) a_object_instance.is_prepared = MagicMock(return_value=True) self.assertTrue(api.is_prepared(a_object)) a_object_instance.is_prepared = MagicMock(return_value=False) self.assertFalse(api.is_prepared(a_object))
def bdf(api: BdfCallbacks): c = api.register('a_condition', ACondition) b = api.register('a_behavior', ABehavior) if api.check(c, 'a_condition_field'): api.activate(b)
def test_api_is_prepared_unregistered_object_raises_exception(self): api = BdfCallbacks(Registry()) self.assertRaises(Exception, api.is_prepared, 'unregistered_object')
def test_api_register_object_name_string_is_returned(self): api = BdfCallbacks(Registry()) a_object_name = 'a_object' a_object = api.register(a_object_name, Object) self.assertIs(a_object_name, a_object)
def test_api_register_registry_add_is_called_with_given_parameters(self): registry = MagicMock() api = BdfCallbacks(registry) a_object = api.register('a_object', Object) api.registry.add.assert_called_once_with(a_object, Object)
def test_api_activate_unregistered_object_raises_exception(self): api = BdfCallbacks(Registry()) self.assertRaises(Exception, api.activate, 'unregistered_object')
def test_api_check_non_existent_field_returns_false(self): api = BdfCallbacks(Registry()) a_object = api.register('a_object', Object) self.assertFalse(api.check(a_object, 'non_existent_field'))
def test_api_check_unregistered_object_raises_exception(self): api = BdfCallbacks(Registry()) self.assertRaises(Exception, api.check, 'unregistered_object', '-')
def test_api_constructor(self): a_registry = MagicMock() api = BdfCallbacks(a_registry) self.assertEqual(api.registry, a_registry)