-
-
Notifications
You must be signed in to change notification settings - Fork 82
/
test_search.py
193 lines (176 loc) · 6.64 KB
/
test_search.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
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
import pytest
from tests import TestSearchResult
from yandex_music import Search, SearchResult
@pytest.fixture(scope='class')
def search_result(results, types):
def make_search_result(param):
return SearchResult(
types[param], TestSearchResult.total, TestSearchResult.per_page, TestSearchResult.order, [results[param]]
)
return make_search_result
@pytest.fixture(scope='class')
def search(best, search_result):
return Search(
TestSearch.search_request_id,
TestSearch.text,
best,
search_result(3),
search_result(2),
search_result(4),
search_result(1),
search_result(5),
search_result(13),
search_result(14),
search_result(15),
TestSearch.type_,
TestSearch.page,
TestSearch.per_page,
TestSearch.misspell_result,
TestSearch.misspell_original,
TestSearch.misspell_corrected,
TestSearch.nocorrect,
)
class TestSearch:
search_request_id = (
'myt1-0261-c2e-msk-myt-music-st-e72-18274.gencfg-c.yandex.net-1573323135801461'
'-3742331365077765411-1573323135819 '
)
text = 'NCS'
type_ = 'artist'
page = 0
per_page = 10
misspell_result = 'era ameno'
misspell_original = 'ero amen'
misspell_corrected = False
nocorrect = False
def test_expected_values(self, search, best, search_result):
assert search.search_request_id == self.search_request_id
assert search.text == self.text
assert search.best == best
assert search.albums == search_result(3)
assert search.artists == search_result(2)
assert search.playlists == search_result(4)
assert search.tracks == search_result(1)
assert search.videos == search_result(5)
assert search.users == search_result(13)
assert search.podcasts == search_result(14)
assert search.podcast_episodes == search_result(15)
assert search.type == self.type_
assert search.page == self.page
assert search.per_page == self.per_page
assert search.misspell_result == self.misspell_result
assert search.misspell_original == self.misspell_original
assert search.misspell_corrected == self.misspell_corrected
assert search.nocorrect == self.nocorrect
def test_de_json_none(self, client):
assert Search.de_json({}, client) is None
def test_de_json_required(self, client, best, search_result):
json_dict = {
'search_request_id': self.search_request_id,
'text': self.text,
'best': best.to_dict(),
'albums': search_result(3).to_dict(),
'artists': search_result(2).to_dict(),
'playlists': search_result(4).to_dict(),
'tracks': search_result(1).to_dict(),
'videos': search_result(5).to_dict(),
'users': search_result(13).to_dict(),
'podcasts': search_result(14).to_dict(),
'podcast_episodes': search_result(15).to_dict(),
}
search = Search.de_json(json_dict, client)
assert search.search_request_id == self.search_request_id
assert search.text == self.text
assert search.best == best
assert search.albums == search_result(3)
assert search.artists == search_result(2)
assert search.playlists == search_result(4)
assert search.tracks == search_result(1)
assert search.videos == search_result(5)
assert search.users == search_result(13)
assert search.podcasts == search_result(14)
assert search.podcast_episodes == search_result(15)
def test_de_json_all(self, client, best, search_result):
json_dict = {
'search_request_id': self.search_request_id,
'text': self.text,
'best': best.to_dict(),
'albums': search_result(3).to_dict(),
'artists': search_result(2).to_dict(),
'playlists': search_result(4).to_dict(),
'tracks': search_result(1).to_dict(),
'videos': search_result(5).to_dict(),
'users': search_result(13).to_dict(),
'podcasts': search_result(14).to_dict(),
'podcast_episodes': search_result(15).to_dict(),
'misspell_corrected': self.misspell_corrected,
'nocorrect': self.nocorrect,
'type': self.type_,
'page': self.page,
'per_page': self.per_page,
'misspell_result': self.misspell_result,
'misspell_original': self.misspell_original,
}
search = Search.de_json(json_dict, client)
assert search.search_request_id == self.search_request_id
assert search.text == self.text
assert search.best == best
assert search.albums == search_result(3)
assert search.artists == search_result(2)
assert search.playlists == search_result(4)
assert search.tracks == search_result(1)
assert search.videos == search_result(5)
assert search.users == search_result(13)
assert search.podcasts == search_result(14)
assert search.podcast_episodes == search_result(15)
assert search.type == self.type_
assert search.page == self.page
assert search.per_page == self.per_page
assert search.misspell_result == self.misspell_result
assert search.misspell_original == self.misspell_original
assert search.misspell_corrected == self.misspell_corrected
assert search.nocorrect == self.nocorrect
def test_equality(self, best, search_result):
a = Search(
self.search_request_id,
self.text,
best,
search_result(3),
search_result(2),
search_result(4),
search_result(1),
search_result(5),
search_result(13),
search_result(14),
search_result(15),
)
b = Search(
self.search_request_id,
'',
best,
search_result(3),
None,
search_result(4),
search_result(1),
search_result(5),
search_result(13),
None,
search_result(15),
)
c = Search(
self.search_request_id,
self.text,
best,
search_result(3),
search_result(2),
search_result(4),
search_result(1),
search_result(5),
search_result(13),
search_result(14),
search_result(15),
)
assert a != b
assert hash(a) != hash(b)
assert a is not b
assert a == c