##// END OF EJS Templates
tests: ensure we never hit same user_id twice in voting tests.
marcink -
r3274:7a9fae48 default
parent child Browse files
Show More
@@ -1,127 +1,127 b''
1 1 # -*- coding: utf-8 -*-
2 2
3 3 # Copyright (C) 2010-2018 RhodeCode GmbH
4 4 #
5 5 # This program is free software: you can redistribute it and/or modify
6 6 # it under the terms of the GNU Affero General Public License, version 3
7 7 # (only), as published by the Free Software Foundation.
8 8 #
9 9 # This program is distributed in the hope that it will be useful,
10 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 12 # GNU General Public License for more details.
13 13 #
14 14 # You should have received a copy of the GNU Affero General Public License
15 15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
16 16 #
17 17 # This program is dual-licensed. If you wish to learn more about the
18 18 # RhodeCode Enterprise Edition, including its added features, Support services,
19 19 # and proprietary license terms, please see https://rhodecode.com/licenses/
20 20
21 21 import pytest
22 22 import random
23 23 from mock import Mock, MagicMock
24 24 from rhodecode.model import db
25 25 from rhodecode.model.changeset_status import ChangesetStatusModel
26 26
27 27
28 28 status_approved = db.ChangesetStatus.STATUS_APPROVED
29 29 status_rejected = db.ChangesetStatus.STATUS_REJECTED
30 30 status_under_review = db.ChangesetStatus.STATUS_UNDER_REVIEW
31 31
32 32
33 33 pytestmark = [
34 34 pytest.mark.backends("git", "hg"),
35 35 ]
36 36
37 37
38 38 class ReviewerMock(object):
39 39 def __init__(self, reviewer_def):
40 40 self.reviewer_def = reviewer_def
41 41
42 42 def rule_user_group_data(self):
43 43 return {'vote_rule': self.reviewer_def['vote_rule']}
44 44
45 45
46 46 class MemberMock(object):
47 47 def __init__(self, reviewer_def):
48 48 self.reviewer_def = reviewer_def
49 self.user_id = random.randint(1, 1024)
49 self.user_id = random.randint(1, 1024*1024)
50 50
51 51
52 52 class Statuses(object):
53 53 def __init__(self, member_status):
54 54 self.member_status = member_status
55 55
56 56 def get_statuses(self):
57 57 if not self.member_status:
58 58 return []
59 59
60 60 ver = 1
61 61 latest = MagicMock(status=self.member_status)
62 62 return [
63 63 [ver, latest]
64 64 ]
65 65
66 66
67 67 @pytest.mark.parametrize("reviewers_def, expected_votes", [
68 68 # empty values
69 69 ({},
70 70 []),
71 71
72 72 # 3 members, 1 votes approved, 2 approvals required
73 73 ({'members': [status_approved, None, None], 'vote_rule':2},
74 74 [status_approved, status_under_review, status_under_review]),
75 75
76 76 # 3 members, 2 approvals required
77 77 ({'members': [status_approved, status_approved, None], 'vote_rule': 2},
78 78 [status_approved, status_approved, status_approved]),
79 79
80 80 # 3 members, 3 approvals required
81 81 ({'members': [status_approved, status_approved, None], 'vote_rule': 3},
82 82 [status_approved, status_approved, status_under_review]),
83 83
84 84 # 3 members, 1 votes approved, 2 approvals required
85 85 ({'members': [status_approved, status_approved, status_rejected], 'vote_rule': 2},
86 86 [status_approved, status_approved, status_approved]),
87 87
88 88 # 2 members, 1 votes approved, ALL approvals required
89 89 ({'members': [status_approved, None,], 'vote_rule': -1},
90 90 [status_approved, status_under_review]),
91 91
92 92 # 4 members, 2 votes approved, 2 rejected, 3 approvals required
93 93 ({'members': [status_approved, status_rejected, status_approved, status_rejected], 'vote_rule': 3},
94 94 [status_approved, status_rejected, status_approved, status_rejected]),
95 95
96 96 # 2 members, ALL approvals required
97 97 ({'members': [status_approved, status_approved], 'vote_rule': -1},
98 98 [status_approved, status_approved]),
99 99
100 100 # 3 members, 4 approvals required
101 101 ({'members': [status_approved, None, None], 'vote_rule': 4},
102 102 [status_approved, status_under_review, status_under_review]),
103 103
104 104 # 4 members, 3 approvals required
105 105 ({'members': [status_approved, status_approved, status_rejected, status_approved], 'vote_rule': 3},
106 106 [status_approved, status_approved, status_approved, status_approved]),
107 107
108 108 # 4 members, 3 approvals required
109 109 ({'members': [status_rejected, status_rejected, status_approved, status_approved], 'vote_rule': 3},
110 110 [status_rejected, status_rejected, status_approved, status_approved]),
111 111
112 112 ])
113 113 def test_calculate_group_vote(reviewers_def, expected_votes):
114 114 reviewers_data = []
115 115
116 116 for member_status in reviewers_def.get('members', []):
117 117 mandatory_flag = True
118 118 reviewers_data.append((
119 119 ReviewerMock(reviewers_def),
120 120 MemberMock(reviewers_def),
121 121 'Test Reason',
122 122 mandatory_flag,
123 123 Statuses(member_status).get_statuses()
124 124 ))
125 125
126 126 votes = ChangesetStatusModel().calculate_group_vote(123, reviewers_data)
127 127 assert votes == expected_votes
General Comments 0
You need to be logged in to leave comments. Login now