Skip to content

Commit

Permalink
Ignore recommendation of itself (#147)
Browse files Browse the repository at this point in the history
  • Loading branch information
AntoineAugusti authored Oct 15, 2020
1 parent 713e636 commit f3b909a
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## Current (in progress)

- Nothing yet
- Ignore recommendation of dataset itself [#147](https://github.com/opendatateam/udata-recommendations/pull/147)

## 2.1.0 (2020-08-25)

Expand Down
15 changes: 15 additions & 0 deletions tests/test_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,3 +176,18 @@ def test_datasets_recommendations_from_config_clean(self, mock_response, rmock,
# Previous recommendations have been cleaned
ds1.reload()
assert ds1.extras == {}

def test_datasets_recommendations_ignore_self_recommendation(self, rmock, datasets):
ds1, _, _ = datasets
rmock.get(MOCK_URL, json=[{
"id": str(ds1.id),
"recommendations": [{
"id": str(ds1.id),
"score": 50
}]
}])

recommendations_add({'fake_source': MOCK_URL}, should_clean=True)

ds1.reload()
assert ds1.extras == {}
2 changes: 2 additions & 0 deletions udata_recommendations/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ def process_dataset(source, dataset):
for reco in dataset['recommendations']:
try:
reco_dataset_obj = get_dataset(reco['id'])
if reco_dataset_obj.id == target_dataset.id:
continue
valid_recos.append({
'id': str(reco_dataset_obj.id),
'score': reco['score'],
Expand Down

0 comments on commit f3b909a

Please sign in to comment.