-
Notifications
You must be signed in to change notification settings - Fork 53
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
MockOptions, get_or_create_with defaults #36
Conversation
szykin
commented
Mar 2, 2017
•
edited
Loading
edited
- MockModel is now a subclass of dict (some workaround with hash allows the use of set :) )
- get_or_create() and create() now requires MockSet to have 'cls' and 'model' attributes being not None
- MockSet() now has cls=MockModel as default cls
- New ClsNotSpecifiedException
- patchers are updated, so MockSets created from 'real' django models project, and MockSets of related fields now have 'cls' and 'model' attributes
- removed tests for 'spec_set', getattr in MockModel now returns None by default (still unsure here, do we ever need the default value here, the idea behind 'spec_set' now can be delegated to this removal)
Codecov Report
@@ Coverage Diff @@
## master #36 +/- ##
=====================================
Coverage 100% 100%
=====================================
Files 6 6
Lines 550 585 +35
=====================================
+ Hits 550 585 +35
Continue to review full report at Codecov.
|
29886a3
to
f68c7c3
Compare
get_or_create() and create() now requires MockSet to have 'cls' and 'model' attributes being not None MockSet() now has cls=MockModel as default cls
682e4ca
to
7f64355
Compare
django_mock_queries/query.py
Outdated
validate_mock_set(mock_set) | ||
for k in attrs.keys(): | ||
if k not in [f.attname for f in mock_set.model._meta.concrete_fields]: | ||
raise ValueError('MockSet model has no field {}'.format(k)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we raise in this case a TypeError: 'foo' is an invalid keyword argument for this function
, like Django, see django/db/models/base.py
- line 555?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes we can!
django_mock_queries/query.py
Outdated
@@ -30,8 +30,9 @@ def MockSet(*initial_items, **kwargs): | |||
'prefetch_related', | |||
'select_for_update' | |||
]) | |||
mock_set.cls = clone.cls if clone else kwargs.get('cls', empty_func) | |||
mock_set.cls = clone.cls if clone else kwargs.get('cls', MockModel) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shall we remove .cls
now that we have . model
that covers everything? It has a _meta
with all the fields required for create
and get_or_create
etc.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did it, but had to do some tweaks with MockModel class.
def __call__(self, *args, **kwargs):
return MockModel(*args, **kwargs)
Also create() now fills fields that are not specified in kwargs with None.
create() now fills MockModel fields with None by default. Updated some of the tests.
Awesome thanks! 👍 |