Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
A
api
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
retribute.me
api
Commits
2cfc0bd3
Verified
Commit
2cfc0bd3
authored
6 years ago
by
Eliot Berriot
Browse files
Options
Downloads
Patches
Plain Diff
Remove duplicates
parent
8d63838b
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
retribute_api/search/sources.py
+13
-1
13 additions, 1 deletion
retribute_api/search/sources.py
tests/search/test_sources.py
+34
-0
34 additions, 0 deletions
tests/search/test_sources.py
with
47 additions
and
1 deletion
retribute_api/search/sources.py
+
13
−
1
View file @
2cfc0bd3
...
@@ -115,8 +115,20 @@ def result_to_retribute_profile(lookup_type, lookup, data):
...
@@ -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
))
valid_means
=
list
(
filter
(
lambda
v
:
v
[
1
]
is
not
None
,
valid_means
))
if
not
valid_means
:
if
not
valid_means
:
raise
exceptions
.
MeansNotFound
()
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
=
[]
final_means
=
[]
for
i
,
mean
in
enumerate
(
reversed
(
vali
d_means
)):
for
i
,
mean
in
enumerate
(
reversed
(
deduplicate
d_means
)):
link_data
=
mean
[
0
]
link_data
=
mean
[
0
]
mean_data
=
mean
[
1
]
mean_data
=
mean
[
1
]
mean_data
.
setdefault
(
"
weight
"
,
i
)
mean_data
.
setdefault
(
"
weight
"
,
i
)
...
...
This diff is collapsed.
Click to expand it.
tests/search/test_sources.py
+
34
−
0
View file @
2cfc0bd3
...
@@ -172,3 +172,37 @@ def test_source_result_to_retribute_profile(settings, now):
...
@@ -172,3 +172,37 @@ def test_source_result_to_retribute_profile(settings, now):
result
=
sources
.
result_to_retribute_profile
(
lookup_type
,
lookup
,
data
)
result
=
sources
.
result_to_retribute_profile
(
lookup_type
,
lookup
,
data
)
assert
result
==
expected
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
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment