forked from lcosmin/boardgamegeek
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_user.py
89 lines (62 loc) · 2.25 KB
/
test_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
import datetime
import time
import pytest
from boardgamegeek import BGGValueError, BGGItemNotFoundError
from _common import *
progress_called = False
def progress_cb(items, total):
global progress_called
logging.debug("progress_cb: fetched {} items out of {}".format(items, total))
progress_called = True
def test_get_user_with_invalid_parameters(bgg):
# test how the module reacts to unexpected parameters
for invalid in [None, ""]:
with pytest.raises(BGGValueError):
bgg.user(invalid)
with pytest.raises(BGGValueError):
bgg.user(TEST_VALID_USER, domain="voodoo")
def test_get_invalid_user_info(bgg, mocker):
mock_get = mocker.patch("requests.sessions.Session.get")
mock_get.side_effect = simulate_bgg
with pytest.raises(BGGItemNotFoundError):
bgg.user(TEST_INVALID_USER, progress=progress_cb)
def test_get_valid_user_info(bgg, mocker, null_logger):
mock_get = mocker.patch("requests.sessions.Session.get")
mock_get.side_effect = simulate_bgg
global progress_called
progress_called = False
user = bgg.user(TEST_USER_WITH_LOTS_OF_FRIENDS, progress=progress_cb)
assert user is not None
assert user.name == TEST_USER_WITH_LOTS_OF_FRIENDS
assert type(user.id) == int
assert progress_called
assert type(user.buddies) == list
assert type(user.guilds) == list
assert type(user.last_login) == datetime.datetime
str(user)
repr(user)
for buddy in user.buddies:
str(buddy)
repr(buddy)
for guild in user.guilds:
repr(guild)
for i in user.top10:
repr(i)
assert i.id >= 0
assert i.name is not None
for i in user.hot10:
repr(i)
assert i.id >= 0
assert i.name is not None
# for coverage's sake
user._format(null_logger)
assert type(user.data()) == dict
# test that fetching user's data without buddies, guilds, hot & top works
user = bgg.user(TEST_VALID_USER, progress=progress_cb, buddies=False, guilds=False, hot=False, top=False)
assert user is not None
assert user.name == TEST_VALID_USER
assert user.id == TEST_VALID_USER_ID
assert user.buddies == []
assert user.guilds == []
assert user.top10 == []
assert user.hot10 == []