-
Notifications
You must be signed in to change notification settings - Fork 426
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Jon Betts
committed
Jun 22, 2023
1 parent
975f547
commit ab30f3f
Showing
18 changed files
with
77 additions
and
225 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,5 +12,6 @@ omit = | |
[report] | ||
show_missing = True | ||
precision = 2 | ||
fail_under = 98.27 | ||
fail_under = 98.44 | ||
|
||
skip_covered = True |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,11 @@ | ||
"""Unit tests for h/atom.py.""" | ||
from datetime import datetime, timedelta | ||
from unittest import mock | ||
|
||
import pytest | ||
|
||
from h import models | ||
from h.feeds import atom | ||
|
||
|
||
def _annotation(**kwargs): | ||
args = { | ||
"userid": "acct:[email protected]", | ||
"created": datetime.utcnow(), | ||
"updated": datetime.utcnow(), | ||
"target_selectors": [], | ||
"document": models.Document(), | ||
} | ||
args.update(kwargs) | ||
return models.Annotation(**args) | ||
|
||
|
||
def test_feed_id(): | ||
feed = atom.feed_from_annotations([], "atom_url", mock.Mock()) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -122,14 +122,6 @@ def test_validate_raises_ValidationError_groupid_authority_mismatch( | |
{"name": "Shambles", "groupid": "group:[email protected]"} | ||
) | ||
|
||
@pytest.fixture | ||
def appstruct(self): | ||
return { | ||
"groupid": "group:[email protected]", | ||
"name": "DingDong!", | ||
"description": "OH, hello there", | ||
} | ||
|
||
@pytest.fixture | ||
def schema(self): | ||
schema = GroupAPISchema( | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
# pylint: disable=too-many-lines | ||
import datetime | ||
|
||
import elasticsearch_dsl | ||
|
@@ -924,91 +923,57 @@ def test_matches_replies_of_replies_to_an_annotation(self, Annotation, search): | |
|
||
|
||
class TestTagsAggregation: | ||
def test_it_returns_annotation_counts_by_tag(self, Annotation, search): | ||
@pytest.mark.parametrize( | ||
"limit,expected", | ||
( | ||
[ | ||
2, | ||
[ | ||
{"count": 2, "tag": "tag_a"}, | ||
{"count": 1, "tag": "tag_b"}, | ||
], | ||
], | ||
[1, [{"count": 2, "tag": "tag_a"}]], | ||
), | ||
) | ||
def test_it_returns_annotation_counts_by_tag( | ||
self, Annotation, search, limit, expected | ||
): | ||
for _ in range(2): | ||
Annotation(tags=["tag_a"]) | ||
Annotation(tags=["tag_b"]) | ||
|
||
search.append_aggregation(query.TagsAggregation()) | ||
search.append_aggregation(query.TagsAggregation(limit=limit)) | ||
result = search.run(webob.multidict.MultiDict({})) | ||
|
||
tag_results = result.aggregations["tags"] | ||
count_for_tag_a = next(r for r in tag_results if r["tag"] == "tag_a")["count"] | ||
count_for_tag_b = next(r for r in tag_results if r["tag"] == "tag_b")["count"] | ||
|
||
assert len(tag_results) == 2 | ||
assert count_for_tag_a == 2 | ||
assert count_for_tag_b == 1 | ||
|
||
def test_it_limits_number_of_annotation_counts_by_tag_returned( | ||
self, Annotation, search | ||
): | ||
bucket_limit = 2 | ||
|
||
Annotation(tags=["tag_a"]) | ||
for _ in range(3): | ||
Annotation(tags=["tag_b"]) | ||
for _ in range(2): | ||
Annotation(tags=["tag_c"]) | ||
|
||
search.append_aggregation(query.TagsAggregation(bucket_limit)) | ||
result = search.run(webob.multidict.MultiDict({})) | ||
|
||
tag_results = result.aggregations["tags"] | ||
count_for_tag_b = next(r for r in tag_results if r["tag"] == "tag_b")["count"] | ||
count_for_tag_c = next(r for r in tag_results if r["tag"] == "tag_c")["count"] | ||
|
||
assert len(tag_results) == bucket_limit | ||
assert count_for_tag_b == 3 | ||
assert count_for_tag_c == 2 | ||
assert result.aggregations["tags"] == expected | ||
|
||
|
||
class TestUsersAggregation: | ||
def test_it_returns_annotation_counts_by_user(self, Annotation, search): | ||
for _ in range(2): | ||
Annotation(userid="acct:[email protected]") | ||
Annotation(userid="acct:[email protected]") | ||
|
||
search.append_aggregation(query.UsersAggregation()) | ||
result = search.run(webob.multidict.MultiDict({})) | ||
|
||
users_results = result.aggregations["users"] | ||
count_pa = next(r for r in users_results if r["user"] == "acct:[email protected]")[ | ||
"count" | ||
] | ||
count_pb = next(r for r in users_results if r["user"] == "acct:[email protected]")[ | ||
"count" | ||
] | ||
|
||
assert len(users_results) == 2 | ||
assert count_pa == 2 | ||
assert count_pb == 1 | ||
|
||
def test_it_limits_number_of_annotation_counts_by_user_returned( | ||
self, Annotation, search | ||
@pytest.mark.parametrize( | ||
"limit,expected", | ||
( | ||
[ | ||
2, | ||
[ | ||
{"count": 2, "user": "acct:[email protected]"}, | ||
{"count": 1, "user": "acct:[email protected]"}, | ||
], | ||
], | ||
[1, [{"count": 2, "user": "acct:[email protected]"}]], | ||
), | ||
) | ||
def test_it_returns_annotation_counts_by_user( | ||
self, Annotation, search, limit, expected | ||
): | ||
bucket_limit = 2 | ||
|
||
Annotation(userid="acct:[email protected]") | ||
for _ in range(3): | ||
Annotation(userid="acct:[email protected]") | ||
Annotation(userid="acct:[email protected]") | ||
for _ in range(2): | ||
Annotation(userid="acct:pc@example.com") | ||
Annotation(userid="acct:b@example.com") | ||
|
||
search.append_aggregation(query.UsersAggregation(limit=bucket_limit)) | ||
search.append_aggregation(query.UsersAggregation(limit=limit)) | ||
result = search.run(webob.multidict.MultiDict({})) | ||
|
||
users_results = result.aggregations["users"] | ||
count_pb = next(r for r in users_results if r["user"] == "acct:[email protected]")[ | ||
"count" | ||
] | ||
count_pc = next(r for r in users_results if r["user"] == "acct:[email protected]")[ | ||
"count" | ||
] | ||
|
||
assert len(users_results) == bucket_limit | ||
assert count_pb == 3 | ||
assert count_pc == 2 | ||
assert result.aggregations["users"] == expected | ||
|
||
|
||
@pytest.fixture | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.