Giter Site home page Giter Site logo

fcurella / django-fakery Goto Github PK

View Code? Open in Web Editor NEW
113.0 7.0 6.0 425 KB

๐Ÿญ An easy-to-use implementation of Creation Methods for Django, backed by Faker.

Home Page: http://django-fakery.readthedocs.org/en/stable/

License: MIT License

Python 99.72% Makefile 0.28%
creation-methods django testing

django-fakery's People

Contributors

arnaudlimbourg avatar fcurella avatar jacobian avatar mjakob avatar sobolevn avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

django-fakery's Issues

Passing kwargs to related models

Imagine that we have a model like so:

class User(models.Model):
     profile = models.ForeignKey('UserProfile') 
     is_active = models.BooleanField()

And later I want to use it like so:

active_user_factory = fakery.blueprint(User).fields(
    is_active=True,
)

empty_username = active_user_factory.m(profile__username='')
email_username = active_user_factory.m(profile__username='[email protected]')

But, currently this does not work. What can be done to pass kwargs to related objects?

Initial Update

Hi ๐Ÿ‘Š

This is my first visit to this fine repo, but it seems you have been working hard to keep all dependencies updated so far.

Once you have closed this issue, I'll create separate pull requests for every update as soon as I find one.

That's it for now!

Happy merging! ๐Ÿค–

Use type annotations instead of type comments

Brief summary of the issue goes here.

Steps to reproduce

PyCharm(and VSCode) cannot recognize these type comments correctly:
image
So whenever I use factory.m, PyCharm always prompts me with type errors:
image

Could you please use type annotations instead of comments for better type hints by modern IDEs or editors?

@fcurella

Consider making Blueprint.fields() update fields instead of overwriting

I think Blueprint.fields() should return a new Blueprint, with updated fields, instead of overwriting all existing fields. This makes for what I think is a more intuitive API when using blueprints.

I'm happy to work up a PR for this if the direction seems appropriate, but I want to validate the direction before I code it up.

Steps to reproduce

I have a blueprint:

reports = factory.blueprint(Report).fields(
    contract_number=lambda n, f: f.bothify("K#####T####"),
    ... many more fields ...
)

This model happens to have a FK to another model (Contractor) , so I tried something that seemed intuitive:

c = contractors.make()
r = reports.fields(contractor=c).make()

This feels like a fairly intuitive API for making "sub-blueprints", but it doesn't work.

Expected behavior

I expected the fields on r to be set according to my field callbacks.

Actual behavior

Instead, not only are the field callbacks not called, subsequent calls to the the report blueprint don't get it either! This is because Blueprint.fields overwrites self._fields


If Blueprint.fields was instead something like:

def fields(self, **kwargs):
    new_fields = self._fields.copy()
    new_fields.update(kwargs)
    return Blueprint(self.model, new_fields, pre_save=self.pre_save, post_save=self.post_save, seed=self.seed)

Then what I expected to happen, would in fact happen. Again I think this makes for a more natural, easy-to-use API -- but maybe I'm wrong? LMK if you'd like to see a patch!

Reference instance fields inside `lambda`

Hi! Thanks a lot for building this project.

I try to solve this problem:

fakery.m(User)(
    username='test',
    email=lambda n, f, instance: '{0}@example.com'.format(instance.username)
)

But I am not sure that I am able to with django-fakery currently.

no module named psycopg2

Thanks for your nice package.

Steps to reproduce

  1. pip install django-fakery
In [1]: from django_fakery import factory

In [2]: factory.m

ModuleNotFoundError: No module named 'psycopg2'

pip install psycopg2 -> OK
but I didn't actually use pg, psycopg2 is not required package

`build` throws confusing `ForeignKeyError` exception

The build commands blows up when you use it to fill out a row which references a non-null ForeignKey.

    obj = factory.build('contacts.Contact')

Yields:

    `ForeignKeyError`: field address_id is a ForeignKey

I dug through the code and figured out that make_fks=True is what I needed to make the error go away but it was kind of confusing.

This fails even when I try to pass in an already existing ForeignKey reference:

    address = factory.make('crm.Address')
    obj = factory.build('crm.Contact', fields={'address': address})

Thank you!

Fields are not filled

I'm having trouble using the package overall.

If we take the user model, it doesn't seem to want to save any other parameter than the username.

e.g:

factory.make(
    'users.User',
    fields={
        'username': lambda n,f:f.user_name(),'city':lambda n,f:f.city()
    }
)

It does create a user but it has no city, just a blank string :( It is a custom user model for info.

I tried with another model but it keeps wanting to fill a slug which does not exist on this model.

ValueError: Cant generate a value for field `slug`

UUID Fields without a default specified do not populate.

I added a UUIDField to the Chef test model, and re-ran the test suite, which produces a litany of

django.db.utils.IntegrityError: null value in column "uuid_id" violates not-null constraint

errors.
Commit with my modifications: 55a8ce7

happy to help fix the issue however I can.

Deprecation warning when faking model with JSONFIeld

/usr/local/lib/python3.9/site-packages/faker/providers/python/__init__.py:19: PendingDeprecationWarning: Passing value types as positional arguments is going to be deprecated. Pass them as a list or tuple instead.
Coming from here

Steps to reproduce

Python 3.10.0
django-fakery 3.2.0
faker 4.18.0

from django.db import models

class TestModel(models.Model):
    data = models.JSONField()

Then with -Wd to show deprecation flags

factory.m(TestModel)()
/usr/local/lib/python3.9/site-packages/faker/providers/python/__init__.py:19: PendingDeprecationWarning: Passing value types as positional arguments is going to be deprecated.  Pass them as a list or tuple instead.
  warnings.warn(
<TestModel: TestModel object (1)>

Expected behavior

Should not have deprecation warning

Actual behavior

Has deprecation warning

Using outdated and insecure faker

Currently django-fakery uses Faker = ">=2.0,<2.1"
It is reported as insecure by safety:

ยป safety check --bare --full-report
faker

Custom mapping types support

I have a custom field inherits from models.IntegerField:

class UnsignedIntegerField(models.IntegerField):
    def db_type(self, connection):
        return "integer UNSIGNED"

    def rel_db_type(self, connection):
        return "integer UNSIGNED"

but django-fakery treats it as models.IntegerField and makes a negative number, then error occured.
So could you make an api to custom mappings types for custom fields๐Ÿ˜„?

GEOS needed?

Hello,

I had to install geos to be able to run any code. I don't use any geospatial code so it requiring geos does not make sense.

Is that intentional?

Thanks!

Faker version dependency

Hello,

Is there a specific reason for the pinning of Faker to version <11. As far as I can see from Faker changelog it should be safe to set it to <12

That would make upgrading possible for those of using pipenv :)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.