def test_service_getter(): service = Service.get(40215) assert service.id == 104707 assert service.code == '40215' assert service.description == "SEDEX 10" assert service.category == "SERVICO_COM_RESTRICAO" assert Service.get(service) == service
def test_service_getter(): service = Service.get(40215) assert service.id == 104707 assert service.code == '40215' assert service.description == "SEDEX 10" assert service.category == "SERVICO_COM_RESTRICAO" assert Service.get(service) == service
def test_package_weight_validation(): posting.Package.validate(posting.Package.TYPE_BOX, 12, 10, 20, service=Service.get(SERVICE_SEDEX), weight=10000) posting.Package.validate( posting.Package.TYPE_BOX, 12, 10, 20, service=Service.get(10065), # 10065 - service with no max weight weight=50000, )
def test_package_weight_validation(): posting.Package.validate( posting.Package.TYPE_BOX, 12, 10, 20, service=Service.get(SERVICE_SEDEX), weight=10000, ) posting.Package.validate( posting.Package.TYPE_BOX, 12, 10, 20, service=Service.get(10065), # 10065 - service with no max weight weight=50000, )
def test_fail_invalid_declared_value_in_pac(): service = Service.get(SERVICE_PAC) with pytest.raises(MaximumDeclaredValueError): service.validate_declared_value(service.max_declared_value + 1) with pytest.raises(MinimumDeclaredValueError): service.validate_declared_value(service.min_declared_value - 1)
def test_fail_invalid_declared_value_in_pac(): service = Service.get(SERVICE_PAC) with pytest.raises(MaximumDeclaredValueError): service.validate_declared_value(service.max_declared_value + 1) with pytest.raises(MinimumDeclaredValueError): service.validate_declared_value(service.min_declared_value - 1)
def test_fail_package_weight_validation(): with pytest.raises(exceptions.InvalidMaxPackageWeightError): posting.Package.validate( posting.Package.TYPE_BOX, 12, 10, 20, service=Service.get(SERVICE_SEDEX), weight=50000, )
def test_fail_package_weight_validation(): with pytest.raises(exceptions.InvalidMaxPackageWeightError): posting.Package.validate(posting.Package.TYPE_BOX, 12, 10, 20, service=Service.get(SERVICE_SEDEX), weight=50000)
def getCodRastreamento (self): """ Adquire o código de rastreamento do objeto """ # Conexão com o webservice env = SigepEnvironment.objects.get(ativo=True) cliente = correios.Correios(username=env.usuario, password=env.senha, environment=env.ambiente) # Solicita ao SIGEP o código de rastreamento. user = User (env.nomeEmpresa, env.cnpj) service = Service.get(self.servico.codigo) self.codRastreamento = cliente.request_tracking_codes(user, service, 1)[0].code
def test_basic_service(): service = Service( code=40215, id=104707, description="SEDEX 10", category="SERVICO_COM_RESTRICAO", symbol="premium", max_weight=10000, ) assert service.id == 104707 assert service.code == '40215' assert service.display_name == "SEDEX 10" assert service.description == "SEDEX 10" assert service.category == "SERVICO_COM_RESTRICAO" assert service.get_symbol_filename().endswith("/premium.gif") assert service.get_symbol_filename("png").endswith("/premium.png") assert isinstance(service.symbol_image, Image) assert service.max_weight == 10000
def test_basic_service(): service = Service( code=40215, id=104707, description="SEDEX 10", category="SERVICO_COM_RESTRICAO", symbol="premium", max_weight=10000, ) assert service.id == 104707 assert service.code == '40215' assert service.display_name == "SEDEX 10" assert service.description == "SEDEX 10" assert service.category == "SERVICO_COM_RESTRICAO" assert service.get_symbol_filename().endswith("/premium.gif") assert service.get_symbol_filename("png").endswith("/premium.png") assert isinstance(service.symbol_image, Image) assert service.max_weight == 10000
def test_declared_value(posting_list, shipping_label): shipping_label.extra_services.append(ExtraService.get(EXTRA_SERVICE_VD)) shipping_label.real_value = 10.29 posting_list.add_shipping_label(shipping_label) serializer = correios.PostingListSerializer() document = serializer.get_document(posting_list) serializer.validate(document) xml = serializer.get_xml(document) assert shipping_label.service == Service.get(SERVICE_PAC) assert b"<codigo_servico_adicional>019</codigo_servico_adicional>" in xml assert b"<valor_declarado>18,00</valor_declarado>" in xml
def test_declared_value(extra_service_vd, code, posting_list, shipping_label): shipping_label.extra_services.append(ExtraService.get(extra_service_vd)) shipping_label.real_value = 10.29 posting_list.add_shipping_label(shipping_label) serializer = PostingListSerializer() document = serializer.get_document(posting_list) serializer.validate(document) xml = serializer.get_xml(document) assert shipping_label.service == Service.get(SERVICE_PAC) assert b"<codigo_servico_adicional>%b</codigo_servico_adicional>" % code in xml assert b"<valor_declarado>19,50</valor_declarado>" in xml
def test_sanitize_service(): service = Service( code="40215 ", id=104707, description="SEDEX 10 ", category="SERVICO_COM_RESTRICAO", ) assert service.id == 104707 assert service.code == '40215' assert service.description == "SEDEX 10" assert service.category == "SERVICO_COM_RESTRICAO"
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
def test_declared_value_without_insurance_extra_service( posting_list, shipping_label): shipping_label.real_value = 10.29 posting_list.add_shipping_label(shipping_label) serializer = PostingListSerializer() document = serializer.get_document(posting_list) serializer.validate(document) xml = serializer.get_xml(document) assert shipping_label.service == Service.get(SERVICE_PAC) assert b"<codigo_servico_adicional>19</codigo_servico_adicional>" not in xml assert b"<codigo_servico_adicional>64</codigo_servico_adicional>" not in xml assert b"<codigo_servico_adicional>65</codigo_servico_adicional>" not in xml assert b"<valor_declarado>000,00</valor_declarado>" in xml
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
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")
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
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
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
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_SEDEX], ) assert shipping_label.value == Decimal("19.50")
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_SEDEX))
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))
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
def test_calculate_delivery_time(client): expected_delivery_time = 1 delivery_time = client.calculate_delivery_time(Service.get(SERVICE_SEDEX), '07192100', '80030001') assert expected_delivery_time == int(delivery_time)
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)
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)
def test_valid_insurance_code(insurance_code): service = Service.get(SERVICE_PAC) assert service.validate_insurance_declared_value(Decimal("0.00"), insurance_code) is True
def test_request_tracking_codes(client, user): result = client.request_tracking_codes(user, Service.get(SERVICE_SEDEX), quantity=10) assert len(result) == 10 assert len(result[0].code) == 13
def test_fail_invalid_insurance_code(insurance_code): service = Service.get(SERVICE_PAC) with pytest.raises(InvalidServiceDeclaredValue): service.validate_insurance_declared_value(Decimal("10.00"), insurance_code)
def test_calculate_delivery_time_service_not_allowed_for_path(client): expected_delivery_time = 0 delivery_time = client.calculate_delivery_time(Service.get(SERVICE_PAC), '01311300', '01311300') assert expected_delivery_time == int(delivery_time)