Skip to content

Commit

Permalink
Merge branch 'master' into flake8fix
Browse files Browse the repository at this point in the history
  • Loading branch information
donkirkby authored Oct 19, 2016
2 parents 95d7c6a + a8954a3 commit ac67551
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
6 changes: 6 additions & 0 deletions django_mock_queries/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,12 @@ def order_by(*fields):

mock_set.order_by = MagicMock(side_effect=order_by)

def distinct():
results = set(items)
return MockSet(*results, clone=mock_set)

mock_set.distinct = MagicMock(side_effect=distinct)

def latest(field):
results = sorted(items, key=attrgetter(field), reverse=True)
if len(results) == 0:
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
setup(
name='django_mock_queries',
packages=['django_mock_queries'],
version='0.0.12',
version='0.0.13',
description='A django library for mocking queryset functions in memory for testing',
author='Phivos Stylianides',
author_email='stphivos@gmail.com',
Expand Down
10 changes: 10 additions & 0 deletions tests/test_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,16 @@ def test_query_order_by_descending(self):

assert results == [item_1, item_2, item_3], results

def test_query_distinct(self):
item_1 = MockModel(foo=1, mock_name='item_1')
item_2 = MockModel(foo=2, mock_name='item_2')
item_3 = MockModel(foo=3, mock_name='item_3')

self.mock_set.add(item_2, item_3, item_1, item_3)
results = list(self.mock_set.distinct().order_by('foo'))

assert results == [item_1, item_2, item_3], results

def test_query_implements_iterator_on_items(self):
items = [1, 2, 3]
assert [x for x in MockSet(*items)] == items
Expand Down

0 comments on commit ac67551

Please sign in to comment.