Skip to main content

No project description provided

Project description

Fake Store

ci

With fake-store, the implementation of a hexagonal architecture in python whose repositories are testable becomes very simple.

This library is able to make hydrated entities from yaml files. It will let use them directly. This is the ideal library for building your fake server that replaces your database in automatic tests.

class FakePetRepository:

    def __init__(self):
        self._store: List[Pet] = fake_store.load_collection(Pet, "pet.yml")

    def store(self, pet: Pet):
        self._store.append(pet)

    ...

The librarie takes care of :

  • loading nested object inside each other
  • converting objects to their native python type
  • take controle of objects generation through a factory
  • works well with dataclass and attrs
  • implement a share memory store and resettable memory store to share datasets between repositories

Getting started

pip install fake-store

The latest version

You can find the latest version to ...

git clone https://github.com/FabienArcellier/fake-store.git

Usage

Binding _class in definition with real python class

You can run the application with the following command

import fake_store
from myapp.domain.entity.pet import Pet

fake_store.bind_class(Pet.__name__, Pet)

Any objects that contains _class: Pet in definition will be instanciated as Pet

- __class: Pet
  name: "Ronny"
  status: available

- __class: Pet
  name: "Crane"
  status: unavailable

The class Pet has to defined it's __init__ method with the 2 keyword arguments. If an argument is missing or doesn't exist in the construct, it will raise an error

class Pet:

    def __init__(self, name: str, status: str):
        pass

look at examples/nested_fake_store.py

use a factory method instead of init method

see examples/factory_fake_store.py

use a memory store to share the same data between several repository

see examples/memory_store.py

use a resettable memory store to share the same data between several repository on automatic test

Data loading can become slower and slower over time. If it is played between each test, it adds 1s of overhead on every test. In a CI or on the development workstation, it is interesting to avoid this loading time.

The ResettableStore class allows between each test to restore the content of the store to its original state in one step negligible with the call to reset_store.

see examples/resettable_store.py

Developper guideline

activate                       activate the virtualenv associate with this project
coverage                       output the code coverage in htmlcov/index.html
help                           provides cli help for this makefile (default)
install_requirements_dev       install pip requirements for development
install_requirements           install pip requirements based on requirements.txt
lint                           run pylint
tests                          run automatic tests
tests_units                    run only unit tests
twine                          publish on pypi
update_requirements            update the project dependencies based on setup.py declaration

Install development environment

Use make to instanciate a python virtual environment in ./venv and install the python dependencies.

make install_requirements_dev

Install production environment

make install_requirements

Initiate or update the library requirements

If you want to initiate or update all the requirements install_requires declared in setup.py and freeze a new Pipfile.lock, use this command

make update_requirements

Activate the python environment

When you setup the requirements, a venv directory on python 3 is created. To activate the venv, you have to execute :

make venv
source venv/bin/activate

Run the linter and the unit tests

Before commit or send a pull request, you have to execute pylint to check the syntax of your code and run the unit tests to validate the behavior.

make lint
make tests

Contributors

  • Fabien Arcellier

License

MIT License

Copyright (c) 2018 Fabien Arcellier

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

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

fake-store-0.2.tar.gz (5.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

fake_store-0.2-py3-none-any.whl (6.7 kB view details)

Uploaded Python 3

File details

Details for the file fake-store-0.2.tar.gz.

File metadata

  • Download URL: fake-store-0.2.tar.gz
  • Upload date:
  • Size: 5.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

File hashes

Hashes for fake-store-0.2.tar.gz
Algorithm Hash digest
SHA256 0c9507d4b8ab849fcdf478c37e8bdd1b3141fa4297f889976829b21ae0c734d4
MD5 7c3fec850d627c43a147e947fea2aa85
BLAKE2b-256 78a569e637047baf159eee188236d66969119dd483476f1479a6446aa971d33a

See more details on using hashes here.

File details

Details for the file fake_store-0.2-py3-none-any.whl.

File metadata

  • Download URL: fake_store-0.2-py3-none-any.whl
  • Upload date:
  • Size: 6.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

File hashes

Hashes for fake_store-0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 054fb191481b08eac2c7642ee9f5b56ad6251ab71654c37c6efab12127b09de6
MD5 277c0219bfbd089521588116d37aa712
BLAKE2b-256 bcf6f3631f375036e9a28b1cedca49f66f6370ee91b997e53b2f9ea68d4e6ce8

See more details on using hashes here.

Supported by

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