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

added spec_set to MockModel #22

Merged
merged 3 commits into from
Dec 12, 2016
Merged

Conversation

szykin
Copy link
Contributor

@szykin szykin commented Dec 12, 2016

Just a little addition to MockModel for testing functions that use getattr().
If you define your MockModel like this:

mock_instance = MockModel(spec_set=True, some_field='some_value')

and try to getattr(mock_instance, 'bad_field') in function that you test it will throw an exception, not add this attribute to MockModel instance.

@codecov-io
Copy link

codecov-io commented Dec 12, 2016

Current coverage is 100% (diff: 100%)

Merging #22 into master will not change coverage

@@           master   #22   diff @@
===================================
  Files           5     5          
  Lines         307   307          
  Methods         0     0          
  Messages        0     0          
  Branches        0     0          
===================================
  Hits          307   307          
  Misses          0     0          
  Partials        0     0          

Powered by Codecov. Last update 793aa27...5d13e37

@szykin
Copy link
Contributor Author

szykin commented Dec 12, 2016

I assume that even with spec_set=True getattr with default value returns default value.
But raises AttributeError if there is no field with such name in mocked instance.

@stphivos
Copy link
Owner

Good idea thanks!

@stphivos stphivos merged commit 3f650f8 into stphivos:master Dec 12, 2016
@szykin szykin deleted the feature/spec_set branch December 14, 2016 09:51
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