Parent: [da33a6] (diff)

Child: [9932c8] (diff)

Download this file

test_mixins.py    61 lines (44 with data), 1.9 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
from mock import Mock
from allura.model import VotableArtifact
class TestVotableArtifact(object):
def setUp(self):
self.user1 = Mock()
self.user1.username = 'test-user'
self.user2 = Mock()
self.user2.username = 'user2'
def test_vote_up(self):
vote = VotableArtifact()
vote.vote_up(self.user1)
assert vote.votes_up == 1
assert vote.votes_up_users == [self.user1.username]
vote.vote_up(self.user1)
assert vote.votes_up == 1, 'Same user can vote only once'
assert vote.votes_up_users == [self.user1.username]
vote.vote_up(self.user2)
assert vote.votes_up == 2
assert vote.votes_up_users == [self.user1.username,
self.user2.username]
assert vote.votes_down == 0, 'vote_down must be 0 if we voted up only'
assert len(vote.votes_down_users) == 0
def test_vote_down(self):
vote = VotableArtifact()
vote.vote_down(self.user1)
assert vote.votes_down == 1
assert vote.votes_down_users == [self.user1.username]
vote.vote_down(self.user1)
assert vote.votes_down == 1, 'Same user can vote only once'
assert vote.votes_down_users == [self.user1.username]
vote.vote_down(self.user2)
assert vote.votes_down == 2
assert vote.votes_down_users == [self.user1.username,
self.user2.username]
assert vote.votes_up == 0, 'vote_up must be 0 if we voted down only'
assert len(vote.votes_up_users) == 0
def test_change_vote(self):
vote = VotableArtifact()
vote.vote_up(self.user1)
vote.vote_down(self.user1)
assert vote.votes_down == 1
assert vote.votes_down_users == [self.user1.username]
assert vote.votes_up == 0
assert len(vote.votes_up_users) == 0