-
Notifications
You must be signed in to change notification settings - Fork 20
/
test_voting_user.py
115 lines (91 loc) · 3.47 KB
/
test_voting_user.py
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
from uuid import UUID
import pytest
from myapp.application.domain.model.identifier.article_id import ArticleId
from myapp.application.domain.model.identifier.user_id import UserId
from myapp.application.domain.model.karma import Karma
from myapp.application.domain.model.vote import Vote
from myapp.application.domain.model.vote_for_article_result import (
AlreadyVotedResult, InsufficientKarmaResult,
SuccessfullyVotedResult
)
from myapp.application.domain.model.voting_user import ArticleVote, VotingUser
def test_vote_for_article_twice_returns_already_voted_result(
voting_user_who_has_voted: VotingUser,
article_id_for_which_user_has_voted: ArticleId,
a_vote: Vote,
expected_already_voted_result: AlreadyVotedResult
):
voting_result = voting_user_who_has_voted.vote_for_article(
article_id_for_which_user_has_voted,
a_vote
)
assert voting_result == expected_already_voted_result
def test_vote_for_article_returns_successfully_voted_result(
voting_user_who_has_not_voted: VotingUser,
article_id_for_which_user_has_voted: ArticleId,
expected_successfully_voted_result: SuccessfullyVotedResult
):
voting_result = voting_user_who_has_not_voted.vote_for_article(
article_id_for_which_user_has_voted,
Vote.DOWN
)
assert voting_result == expected_successfully_voted_result
def test_cannot_vote_for_article_with_insufficient_karma(
voting_user_with_insufficient_karma_for_voting: VotingUser,
an_article_id: ArticleId,
a_vote: Vote,
expected_insufficient_karma_result: InsufficientKarmaResult
):
voting_result = voting_user_with_insufficient_karma_for_voting.vote_for_article(
an_article_id,
a_vote
)
assert voting_result == expected_insufficient_karma_result
@pytest.fixture(scope='module')
def article_id_for_which_user_has_voted() -> ArticleId:
return ArticleId(UUID('4df32c92-0000-0000-0000-000000000000'))
@pytest.fixture(scope='module')
def voting_user_who_has_voted() -> VotingUser:
return VotingUser(
UserId(UUID('7ebd50e7-0000-0000-0000-000000000000')),
Karma(10),
[
ArticleVote(
ArticleId(UUID('4df32c92-0000-0000-0000-000000000000')),
UserId(UUID('7ebd50e7-0000-0000-0000-000000000000')),
Vote.DOWN
)
]
)
@pytest.fixture(scope='module')
def expected_already_voted_result() -> AlreadyVotedResult:
return AlreadyVotedResult(
ArticleId(UUID('4df32c92-0000-0000-0000-000000000000')),
UserId(UUID('7ebd50e7-0000-0000-0000-000000000000'))
)
@pytest.fixture(scope='module')
def voting_user_who_has_not_voted() -> VotingUser:
return VotingUser(
UserId(UUID('c23ec6da-0000-0000-0000-000000000000')),
Karma(10),
[]
)
@pytest.fixture(scope='module')
def expected_successfully_voted_result() -> SuccessfullyVotedResult:
return SuccessfullyVotedResult(
ArticleId(UUID('4df32c92-0000-0000-0000-000000000000')),
UserId(UUID('c23ec6da-0000-0000-0000-000000000000')),
Vote.DOWN
)
@pytest.fixture(scope='module')
def voting_user_with_insufficient_karma_for_voting() -> VotingUser:
return VotingUser(
UserId(UUID('d826bff6-0000-0000-0000-000000000000')),
Karma(4),
[]
)
@pytest.fixture(scope='module')
def expected_insufficient_karma_result() -> InsufficientKarmaResult:
return InsufficientKarmaResult(
UserId(UUID('d826bff6-0000-0000-0000-000000000000'))
)