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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
|
from datetime import timedelta
from decimal import Decimal
import pytest
from pydantic import ValidationError
class TestBucket:
def test_raises_payout(self):
from generalresearch.models.legacy.bucket import Bucket
with pytest.raises(expected_exception=ValidationError) as e:
Bucket(user_payout_min=123)
assert "Must pass a Decimal" in str(e.value)
with pytest.raises(expected_exception=ValidationError) as e:
Bucket(user_payout_min=Decimal(1 / 3))
assert "Must have 2 or fewer decimal places" in str(e.value)
with pytest.raises(expected_exception=ValidationError) as e:
Bucket(user_payout_min=Decimal(10000))
assert "should be less than 1000" in str(e.value)
with pytest.raises(expected_exception=ValidationError) as e:
Bucket(user_payout_min=Decimal(1), user_payout_max=Decimal("0.01"))
assert "user_payout_min should be <= user_payout_max" in str(e.value)
def test_raises_loi(self):
from generalresearch.models.legacy.bucket import Bucket
with pytest.raises(expected_exception=ValidationError) as e:
Bucket(loi_min=123)
assert "Input should be a valid timedelta" in str(e.value)
with pytest.raises(expected_exception=ValidationError) as e:
Bucket(loi_min=timedelta(seconds=9999))
assert "should be less than 90 minutes" in str(e.value)
with pytest.raises(ValidationError) as e:
Bucket(loi_min=timedelta(seconds=0))
assert "should be greater than 0" in str(e.value)
with pytest.raises(expected_exception=ValidationError) as e:
Bucket(loi_min=timedelta(seconds=10), loi_max=timedelta(seconds=9))
assert "loi_min should be <= loi_max" in str(e.value)
with pytest.raises(expected_exception=ValidationError) as e:
Bucket(
loi_min=timedelta(seconds=10),
loi_max=timedelta(seconds=90),
loi_q1=timedelta(seconds=20),
)
assert "loi_q1, q2, and q3 should all be set" in str(e.value)
with pytest.raises(expected_exception=ValidationError) as e:
Bucket(
loi_min=timedelta(seconds=10),
loi_max=timedelta(seconds=90),
loi_q1=timedelta(seconds=200),
loi_q2=timedelta(seconds=20),
loi_q3=timedelta(seconds=12),
)
assert "loi_q1 should be <= loi_q2" in str(e.value)
def test_parse_1(self):
from generalresearch.models.legacy.bucket import Bucket
b1 = Bucket.parse_from_offerwall({"payout": {"min": 123}})
b_exp = Bucket(
user_payout_min=Decimal("1.23"),
user_payout_max=None,
loi_min=None,
loi_max=None,
)
assert b_exp == b1
b2 = Bucket.parse_from_offerwall({"payout": {"min": 123, "max": 230}})
b_exp = Bucket(
user_payout_min=Decimal("1.23"),
user_payout_max=Decimal("2.30"),
loi_min=None,
loi_max=None,
)
assert b_exp == b2
b3 = Bucket.parse_from_offerwall(
{"payout": {"min": 123, "max": 230}, "duration": {"min": 600, "max": 1800}}
)
b_exp = Bucket(
user_payout_min=Decimal("1.23"),
user_payout_max=Decimal("2.30"),
loi_min=timedelta(seconds=600),
loi_max=timedelta(seconds=1800),
)
assert b_exp == b3
b4 = Bucket.parse_from_offerwall(
{
"payout": {"max": 80, "min": 28, "q1": 43, "q2": 43, "q3": 56},
"duration": {"max": 1172, "min": 266, "q1": 746, "q2": 918, "q3": 1002},
}
)
b_exp = Bucket(
user_payout_min=Decimal("0.28"),
user_payout_max=Decimal("0.80"),
user_payout_q1=Decimal("0.43"),
user_payout_q2=Decimal("0.43"),
user_payout_q3=Decimal("0.56"),
loi_min=timedelta(seconds=266),
loi_max=timedelta(seconds=1172),
loi_q1=timedelta(seconds=746),
loi_q2=timedelta(seconds=918),
loi_q3=timedelta(seconds=1002),
)
assert b_exp == b4
def test_parse_2(self):
from generalresearch.models.legacy.bucket import Bucket
b1 = Bucket.parse_from_offerwall({"min_payout": 123})
b_exp = Bucket(
user_payout_min=Decimal("1.23"),
user_payout_max=None,
loi_min=None,
loi_max=None,
)
assert b_exp == b1
b2 = Bucket.parse_from_offerwall({"min_payout": 123, "max_payout": 230})
b_exp = Bucket(
user_payout_min=Decimal("1.23"),
user_payout_max=Decimal("2.30"),
loi_min=None,
loi_max=None,
)
assert b_exp == b2
b3 = Bucket.parse_from_offerwall(
{
"min_payout": 123,
"max_payout": 230,
"min_duration": 600,
"max_duration": 1800,
}
)
b_exp = Bucket(
user_payout_min=Decimal("1.23"),
user_payout_max=Decimal("2.30"),
loi_min=timedelta(seconds=600),
loi_max=timedelta(seconds=1800),
)
assert b_exp, b3
b4 = Bucket.parse_from_offerwall(
{
"min_payout": 28,
"max_payout": 99,
"min_duration": 205,
"max_duration": 1113,
"q1_payout": 43,
"q2_payout": 43,
"q3_payout": 46,
"q1_duration": 561,
"q2_duration": 891,
"q3_duration": 918,
}
)
b_exp = Bucket(
user_payout_min=Decimal("0.28"),
user_payout_max=Decimal("0.99"),
user_payout_q1=Decimal("0.43"),
user_payout_q2=Decimal("0.43"),
user_payout_q3=Decimal("0.46"),
loi_min=timedelta(seconds=205),
loi_max=timedelta(seconds=1113),
loi_q1=timedelta(seconds=561),
loi_q2=timedelta(seconds=891),
loi_q3=timedelta(seconds=918),
)
assert b_exp == b4
def test_parse_3(self):
from generalresearch.models.legacy.bucket import Bucket
b1 = Bucket.parse_from_offerwall({"payout": 123})
b_exp = Bucket(
user_payout_min=Decimal("1.23"),
user_payout_max=None,
loi_min=None,
loi_max=None,
)
assert b_exp == b1
b2 = Bucket.parse_from_offerwall({"payout": 123, "duration": 1800})
b_exp = Bucket(
user_payout_min=Decimal("1.23"),
user_payout_max=None,
loi_min=None,
loi_max=timedelta(seconds=1800),
)
assert b_exp == b2
|