Exemplo n.º 1
0
def test_payment(mode, tva, bank):
    from autonomie.models.task.invoice import Payment
    schema = SQLAlchemySchemaNode(Payment)
    schema = schema.bind()

    value = {
        'mode': mode.label,
        "amount": 12.5,
        "remittance_amount": u"Remittance",
        "date": NOW.isoformat(),
        "tva_id": tva.id,
        "bank_id": bank.id,
        "user_id": 5,
        "task_id": 5,
    }

    expected_value = {
        'mode': mode.label,
        "amount": 1250000,
        "remittance_amount": u"Remittance",
        "date": NOW,
        "tva_id": tva.id,
        "bank_id": bank.id,
        "user_id": 5,
        "task_id": 5,
    }
    result = schema.deserialize(value)

    for key, value in expected_value.items():
        assert result[key] == value
Exemplo n.º 2
0
def test_task_line(config, request_with_config, estimation, unity, tva,
                   product, product_without_tva):
    from autonomie.models.task.task import TaskLine
    schema = SQLAlchemySchemaNode(TaskLine)
    request_with_config.context = estimation
    schema = schema.bind(request=request_with_config)
    value = {
        'description': u'test',
        'cost': 450,
        'quantity': 1,
        'unity': u'Mètre',
        'tva': 20.00,
        'product_id': product.id
    }
    assert schema.deserialize(value) == {
        'description': u'test',
        'cost': 45000000,
        'quantity': 1.0,
        'unity': u'Mètre',
        'tva': 2000,
        'product_id': product.id,
        'order': 1
    }
    value = {
        'description': u'test',
        'cost': 450,
        'quantity': 1,
        'unity': u'Mètre',
        'tva': 20.00,
        'product_id': product_without_tva.id
    }
    with pytest.raises(colander.Invalid):
        schema.deserialize(value)
Exemplo n.º 3
0
def test_estimation_payment_lines():
    from autonomie.models.task.estimation import Estimation
    schema = SQLAlchemySchemaNode(Estimation, includes=('payment_lines', ))
    schema = schema.bind()

    value = {'payment_lines': []}
    with pytest.raises(colander.Invalid):
        schema.deserialize(value)

    value = {}
    with pytest.raises(colander.Invalid):
        schema.deserialize(value)

    value = {
        'payment_lines': [{
            'task_id': 5,
            'date': datetime.date.today().isoformat(),
            'amount': 12.5,
            'description': u"Description"
        }]
    }
    expected_value = {
        'payment_lines': [{
            'task_id': 5,
            'date': datetime.date.today(),
            'amount': 1250000,
            'description': u"Description",
            'order': 1
        }]
    }
    assert schema.deserialize(value) == expected_value
Exemplo n.º 4
0
def test_task_line_group_lines(tva, unity):
    from autonomie.models.task.task import TaskLineGroup
    schema = SQLAlchemySchemaNode(TaskLineGroup, includes=('lines', ))
    schema = schema.bind()
    value = {'lines': []}
    with pytest.raises(colander.Invalid):
        schema.deserialize(value)

    value = {
        'lines': [{
            'cost': 15,
            'tva': 20,
            'description': u'description',
            'unity': u"Mètre",
            "quantity": 5,
        }]
    }
    assert schema.deserialize(value) == {
        'lines': [{
            'cost': 1500000,
            'tva': 2000,
            'description': u'description',
            'unity': u"Mètre",
            "quantity": 5.0,
            'order': 1
        }]
    }
Exemplo n.º 5
0
def test_task_mentions(mention):
    from autonomie.models.task.task import Task
    schema = SQLAlchemySchemaNode(Task, includes=('mentions', ))
    schema = schema.bind()
    value = {'mentions': [mention.id]}
    assert schema.deserialize(value) == value
    value = {'mentions': [mention.id + 1]}
    with pytest.raises(colander.Invalid):
        schema.deserialize(value)
Exemplo n.º 6
0
def test_payment_line_date():
    import datetime
    from autonomie.models.task.estimation import PaymentLine
    schema = SQLAlchemySchemaNode(PaymentLine, includes=('date', ))
    schema = schema.bind()
    value = {'date': datetime.date.today().isoformat()}
    assert schema.deserialize(value) == {'date': datetime.date.today()}
    value = {}
    assert schema.deserialize(value) == value
Exemplo n.º 7
0
def test_payment_line_description():
    from autonomie.models.task.estimation import PaymentLine
    schema = SQLAlchemySchemaNode(PaymentLine, includes=('description', ))
    schema = schema.bind()
    value = {'description': "test\n"}
    assert schema.deserialize(value) == value
    value = {'description': "\n"}
    with pytest.raises(colander.Invalid):
        schema.deserialize(value)
Exemplo n.º 8
0
def test_discount_line_task_id():
    from autonomie.models.task.task import DiscountLine
    schema = SQLAlchemySchemaNode(DiscountLine, includes=('task_id', ))
    schema = schema.bind()
    value = {'task_id': 5}
    assert schema.deserialize(value) == value
    value = {}
    with pytest.raises(colander.Invalid):
        schema.deserialize(value)
Exemplo n.º 9
0
def test_payment_date():
    from autonomie.models.task.invoice import Payment
    schema = SQLAlchemySchemaNode(Payment, includes=('date', ))
    schema = schema.bind()
    value = {'date': NOW.isoformat()}
    assert schema.deserialize(value) == {'date': NOW}
    value = {}
    with pytest.raises(colander.Invalid):
        schema.deserialize(value)
Exemplo n.º 10
0
def test_task_line_quantity():
    from autonomie.models.task.task import TaskLine
    schema = SQLAlchemySchemaNode(TaskLine, includes=('quantity', ))
    schema = schema.bind()
    value = {'quantity': 1}
    assert schema.deserialize(value) == value
    value = {}
    with pytest.raises(colander.Invalid):
        schema.deserialize(value)
Exemplo n.º 11
0
def test_task_date():
    import datetime
    from autonomie.models.task.task import Task
    schema = SQLAlchemySchemaNode(Task, includes=('date', ))
    schema = schema.bind()
    value = {'date': datetime.date.today().isoformat()}
    assert schema.deserialize(value) == {'date': datetime.date.today()}
    value = {}
    with pytest.raises(colander.Invalid):
        schema.deserialize(value)
Exemplo n.º 12
0
def test_task_line_unity(unity):
    from autonomie.models.task.task import TaskLine
    schema = SQLAlchemySchemaNode(TaskLine, includes=('unity', ))
    schema = schema.bind()
    value = {'unity': u"Mètre"}
    assert schema.deserialize(value) == value
    value = {'unity': u"Panies"}
    with pytest.raises(colander.Invalid):
        schema.deserialize(value)
    value = {}
    schema.deserialize(value)
Exemplo n.º 13
0
def test_task_payment_conditions():
    from autonomie.models.task.estimation import Task
    schema = SQLAlchemySchemaNode(Task, includes=('payment_conditions', ))
    schema = schema.bind()

    value = {'payment_conditions': u"À réception de facture"}
    assert schema.deserialize(value) == value

    value = {}
    with pytest.raises(colander.Invalid):
        schema.deserialize(value)
Exemplo n.º 14
0
def test_cancelinvoice_invoice_id():
    from autonomie.models.task.invoice import CancelInvoice
    schema = SQLAlchemySchemaNode(CancelInvoice, includes=('invoice_id', ))
    schema = schema.bind()

    value = {'invoice_id': 5}
    assert schema.deserialize(value) == value

    value = {}
    with pytest.raises(colander.Invalid):
        schema.deserialize(value)
Exemplo n.º 15
0
def test_payment_bank_id(bank):
    from autonomie.models.task.invoice import Payment
    schema = SQLAlchemySchemaNode(Payment, includes=('bank_id', ))
    schema = schema.bind()

    value = {'bank_id': bank.id}
    assert schema.deserialize(value) == value

    value = {'bank_id': bank.id + 1}
    with pytest.raises(colander.Invalid):
        schema.deserialize(value)
Exemplo n.º 16
0
def test_estimation_signed_status():
    from autonomie.models.task.estimation import Estimation
    schema = SQLAlchemySchemaNode(Estimation, includes=('signed_status', ))
    schema = schema.bind()

    value = {'signed_status': u"signed"}
    assert schema.deserialize(value) == value

    value = {'signed_status': u"error"}
    with pytest.raises(colander.Invalid):
        schema.deserialize(value)
Exemplo n.º 17
0
def test_task_line_cost():
    from autonomie.models.task.task import TaskLine
    schema = SQLAlchemySchemaNode(TaskLine, includes=('cost', ))
    schema = schema.bind()
    value = {'cost': 12.50}
    assert schema.deserialize(value) == {'cost': 1250000}
    value = {'cost': 'a'}
    with pytest.raises(colander.Invalid):
        schema.deserialize(value)
    value = {}
    with pytest.raises(colander.Invalid):
        schema.deserialize(value)
Exemplo n.º 18
0
def test_task_address():
    from autonomie.models.task.task import Task
    schema = SQLAlchemySchemaNode(Task, includes=('address', ))
    schema = schema.bind()
    value = {'address': u"address"}
    assert schema.deserialize(value) == value
    value = {"address": u"<br /><p></p>\n"}
    with pytest.raises(colander.Invalid):
        schema.deserialize(value)
    value = {}
    with pytest.raises(colander.Invalid):
        schema.deserialize(value)
Exemplo n.º 19
0
def test_discount_line_amount():
    from autonomie.models.task.task import DiscountLine
    schema = SQLAlchemySchemaNode(DiscountLine, includes=('amount', ))
    schema = schema.bind()
    value = {'amount': 12.50}
    assert schema.deserialize(value) == {'amount': 1250000}
    value = {'amount': 'a'}
    with pytest.raises(colander.Invalid):
        schema.deserialize(value)
    value = {}
    with pytest.raises(colander.Invalid):
        schema.deserialize(value)
Exemplo n.º 20
0
def test_task_line_tva(tva):
    from autonomie.models.task.task import TaskLine
    schema = SQLAlchemySchemaNode(TaskLine, includes=('tva', ))
    schema = schema.bind()
    value = {'tva': 20.00}
    assert schema.deserialize(value) == {'tva': 2000}
    value = {'tva': 21.00}
    with pytest.raises(colander.Invalid):
        schema.deserialize(value)
    value = {}
    with pytest.raises(colander.Invalid):
        schema.deserialize(value)
Exemplo n.º 21
0
def test_task_line_product_id(config, request_with_config, estimation,
                              product):
    from autonomie.models.task.task import TaskLine
    schema = SQLAlchemySchemaNode(TaskLine, includes=('product_id', ))
    request_with_config.context = estimation
    schema = schema.bind(request=request_with_config)
    value = {'product_id': product.id}
    assert schema.deserialize(value) == value
    value = {'product_id': product.id + 1}
    with pytest.raises(colander.Invalid):
        schema.deserialize(value)
    value = {}
    assert schema.deserialize(value) == value
Exemplo n.º 22
0
def test_estimation_paymentDisplay():
    from autonomie.models.task.estimation import Estimation

    schema = SQLAlchemySchemaNode(Estimation, includes=('paymentDisplay', ))
    schema = schema.bind()

    value = {'paymentDisplay': u'SUMMARY'}
    assert schema.deserialize(value) == value

    value = {}
    assert schema.deserialize(value) == {'paymentDisplay': u'NONE'}

    value = {'paymentDisplay': u'ERROR'}
    with pytest.raises(colander.Invalid):
        schema.deserialize(value)
Exemplo n.º 23
0
def test_payment_remittance_amount():
    from autonomie.models.task.invoice import Payment
    schema = SQLAlchemySchemaNode(Payment, includes=('remittance_amount', ))
    schema = schema.bind()

    value = {}
    with pytest.raises(colander.Invalid):
        schema.deserialize(value)

    value = {'remittance_amount': "test"}
    assert schema.deserialize(value) == value

    value = {}
    with pytest.raises(colander.Invalid):
        schema.deserialize(value)
Exemplo n.º 24
0
def test_payment_mode(mode):
    from autonomie.models.task.invoice import Payment
    schema = SQLAlchemySchemaNode(Payment, includes=('mode', ))
    schema = schema.bind()

    value = {'mode': mode.label}
    assert schema.deserialize(value) == value

    value = {'mode': "error"}
    with pytest.raises(colander.Invalid):
        schema.deserialize(value)

    value = {}
    with pytest.raises(colander.Invalid):
        schema.deserialize(value)
Exemplo n.º 25
0
def test_task_line_groups(tva, unity):
    from autonomie.models.task.task import Task
    schema = SQLAlchemySchemaNode(Task, includes=('line_groups', ))
    schema = schema.bind()
    value = {'line_groups': []}
    with pytest.raises(colander.Invalid):
        schema.deserialize(value)
    value = {
        'line_groups': [{
            'task_id':
            5,
            'title':
            u"title",
            'description':
            u"description",
            "order":
            5,
            'lines': [{
                'cost': 15,
                'tva': 20,
                'description': u'description',
                'unity': u"Mètre",
                "quantity": 5,
                "order": 2,
            }]
        }]
    }
    expected_value = {
        'line_groups': [{
            'task_id':
            5,
            'title':
            u"title",
            'description':
            u"description",
            "order":
            5,
            'lines': [{
                'cost': 1500000,
                'tva': 2000,
                'description': u'description',
                'unity': u"Mètre",
                "quantity": 5.0,
                "order": 2,
            }]
        }]
    }
    assert schema.deserialize(value) == expected_value
Exemplo n.º 26
0
def test_discount_line(tva):
    from autonomie.models.task.task import DiscountLine
    schema = SQLAlchemySchemaNode(DiscountLine)
    schema = schema.bind()
    value = {
        'task_id': 5,
        'description': u"description",
        "amount": 5,
        "tva": 20.0
    }
    assert schema.deserialize(value) == {
        'task_id': 5,
        'description': u"description",
        "amount": 500000,
        "tva": 2000
    }
Exemplo n.º 27
0
def test_estimation_deposit():
    from autonomie.models.task.estimation import Estimation

    schema = SQLAlchemySchemaNode(Estimation, includes=('deposit', ))
    schema = schema.bind()

    value = {'deposit': 15}
    assert schema.deserialize(value) == value

    value = {'deposit': 150}
    with pytest.raises(colander.Invalid):
        schema.deserialize(value)

    value = {'deposit': -1}
    with pytest.raises(colander.Invalid):
        schema.deserialize(value)
Exemplo n.º 28
0
def validate_cancelinvoice(cancelinvoice_object, request):
    """
    Globally validate an cancelinvoice_object

    :param obj cancelinvoice_object: An instance of CancelInvoice
    :param obj request: The pyramid request
    :raises: colander.Invalid

    try:
        validate_cancelinvoice(est, self.request)
    except colander.Invalid as err:
        error_messages = err.messages
    """
    schema = SQLAlchemySchemaNode(CancelInvoice)
    schema = schema.bind(request=request)
    appstruct = cancelinvoice_object.__json__(request)
    cstruct = schema.deserialize(appstruct)
    return cstruct
Exemplo n.º 29
0
def validate_estimation(estimation_object, request):
    """
    Globally validate an estimation_object

    :param obj estimation_object: An instance of Estimation
    :param obj request: The pyramid request
    :raises: colander.Invalid

    try:
        validate_estimation(est, self.request)
    except colander.Invalid as err:
        error_messages = err.messages
    """
    schema = SQLAlchemySchemaNode(Estimation)
    schema = schema.bind(request=request)
    appstruct = estimation_object.__json__(request)
    cstruct = schema.deserialize(appstruct)
    return cstruct
Exemplo n.º 30
0
def test_payment_amount():
    from autonomie.models.task.invoice import Payment
    schema = SQLAlchemySchemaNode(Payment, includes=('amount', ))
    schema = schema.bind()

    value = {}
    with pytest.raises(colander.Invalid):
        schema.deserialize(value)

    value = {'amount': 12.5}
    assert schema.deserialize(value) == {'amount': 1250000}

    value = {'amount': 'a'}
    with pytest.raises(colander.Invalid):
        schema.deserialize(value)
    value = {}
    with pytest.raises(colander.Invalid):
        schema.deserialize(value)