示例#1
0
 def test_create_similar(self):
     for user, count in find_similar(self.first_user).iteritems():
         Similar(
             user_1=self.first_user, 
             user_2=user, 
             count=count
         ).save()
     similar_list = Similar.objects.filter(user_1=self.first_user)
     self.assertEqual(similar_list.count(), 1)
示例#2
0
def similar_list(request, 
                 template_name="reviewclone/similar_list.html"):
    """
    Finds users with similar reviews using `find_similar`
    The similar rows will be deleted for the current user, then
    each user returned by `find_similar` will be added with the
    `count` of similar reviews.
    """
    similar_dict = find_similar(request.user)
    Similar.objects.filter(user_1=request.user).delete()
    for user, count in similar_dict.iteritems():
        Similar(
            user_1=request.user,
            user_2=user,
            count=count
        ).save() 
    similar = Similar.objects.filter(user_1=request.user)
    return render_to_response(
        template_name,
        {
            'object_list': similar,
        },
        context_instance=RequestContext(request)
    )
示例#3
0
 def test_first_user(self):
     self.assertEqual(len(find_similar(self.first_user)), 1)