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

Mocked querysets aggregation now handles None values. #21

Merged
merged 1 commit into from
Dec 12, 2016

Conversation

szykin
Copy link
Contributor

@szykin szykin commented Dec 12, 2016

While using django-mock-queries for aggregation testing, I faced problems when trying to mock instances with None values in fields. I define mock instances like this:

first_product=MockModel(price = 2)
second_product=MockModel(price=4)
none_product=MockModel(price=None)

Built-in functions like min() raise an exception when there is a None value in values list.

Now mock_set.aggregate() more precisely mimics Django behaviour when working with None values in fields:

  • Sum, Max, Min return None by default, and work only with not None values
  • Avg divident is sum of not None values, divisor is len() of not None values
  • Count returns 0 by default and works only with not None values.

@codecov-io
Copy link

codecov-io commented Dec 12, 2016

Current coverage is 100% (diff: 100%)

Merging #21 into master will not change coverage

@@           master   #21   diff @@
===================================
  Files           5     5          
  Lines         303   307     +4   
  Methods         0     0          
  Messages        0     0          
  Branches        0     0          
===================================
+ Hits          303   307     +4   
  Misses          0     0          
  Partials        0     0          

Powered by Codecov. Last update b0bcd0a...5fa8289

@stphivos
Copy link
Owner

Thanks!

@stphivos stphivos merged commit 793aa27 into stphivos:master Dec 12, 2016
@szykin szykin deleted the feature/aggregate_with_none branch December 14, 2016 09:52
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