Skip to main content

Wrappers over Factory Boy's Django Factories

Project description

https://circleci.com/gh/jamescooke/factory_djoy.svg?style=shield https://img.shields.io/pypi/pyversions/factory_djoy.svg?maxAge=2592000 https://img.shields.io/badge/license-MIT-blue.svg

Simple wrappers on top of Factory Boy for Django. Works on latest flavour of Django 1.9, with Factory Boy version 2 or greater.

Installation

Install with pip:

pip install factory_djoy

Usage

UserFactory

UserFactory provides a simple wrapper over the django.contrib.auth.User model. You can use it anywhere that you need a User instance to be created in your project’s factories.

Given a simple test that requires a User instance, UserFactory can generate that at test time. This example is a bit contrived, but it works:

from django.test import TestCse
from factory_djoy import UserFactory


class TestUser(TestCase):

    def test_happy(self):
        """
        User can log in
        """
        UserFactory(username='user_1', password='test')

        result = self.client.login(username='user_1', password='test')

        self.assertIs(result, True)

Motivation: Testing first

Primarily the goal of factories is to provide “easy to generate” data at test time - however this data must be 100% reliable, otherwise it’s too easy to create false positive and false negative test results.

Therefore, since it’s so important that each factory creates valid data, these wrappers are tested rigorously using Django projects configured in the test_framework folder.

See also

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

factory_djoy-0.2.tar.gz (2.4 kB view hashes)

Uploaded Source

Supported by

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