Ejemplo n.º 1
0
    def test_fixed(self):
        field5 = fields.Fixed(5)
        field4 = fields.Fixed(4)

        self.assertEquals('3.14159', field5.output("hey", {'hey': self.PI}))
        self.assertEquals('3.1416', field4.output("hey", {'hey': self.PI}))
        self.assertEquals('3.0000', field4.output("hey", {'hey': '3'}))
        self.assertEquals('3.0000', field4.output("hey", {'hey': '03'}))
        self.assertEquals('3.0000', field4.output("hey", {'hey': '03.0'}))
Ejemplo n.º 2
0
class Invoices(Resource):
    _fields = {
        'id': fields.Integer,
        'ref_num': fields.Integer,
        'series_id': fields.Integer,
        'series_prefix': fields.String,
        'issued_on': fields.DateTime(dt_format='iso8601'),
        'due_on': fields.DateTime(dt_format='iso8601'),
        'delivered_on': fields.DateTime(dt_format='iso8601'),
        'sent_on': fields.DateTime(dt_format='iso8601'),
        'paid_on': fields.DateTime(dt_format='iso8601'),
        'po_num': fields.String,
        'notes': fields.String,
        'customer_name': fields.String,
        'customer_tax_id': fields.String,
        'customer_contact_person': fields.String,
        'customer_email': fields.String,
        'customer_invoicing_address': fields.String,
        'customer_shipping_address': fields.String,
    }

    _linefields = {
        'id': fields.Integer,
        'description': fields.String,
        'quantity': fields.Fixed(2),
        'unit': fields.String,
        'unit_price': fields.Fixed(2),
        'tax_rate': fields.Fixed(2),
        'currency': fields.String,
        'net_value': fields.Fixed(2),
        'is_prepaid': fields.Boolean,
    }

    _totalfields = {
        'net': fields.Fixed(2),
        'tax': fields.Fixed(2),
        'gross': fields.Fixed(2),
    }

    @login_required
    def get(self, id):
        try:
            invoice = marshal(
                Invoice.query.filter_by(owner_id=current_user.get_id(),
                                        id=id).one(), Invoices._fields)

            invoice['lines'] = marshal(
                list(
                    map(LineCalculator().calculate,
                        InvoiceLine.query.filter_by(invoice_id=id).all())),
                Invoices._linefields)

            total_calculator = TotalCalculator()
            (subtotals, total) = total_calculator.calculate(invoice['lines'])

            invoice['subtotals'] = {}
            for r, s in subtotals.items():
                invoice['subtotals'][r] = marshal(s, Invoices._totalfields)

            invoice['total'] = marshal(total, Invoices._totalfields)

            return invoice
        except NoResultFound:
            return {'message': 'invoice not found'}, 404

    @login_required
    def delete(self, id):
        try:
            invoice = Invoice.query.filter_by(owner_id=current_user.get_id(),
                                              id=id).one()

            db.session.delete(invoice)
            db.session.commit()

            return {'message': 'invoice removed'}
        except NoResultFound:
            return {'message': 'invoice not found'}, 404

    @login_required
    def put(self, id):
        try:
            args = invoice_args(request)

            invoice = Invoice.query.filter_by(owner_id=current_user.get_id(),
                                              id=id).one()

            # update model fields from args
            for k in args:
                setattr(invoice, k, args[k])

            db.session.commit()

            return {'message': 'invoice updated'}
        except NoResultFound:
            return {'message': 'invoice not found'}, 404
Ejemplo n.º 3
0
 def test_fixed_with_attribute(self):
     field = fields.Fixed(4, attribute="bar")
     self.assertEquals('3.0000', field.output("foo", {'bar': '3'}))
Ejemplo n.º 4
0
 def test_advanced_fixed(self):
     field = fields.Fixed()
     self.assertRaises(MarshallingException,
                       lambda: field.output("hey", {'hey': 'NaN'}))
Ejemplo n.º 5
0
 def test_infinite_fixed(self):
     field = fields.Fixed()
     self.assertRaises(MarshallingException,
                       lambda: field.output("hey", {'hey': '+inf'}))
     self.assertRaises(MarshallingException,
                       lambda: field.output("hey", {'hey': '-inf'}))
Ejemplo n.º 6
0
 def test_zero_fixed(self):
     field = fields.Fixed()
     self.assertEquals('0.00000', field.output('hey', {'hey': 0}))
Ejemplo n.º 7
0
from flask_restful import Resource, reqparse, fields, marshal_with
from dateutil import parser
from flask_jwt_extended import jwt_required
from .revisions import revision_fields
from ... import db

futuremark3dmark06result_fields = {
    'id': fields.Integer,
    'result_date': fields.DateTime(dt_format='iso8601'),
    'sm2_score': fields.Integer(default=None),
    'cpu_score': fields.Integer(default=None),
    'sm3_score': fields.Integer(default=None),
    'proxcyon_fps': fields.Fixed(decimals=2, default=None),
    'fireflyforest_fps': fields.Fixed(decimals=2, default=None),
    'cpu1_fps': fields.Fixed(decimals=2, default=None),
    'cpu2_fps': fields.Fixed(decimals=2, default=None),
    'canyonflight_fps': fields.Fixed(decimals=2, default=None),
    'deepfreeze_fps': fields.Fixed(decimals=2, default=None),
    'overall_score': fields.Integer(default=None),
    'result_url': fields.String(default=None),
    'revision': fields.Nested(revision_fields),
    'uri': fields.Url('.futuremark3dmark06result', absolute=True)
}

from ...models import Revision, Futuremark3DMark06Result


class Futuremark3DMark06ResultListAPI(Resource):
    @marshal_with(futuremark3dmark06result_fields,
                  envelope='futuremark3dmark06results')
    def get(self):
Ejemplo n.º 8
0
from flask_restful import fields

pessoa_json = {
    'id': fields.Integer,
    'nome': fields.String,
}

classificacao_do_tipo_json = {
    'id': fields.Integer,
    'descricao': fields.String,
}

tipo_do_gasto_json = {
    'id': fields.Integer,
    'descricao': fields.String,
    'classificacao': fields.Nested(classificacao_do_tipo_json)
}

gasto_json = {
    'id': fields.Integer,
    'valor': fields.Fixed(decimals=2),
    'motivo': fields.String,
    'data': fields.DateTime("iso8601"),
    'pessoa': fields.Nested(pessoa_json),
    'tipo': fields.Nested(tipo_do_gasto_json),
}

menu_json = {'nome': fields.String}