def test_escrita_campo_num_decimal(self):
        # aceitar somente tipo Decimal
        with self.assertRaises(errors.TipoError):
            self.seg_p.valor_titulo = 10.0
        with self.assertRaises(errors.TipoError):
            self.seg_p.valor_titulo = ''

        # Testa se as casas decimais estao sendo verificadas
        with self.assertRaises(errors.NumDecimaisError):
            self.seg_p.valor_titulo = Decimal('100.2')
        with self.assertRaises(errors.NumDecimaisError):
            self.seg_p.valor_titulo = Decimal('1001')
        with self.assertRaises(errors.NumDecimaisError):
            self.seg_p.valor_titulo = Decimal('1.000')

        # verifica se o numero de digitos esta sendo verificado
        with self.assertRaises(errors.NumDigitosExcedidoError):
            self.seg_p.valor_titulo = Decimal('10000000008100.21')

        # armazemamento correto de um decimal
        self.seg_p.valor_titulo = Decimal('2.13')
        self.assertEqual(self.seg_p.valor_titulo, Decimal('2.13'))
def get_spec(field, limit=10, query='', query_dsl=''):
    """Returns aggregation specs for a term of filtered events.

    The aggregation spec will summarize values of an attribute
    whose events fall under a filter.

    Args:
        field (str): this denotes the event attribute that is used
            for aggregation.
        limit (int): How many buckets to return, defaults to 10.
        query (str): the query field to run on all documents prior to
            aggregating the results.
        query_dsl (str): the query DSL field to run on all documents prior
            to aggregating the results (optional). Either a query string
            or a query DSL has to be present.

    Raises:
        ValueError: if neither query_string or query_dsl is provided.

    Returns:
        a dict value that can be used as an aggregation spec.
    """
    if query:
        query_filter = {
            'bool': {
                'must': [
                    {
                        'query_string': {
                            'query': query
                        }
                    }
                ]
            }
        }
    elif query_dsl:
        query_filter = query_dsl
    else:
        raise ValueError('Neither query nor query DSL provided.')


    return {
        'query': query_filter,
        'aggs': {
            'aggregation': {
                'terms': {
                    'field': field,
                    'size': limit
                }
            }
        }
    }