def test_recommendation_weights(): """ Weights should be ordered greatest to lowest """ ctx = get_mocked_ctx() r = CollaborativeRecommender(ctx) # An non-empty set of addons should give a list of recommendations fixture_client_data = {"installed_addons": ["addon4.id"], "client_id": "test_client"} assert r.can_recommend(fixture_client_data) recommendations = r.recommend(fixture_client_data, 2) assert isinstance(recommendations, list) assert len(recommendations) == 2 # Verify that addon2 - the most heavy weighted addon was # recommended result = recommendations[0] assert type(result) is tuple assert len(result) == 2 assert result[0] == 'addon2.id' assert type(result[1]) is numpy.float64 assert numpy.isclose(result[1], numpy.float64('0.3225')) # Verify that addon2 - the most heavy weighted addon was # recommended result = recommendations[1] assert type(result) is tuple assert len(result) == 2 assert result[0] == 'addon5.id' assert type(result[1]) is numpy.float64 assert numpy.isclose(result[1], numpy.float64('0.29'))
def test_best_recommendation(test_ctx): # Make sure the structure of the recommendations is correct and that we # recommended the the right addon. ctx = install_mock_data(test_ctx) r = CollaborativeRecommender(ctx) # An non-empty set of addons should give a list of recommendations fixture_client_data = { "installed_addons": ["addon4.id"], "client_id": "test_client" } assert r.can_recommend(fixture_client_data) recommendations = r.recommend(fixture_client_data, 1) assert isinstance(recommendations, list) assert len(recommendations) == 1 # Verify that addon2 - the most heavy weighted addon was # recommended result = recommendations[0] assert type(result) is tuple assert len(result) == 2 assert result[0] == 'addon2.id' assert type(result[1]) is numpy.float64 assert numpy.isclose(result[1], numpy.float64('0.3225'))
def test_recommendations(activate_responses): # Tests that the empty recommender always recommends an empty list # of addons. r = CollaborativeRecommender() recommendations = r.recommend({}, 1) # Make sure the structure of the recommendations is correct and that we # recommended the the right addon. assert isinstance(recommendations, list) assert len(recommendations) == 1
def test_recommendations(activate_responses): # Tests that the empty recommender always recommends an empty list # of addons. r = CollaborativeRecommender() recommendations = r.recommend({}, 1) # Make sure the structure of the recommendations is correct and that we # recommended the the right addon. assert isinstance(recommendations, list) assert len(recommendations) == 1 # We are not sure about what addon will be recommended in the test. # Only make sure the reported id is among the expected ones and that # it's a webextension. ADDON_IDS = [ value['id'] for value in FAKE_MAPPING.values() if value['isWebextension'] ] assert recommendations[0] in ADDON_IDS