blob: 4583c4653fdf8f5ce16af56efceb360b54b7ba65 (
plain)
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
|
from itertools import groupby
from random import shuffle as rshuffle
from generalresearch.models.thl.product import (
UserWalletConfig,
)
from generalresearch.models.thl.wallet import PayoutType
def all_equal(iterable):
g = groupby(iterable)
return next(g, True) and not next(g, False)
class TestProductUserWalletConfig:
def test_init(self):
instance = UserWalletConfig()
assert isinstance(instance, UserWalletConfig)
# Check the defaults
assert not instance.enabled
assert not instance.amt
assert isinstance(instance.supported_payout_types, set)
assert len(instance.supported_payout_types) == 3
assert instance.min_cashout is None
def test_model_dump(self):
instance = UserWalletConfig()
# If we use the defaults, the supported_payout_types are always
# in the same order because they're the same
assert isinstance(instance.model_dump_json(), str)
res = []
for idx in range(100):
res.append(instance.model_dump_json())
assert all_equal(res)
def test_model_dump_payout_types(self):
res = []
for idx in range(100):
# Generate a random order of PayoutTypes each time
payout_types = [e for e in PayoutType]
rshuffle(payout_types)
instance = UserWalletConfig.model_validate(
{"supported_payout_types": payout_types}
)
res.append(instance.model_dump_json())
assert all_equal(res)
|