def _to_gob_value(entity, field, spec, resolve_secure=False): """ Transforms a entity field value into a GOB type value Attention: Resolve secure is normally False as this is all handled by the Authority classes For enhanced views however, this is not possible. These queries are based upon a view and cannot directly be related to a GOB Model If the field names of the view are properly named the decryption will be handled here :param entity: :param field: :param spec: :param resolve_secure: :return: """ entity_value = getattr(entity, field, None) if isinstance(spec, dict): gob_type = get_gob_type_from_info(spec) if resolve_secure and Authority.is_secure_type(spec): # Transform the value into a secure type value secure_type = Authority.get_secure_type(gob_type, spec, entity_value) # Return decrypted value return Authority.get_secured_value(secure_type) return gob_type.from_value(entity_value, **spec) else: gob_type = get_gob_type_from_sql_type(spec) return gob_type.from_value(entity_value)
def test_secured_value(self, mock_user, mock_request): authority = Authority('cat', 'col') mock_user.return_value = "any user" mock_secure_type = mock.MagicMock() result = authority.get_secured_value(mock_secure_type) mock_user.assert_called_with(mock_request) mock_secure_type.get_value.assert_called_with("any user")