Python wrapper for Correos PreRegistro SOAP API
Project description
:warning: WORK IN PROGRESS :warning:
This library is a Python wrapper for accessing PreregistroEnvio Correos SOAP API.
You can find the complete documentation of the API here.
Operations
- PreRegistroEnvio - Customers will provide all the necessary data for pre-registering a shipment and will receive in return the pre-registered shipment code and label with which to label the shipment in the format that they requested (XML or base64 encoded PDF format)
Installation
$ pip install correos-preregistro
Configuration Environment
Usage
Create PreRegistroEnvio shipment
Create a preregistroenvio annd save a file with the shipment number in the name and the PDF label as content:
>>> from correos_preregistro.services.shipment import PreRegistrationShipment
>>> user = "utest"
>>> password = "ptest"
>>> client = RawClient(user, password)
>>> receiver = Receiver(
... name="Emilio Jose",
... surname="Marti Gomez",
... address="Cami del corrar, 51, Baix B",
... city="Moralla",
... state="Valencia",
... zip="03015",
... phone="666555444",
... email="emilio.jose@marti.com",
... lang="CA",
... sms_phone="666555444",
... )
>>> sender = Sender(
... name="SomConnexio",
... nif="F66380676",
... address="C/ de les Moreres, 119",
... city="El Prat de Llobregat",
... state="Barcelona",
... zip="08820",
... phone="931311728",
... email="serveis@somconnexio.coop",
... lang="CA",
... )
>>> package = Package(
... weight=1,
... postage_type="FP",
... product_code="S0132",
... delivery_modality="ST",
... weight_type="R",
)
>>> shipment = PreRegistrationShipment.create(
... client=client,
... code="XXX1",
... receiver=receiver,
... sender=sender,
... package=package,
... )
>>> shipment.shipment_code
"PQXXX10721392610108021C"
>>> label_file_name = "shipment_label_{}.pdf".format(shipment.shipment_code)
>>> f = open(shipment.get_pdf_label(), "wb")
>>> f.write(pdf_label)
>>> f.close()
Development
Setup environment
- Install
pyenv
curl https://pyenv.run | bash
- Build the Python version
pyenv install 3.7.13
- Create a virtualenv
pyenv virtualenv 3.7.13 correos-preregistro
- Install dependencies
pyenv exec pip install -r requirements.txt
- Install pre-commit hooks
pyenv exec pre-commit install
Install the package locally in development mode
When we are using this package in other projects, we need to install it to use as import in the other files. Install the package in development mode helps us to modify the package and use the new version in live in the other project.
pip install -e .
Test the HTTP request
We are using the HTTP recording plugin of Pytest: pytest-recording.
With VRC we can catch the HTTP responses and then, execute the tests using them.
To add a new test:
- Expose the needed envvars. Look for them at the Configuration Environment section
- Execute the tests using
pytest
command: - If you are writing a new test that is making requests, you should run:
$ pytest --record-mode=once path/to/your/test
- You might need to record requests for an specific tests. In that case make sure to only run the tests affected and run
$ pytest --record-mode=rewrite path/to/your/test
- Add the new
cassetes
to the commit and push them. - The CI uses the cassetes to emulate the HTTP response in the test.
Run test suite
$ tox
Formatting
We use Black as formatter.
First to commit, tun the black
command:
$ black .
All done! ✨ 🍰 ✨
29 files left unchanged.
Darker
Black is a great formatter, but to mantain your code without execute the black
command avery time, you can configure your IDE to use darker to format only the changed or added code when you save the file.
Release process
Update CHANGELOG.md following this steps:
- Add any entries missing from merged merge requests.
- Duplicate the
[Unreleased]
header. - Replace the second
Unreleased
with a version number followed by the current date. Copy the exact format from previous releases.
Then, you can release and publish the package to PyPi:
- Update the
__version__
var in__init__.py
matching the version you specified in the CHANGELOG. - Open a merge request with these changes for the team to approve
- Merge it, add a git tag on that merge commit and push it.
- Once the pipeline has successfully passed, your package had been published.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file correos-preregistro-0.0.6.tar.gz
.
File metadata
- Download URL: correos-preregistro-0.0.6.tar.gz
- Upload date:
- Size: 7.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.7.16
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9b705794772d6ce9219fd86bd0815c2f6404b324b169675627af39cc296a2d47 |
|
MD5 | 3837f1c98657ea9e78e4b0110c6bbd17 |
|
BLAKE2b-256 | 9d16b002d1432b6a0bb1c09d1551b6f01886d4c7ba5cd2217e183274098208ec |
File details
Details for the file correos_preregistro-0.0.6-py2.py3-none-any.whl
.
File metadata
- Download URL: correos_preregistro-0.0.6-py2.py3-none-any.whl
- Upload date:
- Size: 10.0 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.7.16
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f000f0376024705cdc018fe9fd5731dcfdb4977977b1c2229a95b6d10445bd97 |
|
MD5 | b7d28410fe2abc2c3308f213b570b75e |
|
BLAKE2b-256 | 57c1032ad8541006f662d54856722b7cbfe47e7483d310d2e435f33867be8b4d |