Skip to main content

Python wrapper for SomConnexio's MM Proxy (using REST API)

Project description

pipeline status coverage report

:warning: WORK IN PROGRESS :warning:

This library is a Python wrapper for accessing Somconnexio's Odoo (Odoo v12 with customizations). More info about the customizations in SomConnexio Odoo module.

Resources

  • AssetConsumption - Asset consumption

Installation

$ pip install mm-proxy-python-client

Configuration Environment

You need define the mm-proxy basic autenthication user and password and the host URL as environment variables. You need to define:

MM_PROXY_BASEURL=<YOUR MM-PROXY HOST>/api
MM_PROXY_USER=<YOUR MM-PROXY BASIC AUTH USER>
MM_PROXY_PASSWORD=<YOUR MM-PROXY BASIC AUTH PASSWORD>

If this envvars are not defined, a exception will be raised with the name of the envvar not defined.

Usage

Get mobile consumption

>>> from mm_proxy_python_client.resources.mobile_consumption import MobileConsumption
>>>
>>> consumption = MobileConsumption.get(asset_id="", phone_number="666888999", start_date="2023-12-01", end_date="2023-13-31")
>>> consumption.asset_id
123
>>> consumption.tariffs[0].dataTotal
"10240"

Development

Setup environment

  1. Install pyenv
curl https://pyenv.run | bash
  1. Build the Python version
pyenv install  3.8.13
  1. Create a virtualenv
pyenv virtualenv 3.8.13 mm-proxy-python-client
  1. Install dependencies
pyenv exec pip install -r requirements-dev.txt
  1. Install pre-commit hooks
pyenv exec pre-commit install

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 actually call the mm-proxy local client in order to create or rewrite cassettes using the next pyenv commands, we need to first change the conftest.py file and temporally provide the actual mm-proxy user and password.

monkeypatch.setenv("MM_PROXY_PASSWORD", "<ACTUAL_MM_PROXY_PASSWORD>")

⚠️ Do not commit this change!

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 pre-commit to execute Flake8, yamllint (for the cassetes) and Black as formatter.

Release process

Update CHANGELOG.md following this steps:

  1. Add any entries missing from merged merge requests.
  2. Duplicate the [Unreleased] header.
  3. 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:

  1. Update the __version__ var in __init__.py matching the version you specified in the CHANGELOG.
  2. Open a merge request with these changes for the team to approve
  3. Merge it, add a git tag on that merge commit and push it.
  4. Once the pipeline has successfully passed, go approve the publish step.

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

mm-proxy-python-client-0.1.0.tar.gz (9.3 kB view details)

Uploaded Source

Built Distribution

mm_proxy_python_client-0.1.0-py2.py3-none-any.whl (10.6 kB view details)

Uploaded Python 2Python 3

File details

Details for the file mm-proxy-python-client-0.1.0.tar.gz.

File metadata

  • Download URL: mm-proxy-python-client-0.1.0.tar.gz
  • Upload date:
  • Size: 9.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.8.18

File hashes

Hashes for mm-proxy-python-client-0.1.0.tar.gz
Algorithm Hash digest
SHA256 39d158262bc0c1aa74e22bdd19183f3a1b4053a5c326fc550c0c4fe15e51d37d
MD5 bf15d0520701433b43b532cf04d1cfc3
BLAKE2b-256 ea1d04044aa8f9c3981c4ddcb8b4fb93a74d98653e5a945d1b922529319b7cb5

See more details on using hashes here.

File details

Details for the file mm_proxy_python_client-0.1.0-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for mm_proxy_python_client-0.1.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 c7346947c94644afd81e54f24615a5266d1794c4c2abdc1e89fe412fe8ccdfdc
MD5 93ad8804fe09645a1af532a21638d82a
BLAKE2b-256 ddac39dd2863a6bcc465de506d681190e7e396cddf9a5cbb6c5a8cf39680e691

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page