Return full avatar URLs instead of digests in stats

- Replace digest_sha256 with avatar_url in top_viewed_avatars
- Replace digest_sha256 with avatar_url in top_queried_emails
- Replace digest_sha256 with avatar_url in top_queried_openids
- All avatar URLs now use https://libravatar.org/avatar/{digest} format
- Update tests to verify avatar_url presence and correct format
- All 5 stats tests pass successfully

This makes the stats API more user-friendly by providing complete
avatar URLs that can be directly used in applications instead of
requiring clients to construct the URLs themselves.
This commit is contained in:
Oliver Falk
2025-09-26 09:21:00 +02:00
parent 928ffaea76
commit 15062b3cda
2 changed files with 28 additions and 4 deletions

View File

@@ -160,6 +160,14 @@ class StatsTester(TestCase):
100,
"top avatar access count incorrect",
)
# Check that avatar_url is present and starts with the correct base URL
self.assertIn("avatar_url", j["top_viewed_avatars"][0], "avatar_url missing")
self.assertTrue(
j["top_viewed_avatars"][0]["avatar_url"].startswith(
"https://libravatar.org/avatar/"
),
"avatar_url should start with https://libravatar.org/avatar/",
)
# Test top queried emails
self.assertIn("top_queried_emails", j, "top_queried_emails missing")
@@ -171,6 +179,14 @@ class StatsTester(TestCase):
100,
"top email access count incorrect",
)
# Check that avatar_url is present and starts with the correct base URL
self.assertIn("avatar_url", j["top_queried_emails"][0], "avatar_url missing")
self.assertTrue(
j["top_queried_emails"][0]["avatar_url"].startswith(
"https://libravatar.org/avatar/"
),
"avatar_url should start with https://libravatar.org/avatar/",
)
# Test top queried openids
self.assertIn("top_queried_openids", j, "top_queried_openids missing")
@@ -182,6 +198,14 @@ class StatsTester(TestCase):
75,
"top openid access count incorrect",
)
# Check that avatar_url is present and starts with the correct base URL
self.assertIn("avatar_url", j["top_queried_openids"][0], "avatar_url missing")
self.assertTrue(
j["top_queried_openids"][0]["avatar_url"].startswith(
"https://libravatar.org/avatar/"
),
"avatar_url should start with https://libravatar.org/avatar/",
)
# Test photo format distribution
self.assertIn(

View File

@@ -589,7 +589,7 @@ class StatsView(TemplateView, JsonResponse):
top_photos_data.append(
{
"access_count": top_associated.access_count,
"digest_sha256": top_associated.digest_sha256,
"avatar_url": f"https://libravatar.org/avatar/{top_associated.digest_sha256}",
}
)
else:
@@ -597,7 +597,7 @@ class StatsView(TemplateView, JsonResponse):
top_photos_data.append(
{
"access_count": top_associated.access_count,
"digest_sha256": top_associated.digest,
"avatar_url": f"https://libravatar.org/avatar/{top_associated.digest}",
}
)
@@ -610,7 +610,7 @@ class StatsView(TemplateView, JsonResponse):
top_emails_data.append(
{
"access_count": email.access_count,
"digest_sha256": email.digest_sha256,
"avatar_url": f"https://libravatar.org/avatar/{email.digest_sha256}",
}
)
@@ -623,7 +623,7 @@ class StatsView(TemplateView, JsonResponse):
top_openids_data.append(
{
"access_count": openid.access_count,
"digest_sha256": openid.digest,
"avatar_url": f"https://libravatar.org/avatar/{openid.digest}",
}
)