No longer maintained, please migrate to model_bakery

Overview

Model Mommy: Smart fixtures for better tests

Test Status Latest PyPI version

IMPORTANT: Model Mommy is no longer maintained and was replaced by Model Bakery. Please, consider migrating your project to use the new lib.

Model Mommy's creator and the maintainers decided to rename the project to not reinforce gender stereotypes for women in technology. You can read more about this subject here.

Maintainers

Creator

Comments
  • Better coordination of Foreign Key model use during generation

    Better coordination of Foreign Key model use during generation

    We have a multi-tenant app where all models are ultimately owned by a customer model, but some of the models are only indirectly owned by that customer model, some pseudocode:

    class Job(Model):  has foreignkey to Customer
    class Call(Model): has foreignkey to Job
      contains PositionTitle(Model): has foreignkey to Customer
    class Position(Model): has foreignkey to Call
    class Assignment(Model): has foreignkey to Position
    

    That isn't all the models in my code, but when I do

    mommy.make(Assignment) 
    

    mommy creates 32 Customer objects because of the generation. It would be nice if you could say something like

    with mommy.register({"customers.customer": mommy.make(Customer)}):
        assignment = mommy.make(Assignment)
    

    Admittedly the syntax needs some work, and you would probably need to do with nesting of the with clauses. Recipes might work for this case, but it seems like a HUGE amount of overhead for something simple like this.

    opened by mark0978 18
  • Feature/custom field value generation api #90

    Feature/custom field value generation api #90

    Started some code on a feature branch. Needs more work and discussion. Doing a pull_request for further discussion following #90.

    Not sure about the decorators. They don't really make sense, as we aren't really wrapping the fields.

    def gen_func():
        return "random_value"
    
    class CustomField(models.Fields):
        ... #some field code
    
    add_value_generator(gen_func, CustomField)
    

    Is the same LOC. But make more sense semantically, than

    def gen_func():
        return "random_value"
    
    @custom_field_gen("gen_func")
    class CustomField(models.Fields):
        ... #some field code
    

    I do still see a usecase for the context_manager as it is better at handling exception cases than a single_use parameter would.

    And what about a model_field param? When I did the model param, I thought, about a model using the same CustomField multiple times for different model_fields. But when implementing that, I felt like I was redoing stuff, that can already be done pretty well with recipes.

    opened by CharString 16
  • Enabling spatial support into model mommy

    Enabling spatial support into model mommy

    Hello @vandersonmota.

    This is a great project, but in my day to day work uses a lot of geospatial information, so I need model_mommy to generate spatial data as well.

    This a first draft that includes a point generator, using the already consolidated formulaes used by model_mommy.

    In here I've updated the association between a field type and generators and created the spatial generator.

    perhaps there are other ways to handle this, but let me know.

    opened by george-silva 14
  • New feature: objects creation using multiple attrs values

    New feature: objects creation using multiple attrs values

    I'll explain the idea given by @henriquebastos during our last lunch. Suppose that we have the following model:

    class Person(models.Model):
        name = models.CharField(max_length=60)
        age = models.PositiveIntegerField()
    

    Now, imagine some test situation that we need to create 4 objects with the same age but different, but not random, names. Today, the way we can achieve this with model mommy is as following:

    person1 = mommy.make(Person, age=20, name='bob')
    person2 = mommy.make(Person, age=20, name='alice')
    person3 = mommy.make(Person, age=20, name='john')
    person4 = mommy.make(Person, age=20, name='peter')
    

    There is a lot of code repetition on the previous snippet and maybe we can improve this. This issue is to start this discussion to explore possibilities of how we can implement something better. The first suggestion was using something like this:

    names = ['bob', 'alice', 'john', 'peter']
    persons = mommy.make(Person, age=20, name=names)
    

    So, we can instantiate an iterable object with the multiple values that we expect and pass it to the model attribute that we want to change. Although this is an easy approach, it could make the API more complex and confusing. I mean, on the previous code we have a model attribute receiving a list as a parameter, which is something king of odd if we think about model creation...

    Well, let the discussion begins =)

    opened by berinhard 14
  • Column user_id is not Unique

    Column user_id is not Unique

    I have the following models

    app1.models.py

    class UserProfile(Subject): """ UserProfile class """ # This field is required. user = models.OneToOneField(User) # Other fields here company = models.CharField(max_length=50, null=True, blank=True, verbose_name=("Company")) contact = models.CharField(max_length=50, null=True, blank=True, verbose_name=("Contact")) msg = models.TextField(null=True, blank=True, verbose_name=_("Message"))

    def __unicode__(self):
        return self.user.username
    

    class ParentImportJob(models.Model): """ Class to store importing jobs """

    STATUS_ACTIVE = u'A'
    STATUS_SUCCESS = u'S'
    STATUS_PARTIAL = u'P'
    STATUS_ERROR = u'E'
    
    STATUS_CHOICES = (
        (STATUS_ACTIVE, _(u'In Progress')),
        (STATUS_SUCCESS, _(u'Successfully Imported')),
        (STATUS_PARTIAL, _(u'Partially Imported')),
        (STATUS_ERROR, _(u'Aborted with error')),
    )
    
    status = models.CharField(max_length=1, choices=STATUS_CHOICES)
    user_profile = models.ForeignKey(UserProfile)
    errors = models.TextField(null=True, blank=True)
    start_date = models.DateTimeField(auto_now_add=True)
    end_date = models.DateTimeField(blank=True, null=True)
    instance_class = models.CharField(max_length=200)
    

    app2.models.py

    class ImportJob(ParentImportJob): """ Class to store jobs of files being imported Extends ParentImportJob ParentImportJob is not abstract! But I am interested in 2 separated tables """

    _imported_file = models.TextField(null=True,
                                      blank=True,
                                      db_column='imported_file')
    import_result = models.TextField(null=True, blank=True)
    
    def set_import_file(self, imported_file):
        """ Set method for import_file field """
        self._imported_file = base64.encodestring(imported_file)
    
    def get_import_file(self, imported_file):
        """ Set method for import_file field """
        return base64.decodestring(self._imported_file)
    
    imported_file = property(get_import_file, set_import_file)
    

    The following recipe:

    ob_mock = Recipe(ImportJob, import_file=ofile.read(), import_result=EXCEL_DICT)

    When I ran self.job = mommy.make_recipe('excel2db.job_mock') inside the testcase I get IntegrityError: column user_id is not unique

    I'm doing something wrong?

    opened by fernandoferreira-me 13
  • Override default recipe

    Override default recipe

    Is there a way to provide a recipe that replaces mommy's default recipe for a model? In other words, when I run mommy.make('myapp.MyModel'), I want it to use a custom recipe, without having to worry about mommy.make_recipe.

    opened by rouge8 12
  • Write a recipe where ommitted fields are still populated automatically?

    Write a recipe where ommitted fields are still populated automatically?

    I really only need to write a recipe to populate one field--not all of them. Is it possible to have the remaining fields auto-populate? If not, I'd be happy to add this functionality.

    opened by grjones 12
  • Recipe generators

    Recipe generators

    These changes add a little more magic to Recipe and allow us to eliminate the need for Sequence, and allow Recipe to accept iterators (and generators) as field values.

    Advantages:

    • no need for users to work with Sequence, they can use Python generators or iterators which are more familiar and more powerful.
    • the "seq" function still works the same as it always has, and is a simple 2 line generator.
    • all the original unit tests pass, and all new code is covered by new tests

    Disadvantages:

    • The Recipe _mapping function is more complicated.

    This is my first pull request ever. If there are any problem please be patient. I'm open to any feedback you may have.

    opened by DevJac 11
  • *** DoesNotExist: Post matching query does not exist. Lookup parameters were {'pk': 1}

    *** DoesNotExist: Post matching query does not exist. Lookup parameters were {'pk': 1}

    (Pdb) mommy.make(Post)
    *** DoesNotExist: Post matching query does not exist. Lookup parameters were {'pk': 1}
    (Pdb) Post.objects.all()
    []
    (Pdb) Article.objects.all()
    [<Article: /article/3apmB5cyN0yDsyzZwmBhqhf0mDlsIA-BlNrdcJVul0zpiLIM-Y/HY1y3VDgxuERG5-a0Sys8RbzJaQpOl2hlKA9eZuGbF_S09o6mW>]
    (Pdb)
    

    Model Post extend model Article (not abstract).

    mommy.make: Article created and not created Post

    opened by avelino 11
  • Version 1.2.1 and

    Version 1.2.1 and "ValueError: Cannot assign None: "Foo.bar" does not allow null values."

    I have been using version 1.2 for a while without a problem, but since I installed 1.2.1 I started to get a lot of ValueError as the one you see above. Basically, it looks like that when mommy creates a ManyToManyField for a model it's not able to relate it to the instance being created.

    An example will help me explain it: this worked with version 1.2 (simplified):

        tag1 = mommy.make_recipe('myapp.TagRecipe')
        tag2 = mommy.make_recipe('myapp.TagRecipe')
        tag3 = mommy.make_recipe('myapp.TagRecipe')
        params = {
            'tags': [tag1, tag2, tag3],
        }
        article = mommy.make_recipe("myapp.ArticleRecipe", **params)
    

    The recipes simply being:

    TagRecipe = Recipe(Tag, name = seq('tag'))
    ArticleRecipe = Recipe(Article, name = seq('article'))
    

    And the models:

    class Tag(models.Model):
         name = models.CharField(max_length=255, unique=True)
         [...]
    
    class Article(models.Model):
        name = models.CharField(max_length=255, unique=True)
        tags = models.ManyToManyField(Tag, related_name="articles", blank=True, null=True)
        [...]
    

    Since version 1.2.1 I'm getting:

    ValueError: Cannot assign None: "Article_tags.article" does not allow null values.
    

    If you need more information I'll be happy to provide it.

    opened by GermanoGuerrini 10
  • TaggableManager from django-taggit fails in model creation

    TaggableManager from django-taggit fails in model creation

    This is related to #89, but it looks like recent versions of taggit's TaggableManager now subclasses Field and provides has_default() == False.

    ../../.virtualenvs/dashboard/lib/python2.7/site-packages/model_mommy/mommy.py:75: in make
    >           return mommy.make(**attrs)
    ../../.virtualenvs/dashboard/lib/python2.7/site-packages/model_mommy/mommy.py:241: in make
    >       return self._make(commit=True, **attrs)
    ../../.virtualenvs/dashboard/lib/python2.7/site-packages/model_mommy/mommy.py:277: in _make
    >                   model_attrs[field.name] = self.generate_value(field)
    ../../.virtualenvs/dashboard/lib/python2.7/site-packages/model_mommy/mommy.py:351: in generate_value
    >       return generator(**generator_attrs)
    ../../.virtualenvs/dashboard/lib/python2.7/site-packages/model_mommy/mommy.py:75: in make
    >           return mommy.make(**attrs)
    ../../.virtualenvs/dashboard/lib/python2.7/site-packages/model_mommy/mommy.py:241: in make
    >       return self._make(commit=True, **attrs)
    ../../.virtualenvs/dashboard/lib/python2.7/site-packages/model_mommy/mommy.py:277: in _make
    >                   model_attrs[field.name] = self.generate_value(field)
    ../../.virtualenvs/dashboard/lib/python2.7/site-packages/model_mommy/mommy.py:342: in generate_value
    >           raise TypeError('%s is not supported by mommy.' % field.__class__)
    E           TypeError: <class 'taggit.managers.TaggableManager'> is not supported by mommy.
    

    I can't provide a generator function for a custom field either, because the tags cannot be set from the model constructor.

    I don't see an easy way to identify this kind of fake field. :/

    opened by rouge8 10
Releases(1.5.1)
Python dilinin Selenium kütüphanesini kullanarak; Amazon, LinkedIn ve ÇiçekSepeti üzerinde test işlemleri yaptığımız bir case study reposudur.

Python dilinin Selenium kütüphanesini kullanarak; Amazon, LinkedIn ve ÇiçekSepeti üzerinde test işlemleri yaptığımız bir case study reposudur. LinkedI

Furkan Gulsen 8 Nov 01, 2022
It helps to use fixtures in pytest.mark.parametrize

pytest-lazy-fixture Use your fixtures in @pytest.mark.parametrize. Installation pip install pytest-lazy-fixture Usage import pytest @pytest.fixture(p

Marsel Zaripov 299 Dec 24, 2022
The definitive testing tool for Python. Born under the banner of Behavior Driven Development (BDD).

mamba: the definitive test runner for Python mamba is the definitive test runner for Python. Born under the banner of behavior-driven development. Ins

Néstor Salceda 502 Dec 30, 2022
Compiles python selenium script to be a Window's executable

Problem Statement Setting up a Python project can be frustrating for non-developers. From downloading the right version of python, setting up virtual

Jerry Ng 8 Jan 09, 2023
Scalable user load testing tool written in Python

Locust Locust is an easy to use, scriptable and scalable performance testing tool. You define the behaviour of your users in regular Python code, inst

Locust.io 20.4k Jan 04, 2023
A python bot using the Selenium library to auto-buy specified sneakers on the nike.com website.

Sneaker-Bot-UK A python bot using the Selenium library to auto-buy specified sneakers on the nike.com website. This bot is still in development and is

Daniel Hinds 4 Dec 14, 2022
Mimesis is a high-performance fake data generator for Python, which provides data for a variety of purposes in a variety of languages.

Mimesis - Fake Data Generator Description Mimesis is a high-performance fake data generator for Python, which provides data for a variety of purposes

Isaak Uchakaev 3.8k Dec 29, 2022
Photostudio是一款能进行自动化检测网页存活并实时给网页拍照的工具,通过调用Fofa/Zoomeye/360qua/shodan等 Api快速准确查询资产并进行网页截图,从而实施进一步的信息筛查。

Photostudio-红队快速爬取网页快照工具 一、简介: 正如其名:这是一款能进行自动化检测,实时给网页拍照的工具 信息收集要求所收集到的信息要真实可靠。 当然,这个原则是信息收集工作的最基本的要求。为达到这样的要求,信息收集者就必须对收集到的信息反复核实,不断检验,力求把误差减少到最低限度。我

s7ck Team 41 Dec 11, 2022
This project demonstrates selenium's ability to extract files from a website.

This project demonstrates selenium's ability to extract files from a website. I've added the challenge of connecting over TOR. This package also includes a personal archive site built in NodeJS and A

2 Jan 16, 2022
A library for generating fake data and populating database tables.

Knockoff Factory A library for generating mock data and creating database fixtures that can be used for unit testing. Table of content Installation Ch

Nike Inc. 30 Sep 23, 2022
WomboAI Art Generator

WomboAI Art Generator Automate AI art generation using wombot.art. Also integrated into SnailBot for you to try out. Setup Install Python Go to the py

nbee 7 Dec 03, 2022
A modern API testing tool for web applications built with Open API and GraphQL specifications.

Schemathesis Schemathesis is a modern API testing tool for web applications built with Open API and GraphQL specifications. It reads the application s

Schemathesis.io 1.6k Jan 06, 2023
Connexion-faker - Auto-generate mocks from your Connexion API using OpenAPI

Connexion Faker Get Started Install With poetry: poetry add connexion-faker # a

Erle Carrara 6 Dec 19, 2022
A simple script to login into twitter using Selenium in python.

Quick Talk A simple script to login into twitter using Selenium in python. I was looking for a way to login into twitter using Selenium in python. Sin

Lzy-slh 4 Nov 20, 2022
A browser automation framework and ecosystem.

Selenium Selenium is an umbrella project encapsulating a variety of tools and libraries enabling web browser automation. Selenium specifically provide

Selenium 25.5k Jan 01, 2023
A framework-agnostic library for testing ASGI web applications

async-asgi-testclient Async ASGI TestClient is a library for testing web applications that implements ASGI specification (version 2 and 3). The motiva

122 Nov 22, 2022
Selenium-python but lighter: Helium is the best Python library for web automation.

Selenium-python but lighter: Helium Selenium-python is great for web automation. Helium makes it easier to use. For example: Under the hood, Helium fo

Michael Herrmann 3.2k Dec 31, 2022
Simple frontend TypeScript testing utility

TSFTest Simple frontend TypeScript testing utility. Installation Install webpack in your project directory: npm install --save-dev webpack webpack-cli

2 Nov 09, 2021
This repository contnains sample problems with test cases using Cormen-Lib

Cormen Lib Sample Problems Description This repository contnains sample problems with test cases using Cormen-Lib. These problems were made for the pu

Cormen Lib 3 Jun 30, 2022
A Library for Working with Sauce Labs

Robotframework - Sauce Labs Plugin This is a plugin for the SeleniumLibrary to help with using Sauce Labs. This library is a plugin extension of the S

joshin4colours 6 Oct 12, 2021