Beispiel #1
0
def test_load_package_fields(model_builder, post_info_data, expected_fields, package_type):
    post_info = fromstring(post_info_data)
    post_info.dimensao_objeto.tipo_objeto = package_type

    package_data = model_builder._build_package_data(post_info)

    assert set(package_data.keys()) == set(expected_fields)
Beispiel #2
0
def test_build_receipt_when_status_processed(model_builder, post_info_data):
    post_info = fromstring(post_info_data)

    receipt = model_builder.build_receipt(post_info)
    assert receipt is not None
    assert receipt.number == 155305650
    assert receipt.real_value == "14.99"
    assert receipt.real_post_date == "20190603"
Beispiel #3
0
def test_get_post_info(client):
    result = client._auth_call('solicitaXmlPlp', 875057)

    data = fromstring(result.encode('iso-8859-1'))

    user = client.get_user(
        contract_number=data.remetente.numero_contrato.text,
        posting_card_number=data.plp.cartao_postagem.text
    )

    post_info = client.get_post_info(number=875057)
    assert isinstance(post_info, PostInfo)
    assert str(post_info.value) == data.plp.valor_global.text

    postal_unit = post_info.postal_unit
    assert isinstance(postal_unit, PostalUnit)
    assert postal_unit.code == data.plp.mcu_unidade_postagem
    assert postal_unit.description == data.plp.nome_unidade_postagem

    posting_list = post_info.posting_list
    assert isinstance(posting_list, PostingList)
    assert posting_list.number == data.plp.id_plp

    shipping_labels = posting_list.shipping_labels
    assert len(shipping_labels) == len(data.objeto_postal)

    for obj in data.objeto_postal:
        tracking_code = TrackingCode.create(obj.numero_etiqueta.text)
        assert tracking_code.short in shipping_labels
        label = shipping_labels[tracking_code.short]

        extra_info = obj.nacional
        billing = getattr(extra_info, 'valor_a_cobrar', None) or '0.00'
        assert label.billing == to_decimal(billing)
        assert label.invoice_number == extra_info.numero_nota_fiscal
        assert label.invoice_series == extra_info.serie_nota_fiscal

        extra_services = obj.servico_adicional

        declared_value = getattr(extra_services, 'valor_declarado', None)

        invoice_value = getattr(extra_info, 'valor_nota_fiscal', None)

        assert label.real_value == to_decimal(
            declared_value or invoice_value or '0.00'
        )

        assert label.text == extra_info.descricao_objeto
        posting_card_number = user.contracts[0].posting_cards[0].number
        assert label.posting_card.number == posting_card_number

        sender = data.remetente

        assert label.sender.email == sender.email_remetente.text
        assert label.sender.name == sender.nome_remetente.text
        assert label.sender.street == sender.logradouro_remetente.text
        assert label.sender.number == sender.numero_remetente.text
        assert label.sender.complement == sender.complemento_remetente.text
        assert label.sender.neighborhood == sender.bairro_remetente.text
        assert label.sender.zip_code == sender.cep_remetente.text
        assert label.sender.city == sender.cidade_remetente.text
        assert label.sender.state == sender.uf_remetente.text
        assert (
            label.sender.phone.number == (sender.telefone_remetente.text or '')
        )

        receiver = obj.destinatario

        assert label.receiver.email == (receiver.email_destinatario.text or '')

        assert label.receiver.name == receiver.nome_destinatario.text
        assert label.receiver.street == receiver.logradouro_destinatario.text
        assert label.receiver.number == receiver.numero_end_destinatario.text
        assert (
            label.receiver.complement ==
            (receiver.complemento_destinatario.text or '')
        )
        assert (
            label.receiver.neighborhood == extra_info.bairro_destinatario.text
        )
        assert label.receiver.zip_code == extra_info.cep_destinatario.text
        assert label.receiver.city == extra_info.cidade_destinatario.text
        assert label.receiver.state == extra_info.uf_destinatario.text
        assert (
            label.receiver.phone.number ==
            (receiver.celular_destinatario.text or '')
        )

        assert len(label.extra_services) == len(extra_services)

        for service in extra_services.codigo_servico_adicional:
            assert service in label.extra_services

        package = label.package

        assert package.service == obj.codigo_servico_postagem

        dimensions = obj.dimensao_objeto

        assert package.package_type == dimensions.tipo_objeto

        assert package.real_diameter == float(
            dimensions.dimensao_diametro.text.replace(',', '.')
        )

        assert package.real_height == float(
            dimensions.dimensao_altura.text.replace(',', '.')
        )

        assert package.real_length == float(
            dimensions.dimensao_comprimento.text.replace(',', '.')
        )

        assert package.real_weight == float(obj.peso.text.replace(',', '.'))
        assert package.real_width == float(
            dimensions.dimensao_largura.text.replace(',', '.')
        )

        receipt = label.receipt

        assert receipt.number == obj.numero_comprovante_postagem
        assert receipt.real_post_date == obj.data_postagem_sara.text
        assert receipt.real_value == obj.valor_cobrado.text
Beispiel #4
0
def test_build_receipt_when_status_unprocessed(status, model_builder, post_info_data):
    post_info = fromstring(post_info_data)
    post_info.status_processamento = status

    receipt_data = model_builder.build_receipt(post_info)
    assert receipt_data is None