Skip to content
This repository has been archived by the owner on Mar 24, 2021. It is now read-only.

Commit

Permalink
Test periodic grouping returns most recent first
Browse files Browse the repository at this point in the history
  • Loading branch information
Gareth Rogers committed Mar 26, 2013
1 parent bf0f611 commit 0ce712d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
2 changes: 1 addition & 1 deletion backdrop/core/database.py
Expand Up @@ -85,7 +85,7 @@ def multi_group(self, key1, key2, query):
output = nested_merge([key1, key2], results)

result = []
for key1_value, value in sorted(output.items()):
for key1_value, value in sorted(output.items(), reverse=True):
result.append({
key1: key1_value,
"_count": sum(doc['_count'] for doc in value.values()),
Expand Down
14 changes: 13 additions & 1 deletion tests/core/integration/test_database_integration.py
Expand Up @@ -389,7 +389,6 @@ def test_sorted_query_with_alphanumeric(self):
has_entry('val', 'a')
))


def test_sorted_group_ascending(self):
self.mongo_collection.save({"suite": "clubs"})
self.mongo_collection.save({"suite": "hearts"})
Expand Down Expand Up @@ -463,3 +462,16 @@ def test_sorted_group_by_count(self):
has_entry("suite", "hearts"),
has_entry("suite", "clubs")
))

def test_periodic_group_is_sorted_by__week_start_at(self):
self.mongo_collection.save({"_week_start_at": d(2013, 3, 17),
'val': 1})
self.mongo_collection.save({"_week_start_at": d(2013, 3, 24),
'val': 7})

result = self.repo.multi_group('_week_start_at', 'val', {})

assert_that(list(result), contains(
has_entry('_week_start_at', d(2013, 3, 24)),
has_entry('_week_start_at', d(2013, 3, 17))
))

2 comments on commit 0ce712d

@robyoung
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think this is right, it doesn't match the wiki documentation or the usage in limelight.

@gtrogers
Copy link
Contributor

Choose a reason for hiding this comment

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

Feel free to change, with the proviso that if we have logic around the ordering of a result we should be testing that logic. What is the expected result?

Please sign in to comment.