Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions badges/sources.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,21 @@ def _iter_library_maintenance():
yield user, version.library


def _iter_library_versioning():
"""Yield (user, library_version) for every authorship of a parent's release.

Only parent libraries count: see the module docstring.
"""
from libraries.models import LibraryVersion

versions = LibraryVersion.objects.exclude(
library__key__in=SUB_LIBRARIES
).prefetch_related("authors")
for version in versions.iterator(chunk_size=500):
for user in version.authors.all():
yield user, version


def _iter_code_commits():
"""Yield (user, commit) for every attributed commit."""
from libraries.models import Commit
Expand All @@ -80,6 +95,7 @@ def _iter_code_commits():
BACKFILL_ITERATORS = {
AchievementSlug.LIBRARY_AUTHORING: _iter_library_authoring,
AchievementSlug.LIBRARY_MAINTENANCE: _iter_library_maintenance,
AchievementSlug.LIBRARY_VERSIONING: _iter_library_versioning,
AchievementSlug.CODE_COMMITS: _iter_code_commits,
}

Expand Down
16 changes: 16 additions & 0 deletions badges/tests/test_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,22 @@ def test_backfill_library_maintenance(plain_user):
).exists()


def test_backfill_library_versioning(plain_user):
"""Backfill grants the versioning achievement per LibraryVersion authored."""
for _ in range(2):
version = baker.make("libraries.LibraryVersion")
version.authors.add(plain_user)

call_command("backfill_achievements", "--source", "library-versioning")

assert (
UserAchievement.objects.filter(
user=plain_user, achievement__slug="library-versioning"
).count()
== 2
)


def test_backfill_fails_loudly_on_an_explicit_unseeded_source(plain_user):
"""A named source with no Achievement row is a deploy bug, not a skip."""
Achievement.objects.filter(slug=AchievementSlug.CODE_COMMITS).delete()
Expand Down
9 changes: 9 additions & 0 deletions badges/tests/test_sources.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,15 @@ def test_iter_library_maintenance_skips_sub_libraries(plain_user):
assert list(sources._iter_library_maintenance()) == []


def test_iter_library_versioning_skips_sub_libraries(plain_user):
"""A sub-library's releases belong to its parent, and count for nothing here."""
sub = baker.make("libraries.Library", key="math/quaternion")
version = baker.make("libraries.LibraryVersion", library=sub)
version.authors.add(plain_user)

assert list(sources._iter_library_versioning()) == []


def test_iter_code_commits_skips_unlinked(plain_user):
"""Only commits whose author has a linked user are yielded."""
linked = baker.make("libraries.CommitAuthor", user=plain_user)
Expand Down
Loading