Verified Commit 2cfc0bd3 authored by Eliot Berriot's avatar Eliot Berriot
Browse files

Remove duplicates

parent 8d63838b
......@@ -115,8 +115,20 @@ def result_to_retribute_profile(lookup_type, lookup, data):
valid_means = list(filter(lambda v: v[1] is not None, valid_means))
if not valid_means:
raise exceptions.MeansNotFound()
# remove possible duplicates
deduplicated_means = []
handled = []
for mean in valid_means:
id = (mean[1]["provider"], mean[1]["id"])
if id in handled:
# avoid duplicates
continue
deduplicated_means.append(mean)
handled.append(id)
final_means = []
for i, mean in enumerate(reversed(valid_means)):
for i, mean in enumerate(reversed(deduplicated_means)):
link_data = mean[0]
mean_data = mean[1]
mean_data.setdefault("weight", i)
......
......@@ -172,3 +172,37 @@ def test_source_result_to_retribute_profile(settings, now):
result = sources.result_to_retribute_profile(lookup_type, lookup, data)
assert result == expected
def test_source_result_to_retribute_profile_removes_duplicates(settings, now):
settings.BASE_URL = "https://retribute.me.test"
lookup_type = "webfinger"
lookup = "test@domain.test"
data = {
"links": [
{"summary": "Patreon", "url": "https://patreon.com/username"},
{"summary": "Duplicate Patreon", "url": "https://patreon.com/username"},
]
}
expected = {
"version": "0.1",
"id": "https://retribute.me.test/compat/{}:{}".format(lookup_type, lookup),
"title": "Compat profile for {}:{}".format(lookup_type, lookup),
"updated": now.isoformat(),
"identities": [],
"means": [
{
"provider": "patreon",
"id": "username",
"summary": "Patreon",
"weight": 0,
"url": "https://patreon.com/username",
}
],
}
result = sources.result_to_retribute_profile(lookup_type, lookup, data)
assert result == expected
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment