Skip to content
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

Merged
merged 2 commits into from
Mar 5, 2017

Conversation

szykin
Copy link
Contributor

@szykin szykin commented Mar 2, 2017

  • 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-io
Copy link

codecov-io commented Mar 2, 2017

Codecov Report

Merging #36 into master will not change coverage.
The diff coverage is 100%.

@@          Coverage Diff          @@
##           master    #36   +/-   ##
=====================================
  Coverage     100%   100%           
=====================================
  Files           6      6           
  Lines         550    585   +35     
=====================================
+ Hits          550    585   +35
Impacted Files Coverage Δ
django_mock_queries/utils.py 100% <100%> (ø)
django_mock_queries/mocks.py 100% <100%> (ø)
django_mock_queries/query.py 100% <100%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 9736f87...adeaf4f. Read the comment docs.

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
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))
Copy link
Owner

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes we can!

@@ -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)
Copy link
Owner

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.

Copy link
Contributor Author

@szykin szykin Mar 4, 2017

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.
@stphivos
Copy link
Owner

stphivos commented Mar 5, 2017

Awesome thanks! 👍

@stphivos stphivos merged commit 6513c33 into stphivos:master Mar 5, 2017
@szykin szykin deleted the feature/mock_options branch March 5, 2017 12:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants