jamescooke / factory_djoy Goto Github PK
View Code? Open in Web Editor NEWFactories for Django, creating valid model instances every time
Home Page: https://factory-djoy.readthedocs.io/
License: MIT License
Factories for Django, creating valid model instances every time
Home Page: https://factory-djoy.readthedocs.io/
License: MIT License
When using a custom user model I'd love to still use your unique username generation.
Would it be possible to provide the Username generator as it's own standalone module/provider?
Something like:
from factory.django import DjangoModelFactory
from factory_djoy import UniqueUsername
class AccountFactory(DjangoModelFactory):
username = UniqueUsername()
There is a possible collision when creating User
instances.
======================================================================
FAIL: test_make_multi (tests.test_user_factory.TestUserFactory)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/ubuntu/factory_djoy/test_framework/django18/tests/test_user_factory.py", line 52, in test_make_multi
'Both users found to have same "{}" attribute'.format(varname)
AssertionError: 'Devin' == 'Devin' : Both users found to have same "first_name" attribute
----------------------------------------------------------------------
Update to support Django versions: 3.2, 4.0, 4.1, 4.2
When a Factory fails to create an instance because full_clean()
fails - it's hard to work out why the failure happened because the original value is not captured in Django's ValidationError
. This can be super-hard to work out when working with multiple SubFactories - which one created the error? Especially when multiple sub-factories might have fields named the same... like name
.
Therefore, add some information to the raised ValueError
to indicate the model that failed to build and the values for those failed fields that were tried by factory boy:
try:
obj.full_clean()
except ValidationError as ve:
message = 'Error building {}.\nBad values:\n'.format(model_class)
for field in ve.error_dict.keys():
message += ' {}: "{}"\n'.format(field, getattr(obj, field))
raise RuntimeError(message) from ve
Rather than latest.
Version is v0.6.0 but docs show 0.5.0 in title.
Build of docs is failing here: https://readthedocs.org/projects/factory-djoy/builds/18444075/
Also related - docs are still built on py27, this could do with being updated to python 3.
Maybe use tox for this. Check out https://github.com/tomchristie/django-rest-framework/blob/master/tox.ini
Ensure that get_or_create
works with _create
and CleanModelFactory
.
Document that get_or_create
functionality is not provided.
README is poor and unhelpful.
Getting started info needs to be added to show the benefits of lib.
As a result of new code #21, UserFactory
docs need updating for v1.
Add lint
step to tox.ini
and remove from Makefile
. This will create an isort
error because there is a Django import in the wrong place.
Switch to Travis for better Tox integration.
Needs a new target test run and a coverage report to be generated.
Will allow for better testing both internally and by developers.
When a faker
instance is used, it should be configurable. For now, this means being able to set a locale string somewhere, and this should be loaded when faker
is instantiated.
In a test run, it can be helpful to be able to create invalid data that has slipped into the Django database. However, invalid data can not be created because the call to full_clean
happens on both create
and build
.
A simple solution is to allow build
to create unsaved, invalid instances. What the developer does with that instance after it has been built is up to them... if they want to just save()
it and create invalid data, that's their choice.
Steps would be:
build
to not have full_clean
called.UserFactory.build(username='something bad').save()
Update requirements for:
requirements/base.txt
test_framework/requirements/*.txt
Script (makefile recipe), should:
Update to support Pythons: 3.7, 3.8, 3.9, 3.10 and 3.11
For sanity.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.