예제 #1
0
def test_fail_shipping_label_same_addresses(posting_card, sender_address,
                                            tracking_code, package):
    with pytest.raises(exceptions.InvalidAddressesError):
        posting.ShippingLabel(posting_card,
                              sender_address,
                              sender_address,
                              SERVICE_SEDEX,
                              package=package,
                              tracking_code=tracking_code)
예제 #2
0
def test_posted_shipping_label(posting_card, sender_address, receiver_address,
                               package, receipt):
    service = Service.get(SERVICE_SEDEX)
    shipping_label = posting.ShippingLabel(posting_card=posting_card,
                                           sender=sender_address,
                                           receiver=receiver_address,
                                           service=service,
                                           package=package,
                                           tracking_code="PD12345678 BR",
                                           receipt=receipt)
    assert shipping_label.receipt is not None
    assert shipping_label.posted
예제 #3
0
def test_shipping_label_with_min_declared_value_sedex(posting_card, sender_address, receiver_address, package):
    service = Service.get(SERVICE_SEDEX)
    shipping_label = posting.ShippingLabel(
        posting_card=posting_card,
        sender=sender_address,
        receiver=receiver_address,
        service=service,
        package=package,
        tracking_code="PD12345678 BR",
        value=Decimal("0"),
        extra_services=[EXTRA_SERVICE_VD],
    )
    assert shipping_label.value == Decimal("18.00")
예제 #4
0
def test_basic_default_shipping_label(posting_card, sender_address, receiver_address, package):
    shipping_label = posting.ShippingLabel(
        posting_card=posting_card,
        sender=sender_address,
        receiver=receiver_address,
        service=4162,  # SERVICE_SEDEX_CODE
        package=package,
        tracking_code="PD12345678 BR",
    )

    assert shipping_label.service == Service.get(SERVICE_SEDEX)
    assert shipping_label.tracking_code.code == "PD123456785BR"
    assert len(shipping_label.extra_services) == 1
예제 #5
0
def test_shipping_label_get_datamatrix_info_with_complement_display(
        posting_card, sender_address, receiver_address, package):
    receiver_address.complement = '15 • andar'
    shipping_label = posting.ShippingLabel(
        posting_card=posting_card,
        sender=sender_address,
        receiver=receiver_address,
        service=4162,
        package=package,
        tracking_code="PD12345678 BR",
    )
    datamatrix = shipping_label.get_datamatrix_info()
    assert '000000000000015andar' in datamatrix
예제 #6
0
def test_shipping_label_with_declared_value(extra_service_vd, posting_card, sender_address, receiver_address, package):
    service = Service.get(SERVICE_SEDEX)
    shipping_label = posting.ShippingLabel(
        posting_card=posting_card,
        sender=sender_address,
        receiver=receiver_address,
        service=service,
        package=package,
        tracking_code="PD12345678 BR",
        value=service.max_declared_value - Decimal("1.00"),
        extra_services=[extra_service_vd],
    )
    assert ExtraService.get(extra_service_vd) in shipping_label.extra_services
예제 #7
0
def test_fail_shipping_label_with_invalid_declared_value(posting_card, sender_address, receiver_address, package):
    service = Service.get(SERVICE_SEDEX)
    shipping_label = posting.ShippingLabel(
        posting_card=posting_card,
        sender=sender_address,
        receiver=receiver_address,
        service=service,
        package=package,
        tracking_code="PD12345678 BR",
        value=service.max_declared_value + Decimal("1.00"),
    )

    with pytest.raises(exceptions.MaximumDeclaredValueError):
        shipping_label.add_extra_service(ExtraService.get(EXTRA_SERVICE_VD))
예제 #8
0
def test_basic_shipping_label(posting_card, sender_address, receiver_address,
                              tracking_code, package):
    shipping_label = posting.ShippingLabel(
        posting_card=posting_card,
        sender=sender_address,
        receiver=receiver_address,
        service=SERVICE_SEDEX,
        extra_services=[EXTRA_SERVICE_AR],
        tracking_code=tracking_code,
        logo=os.path.join(FIXTURESDIR, "test_logo.jpg"),
        order="123",
        invoice_number="321",
        invoice_series="A1",
        invoice_type="",
        package=package,
        text="Hello World!",
        latitude=-25.4131980,
        longitude=-49.2584896,
    )

    assert shipping_label.posting_card == posting_card
    assert shipping_label.sender == sender_address
    assert shipping_label.receiver == receiver_address

    assert shipping_label.service == Service.get(SERVICE_SEDEX)
    assert shipping_label.get_service_name() == "SEDEX"

    assert shipping_label.extra_services == [
        ExtraService.get(EXTRA_SERVICE_RR),
        ExtraService.get(EXTRA_SERVICE_AR)
    ]

    assert shipping_label.tracking_code == tracking_code
    assert shipping_label.get_tracking_code().replace(" ", "") == str(
        shipping_label.tracking_code)

    assert isinstance(shipping_label.logo, Image)

    # noinspection PyUnresolvedReferences
    assert shipping_label.logo.filename == os.path.join(
        FIXTURESDIR, "test_logo.jpg")

    assert shipping_label.order == "123"
    assert shipping_label.get_order() == "123"

    assert shipping_label.invoice_number == "321"
    assert shipping_label.get_invoice() == "321"

    assert shipping_label.get_contract_number() == "9911222777"
    assert shipping_label.get_package_sequence() == "{}/{}".format(
        *shipping_label.package.sequence)
    assert shipping_label.get_weight() == "{}g".format(
        shipping_label.package.weight)
    assert shipping_label.package.posting_list_volumetric_weight == Decimal(
        "0.00")

    assert shipping_label.text == "Hello World!"

    assert shipping_label.latitude == -25.4131980
    assert shipping_label.longitude == -49.2584896

    assert shipping_label.posting_list_group == 0

    assert shipping_label.get_symbol_filename().endswith("/express.gif")
    assert isinstance(shipping_label.symbol, Image)

    assert len(shipping_label.get_datamatrix_info()
               ) == 164  # datamatrix info size accordingly with documentation
    assert shipping_label.get_sender_data().count("<br/>") >= 2
    assert shipping_label.get_receiver_data().count("<br/>") >= 2

    assert repr(shipping_label) == "<ShippingLabel tracking='{!s}'>".format(
        shipping_label.tracking_code)