def test_no_permission(self): def adapter(*args): self.assertEqual((field, 'ctx', 'source_dict', 'target_object'), args) return 'field', 'source', 'target' function = Mock() auth = authorization(adapter) field = Mock(name='field', spec=['permission']) field.permission = None value = auth(function) value(field, 'ctx', 'source_dict', 'target_object') function.assert_called_with(field, 'ctx', 'source_dict', 'target_object')
def test_not_authorized(self): def adapter(*args): self.assertEqual((field, 'ctx', 'source_dict', 'target_object'), args) return 'field', 'source', 'target' function = Mock() # Raise an exception if it is called. function.side_effect = Exception auth = authorization(adapter) field = Mock(name='field', spec=['permission']) field.permission.auth_adapter = None field.permission.is_write_authorized.return_value = False value = auth(function) with self.assertRaises(AuthorizationError): value(field, 'ctx', 'source_dict', 'target_object') field.permission.is_write_authorized.assert_called_with('ctx', 'target_object', 'source', 'target')
def test_not_authorized(self): def adapter(*args): self.assertEqual((field, 'ctx', 'source_dict', 'target_object'), args) return 'field', 'source', 'target' function = Mock() # Raise an exception if it is called. function.side_effect = Exception auth = authorization(adapter) field = Mock(name='field', spec=['permission']) field.permission.auth_adapter = None field.permission.is_write_authorized.return_value = False value = auth(function) with self.assertRaises(AuthorizationError): value(field, 'ctx', 'source_dict', 'target_object') field.permission.is_write_authorized.assert_called_with( 'ctx', 'target_object', 'source', 'target')