コード例 #1
0
 def test_get_not_default(self):
     """
     [recommendation.core.Util] Test get "not default" recommendation controller
     """
     try:
         get_controller("not default")
         assert False, "Not default controller is not throwing ControllerNotDefined exception"
     except ControllerNotDefined:
         pass
コード例 #2
0
 def test_get_default(self):
     """
     [recommendation.core.Util] Test get default recommendation controller
     """
     try:
         rec = get_controller()
     except ControllerNotDefined:
         assert False, "Default controller is throwing ControllerNotDefined exception"
     assert isinstance(rec, IController), "Recommendation in result is not IController instance"
コード例 #3
0
ファイル: views.py プロジェクト: anukat2015/frappe
    def get(self, request, user_external_id, number_of_recommendations=5):
        """
        Get method to request recommendations

        :param request: This is the request. It is not needed but has to be here because of the django interface with
        views.
        :param user_external_id: The user that want the recommendation ore the object of the recommendations.
        :param number_of_recommendations: Number of recommendations that are requested.
        :return: A HTTP response with a list of recommendations.
        """
        # connection.close()
        # Here is the decorator for recommendation
        recommended_apps = \
            get_controller().get_external_id_recommendations(user_external_id, int(number_of_recommendations))

        data = {"user": user_external_id, "recommendations": recommended_apps}
        return self.format_response(data)
コード例 #4
0
ファイル: views.py プロジェクト: mozilla/frappe
    def get(self, request, user_external_id, number_of_recommendations=5):
        """
        Get method to request recommendations

        :param request: This is the request. It is not needed but has to be here because of the django interface with
        views.
        :param user_external_id: The user that want the recommendation ore the object of the recommendations.
        :param number_of_recommendations: Number of recommendations that are requested.
        :return: A HTTP response with a list of recommendations.
        """
        # connection.close()
        # Here is the decorator for recommendation
        recommended_apps = \
            get_controller().get_external_id_recommendations(user_external_id, int(number_of_recommendations))

        data = {"user": user_external_id, "recommendations": recommended_apps}
        return self.format_response(data)
コード例 #5
0
    def test_check_std_recommendation(self):
        """
        [recommendation.core.TensorCoFiController] Test get default recommendation
        """
        rec_controller = get_controller()
        for u in USERS:
            recommendation = rec_controller.get_recommendation(user=User.get_user_by_external_id(u["external_id"]), n=5)
            assert len(recommendation) == 5, "Size of recommendation is not right"

    #@ut.skipIf("default" not in RECOMMENDATION_SETTINGS, "Default recommendation is not defined")
    #def test_check_alternative_recommendation(self):
    #    """
    #    [recommendation.core.TensorCoFiController] Test get alternative recommendation
    #    """
    #    rec_controller = get_controller()
    #    pop_result = \
    #        [aid+1 for aid, _ in sorted(enumerate(Popularity.get_model().recommendation),
    #                                    key=lambda x: x[1], reverse=True)]
    #    for name in ["Gepeto", "Son_Goku", "Peter_Pan", "Tony_Montana", "Lady_Diana"]:
    #        user = User.objects.create(external_id=name)
    #        recommendation = rec_controller.get_recommendation(user=user, n=5)
    #        #assert len(recommendation) == 5, "Size of recommendation is not right"
    #        assert recommendation == pop_result[:len(recommendation)], \
    #            "Recommendation is not popularity for user %s (%s != %s)" % (user, recommendation, pop_result)