def test_cant_recommend(test_ctx): ctx = install_mock_data(test_ctx) r = CollaborativeRecommender(ctx) # Test that we can't recommend if we have not enough client info. assert not r.can_recommend({}) assert not r.can_recommend({"installed_addons": []})
def test_can_recommend_no_model(activate_error_responses): r = CollaborativeRecommender() # We should never be able to recommend if something went wrong with the model. assert not r.can_recommend({}) assert not r.can_recommend({"installed_addons": []}) assert not r.can_recommend({"installed_addons": ["*****@*****.**"]})
def test_recommender_str(activate_responses): """Tests that the string representation of the recommender is correct """ # TODO: this test is brittle and should be removed once it is safe # to do so r = CollaborativeRecommender() assert str(r) == "CollaborativeRecommender"
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_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_recommender_str(): """Tests that the string representation of the recommender is correct """ # TODO: this test is brittle and should be removed once it is safe # to do so ctx = get_mocked_ctx() r = CollaborativeRecommender(ctx) assert str(r) == "CollaborativeRecommender"
def test_can_recommend(activate_responses): r = CollaborativeRecommender() # Test that we can't recommend if we have not enough client info. assert not r.can_recommend({}) assert not r.can_recommend({"installed_addons": []}) # Check that we can recommend if we the user has at least an addon. assert r.can_recommend({"installed_addons": ["*****@*****.**"]})
def test_can_recommend(test_ctx): with mock_install_mock_data(test_ctx): r = CollaborativeRecommender(test_ctx) # Check that we can recommend if the user has at least an addon. assert r.can_recommend({ "installed_addons": ["*****@*****.**"], "client_id": "test-client", })
def test_can_recommend_no_model(test_ctx): ctx = install_none_mock_data(test_ctx) r = CollaborativeRecommender(ctx) # We should never be able to recommend if something went wrong with the model. assert not r.can_recommend({}) assert not r.can_recommend({"installed_addons": []}) assert not r.can_recommend( {"installed_addons": ["*****@*****.**"]})
def test_can_recommend(test_ctx): ctx = install_mock_data(test_ctx) r = CollaborativeRecommender(ctx) # For some reason, moto doesn't like to play nice with this call # Check that we can recommend if we the user has at least an addon. assert r.can_recommend({ "installed_addons": ["*****@*****.**"], "client_id": "test-client" })
def test_can_recommend(): ctx = get_mocked_ctx() r = CollaborativeRecommender(ctx) # Test that we can't recommend if we have not enough client info. assert not r.can_recommend({}) assert not r.can_recommend({"installed_addons": []}) # Check that we can recommend if we the user has at least an addon. assert r.can_recommend({"installed_addons": ["*****@*****.**"]})
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
def test_empty_recommendations(activate_responses): # Tests that the empty recommender always recommends an empty list # of addons if we have no addons r = CollaborativeRecommender() assert not r.can_recommend({})
def test_recommender_str(activate_responses): # Tests that the string representation of the recommender is correct r = CollaborativeRecommender() assert str(r) == "CollaborativeRecommender"
def test_empty_recommendations(): # Tests that the empty recommender always recommends an empty list # of addons if we have no addons ctx = get_mocked_ctx() r = CollaborativeRecommender(ctx) assert not r.can_recommend({})
def test_empty_recommendations(test_ctx): # Tests that the empty recommender always recommends an empty list # of addons if we have no addons ctx = install_none_mock_data(test_ctx) r = CollaborativeRecommender(ctx) assert not r.can_recommend({})