Welcome to Factory Boy Rest’s documentation!¶
A REST test fixtures replacement for Python.
This is intented to be used on functional tests, to create REST-based entities through the same Factories interface provided by Factory Boy
Contents:
Install¶
Basic Github checkout¶
If you want to download the latest development version, you can get it by cloning the git
respository and use the classic setuptools
installation:
git clone https://github.com/bertonha/factory-boy-rest.git
cd factory-boy-rest
python setup.py install
Usage¶
Defining factories¶
python
from urllib.parse import urljoin
import requests
from factory import fuzzy
from factory_rest import RestFactory
base_url = 'http://127.0.0.1:8000'
class UserFactory(RestFactory):
class Meta:
create_url = urljoin(base_url, '/v1/users/')
create_method = 'post'
request_session = requests.session()
first_name = 'John'
last_name = 'Doe'
admin = False
class UserFactory(RestFactory):
class Meta:
create_url = urljoin(base_url, '/v1/users/')
create_method = 'post'
request_session = requests.session()
first_name = 'Admin'
last_name = 'User'
admin = True
Contributing¶
Development Installation¶
Create a virtualenv:
mkproject --python=<fullpath_to_python_3> factory-boy-rest
Get the code:
git clone https://github.com/bertonha/factory-boy-rest.git .
Install it:
python setup.py develop
The last command enter your code in “Development Mode” it creates an
egg-link
in your virtualenv’s site-packages
making it available
on this environment sys.path
. For more info see setuptools development mode
Development and test dependencies¶
setup.py
will handle test dependencies, to install development use:
pip install -e .[dev]
Tests¶
You have many forms to run tests.
The following command will handle test dependencies installation. Perfect for first run.
python setup.py test
Don’t forget to run the test suite against all python versions before submit a pull request. It’s ease just do:
tox
If you want to run only for Python3 you can do:
tox -e py34