Esempio n. 1
0
    def test_recommendation(self):
        # lets praise user1
        content = 'Goooooood!'
        r1 = Recommendation.add(self.user2, self.user1, content)
        assert r1.from_user == self.user2
        assert r1.to_user == self.user1
        assert r1.content == content

        r2 = Recommendation.add(self.user3, self.user1, content)
        assert r2.from_user == self.user3
        assert r2.to_user == self.user1
        assert r2.content == content

        r3 = Recommendation.add(self.user4, self.user1, content)
        assert r3.from_user == self.user4
        assert r3.to_user == self.user1
        assert r3.content == content

        r4 = Recommendation.add(self.user1, self.user1, content)
        assert r4 is None

        rs = Recommendation.gets_by_user(self.user1)
        assert len(rs) == len([self.user2, self.user3, self.user4])
        # check default sort
        assert rs[0].id == r3.id
Esempio n. 2
0
    def test_recommendation(self):
        self.clean_up()
        # lets praise user1
        content = 'Goooooood!'
        r1 = Recommendation.add(self.user2, self.user1, content)
        assert r1.from_user == self.user2
        assert r1.to_user == self.user1
        assert r1.content == content

        r2 = Recommendation.add(self.user3, self.user1, content)
        assert r2.from_user == self.user3
        assert r2.to_user == self.user1
        assert r2.content == content

        r3 = Recommendation.add(self.user4, self.user1, content)
        assert r3.from_user == self.user4
        assert r3.to_user == self.user1
        assert r3.content == content

        r4 = Recommendation.add(self.user1, self.user1, content)
        assert r4 is None

        rs = Recommendation.gets_by_user(self.user1)
        assert len(rs) == len([self.user2, self.user3, self.user4])
        # check default sort
        assert rs[0].id == r3.id
Esempio n. 3
0
 def add_rec(self, request):
     name = self.name
     if request.method == "POST":
         content = request.get_form_var("content")
         user = request.user
         r = Recommendation.add(from_user=user.name, to_user=self.name, content=content)
         return request.redirect("/people/%s/praises" % name)
     return st("people_add_rec.html", **locals())
Esempio n. 4
0
 def add_rec(self, request):
     name = self.name
     if request.method == "POST":
         content = request.get_form_var('content')
         user = request.user
         r = Recommendation.add(from_user=user.name,
                                to_user=self.name,
                                content=content)
         return request.redirect('/people/%s/praises' % name)
     return st('people_add_rec.html', **locals())
Esempio n. 5
0
    def test_recommendation_vote(self):
        self.clean_up()
        content = 'Goooooood!'
        r1 = Recommendation.add(self.user2, self.user1, content)
        assert r1.from_user == self.user2
        assert r1.to_user == self.user1
        assert r1.content == content

        r1.add_vote(self.user3)
        r1.add_vote(self.user4)

        assert Recommendation.get(
            r1.id).n_vote == len([self.user3, self.user4])

        # duplicate vote
        r1.add_vote(self.user3)
        r1 = Recommendation.get(r1.id)
        assert Recommendation.get(
            r1.id).n_vote == len([self.user3, self.user4])

        assert r1.is_voted(self.user5) is False

        # last vote
        r1.add_vote(self.user5)
        assert Recommendation.get(
            r1.id).n_vote == len([self.user3, self.user4, self.user5])

        # check sord, more vote more ahead
        r2 = Recommendation.add(self.user3, self.user1, content)
        rs = Recommendation.gets_by_user(self.user1)
        assert len(rs) == len([self.user2, self.user3])
        # check default sort
        assert rs[0].id == r1.id

        assert r1.is_voted(self.user3)
        assert r1.is_voted(self.user4)
        assert r1.is_voted(self.user5)
        assert r1.is_voted(self.user1) is False

        assert r2.is_voted(self.user2) is False
        assert r2.is_voted(self.user3) is False
        assert r2.is_voted(self.user5) is False