Debian Codegraph @

test/plugins/test_embyupdate.py

raw
1 import responses
2
3 from beets.test.helper import PluginTestCase
4 from beetsplug import embyupdate
5
6
7 class EmbyUpdateTest(PluginTestCase):
8 plugin = "embyupdate"
9
10 def setUp(self):
11 super().setUp()
12
13 self.config["emby"] = {
14 "host": "localhost",
15 "port": 8096,
16 "username": "username",
17 "password": "password",
18 }
19
20 def test_api_url_only_name(self):
21 assert (
22 embyupdate.api_url(
23 self.config["emby"]["host"].get(),
24 self.config["emby"]["port"].get(),
25 "/Library/Refresh",
26 )
27 == "http://localhost:8096/Library/Refresh?format=json"
28 )
29
30 def test_api_url_http(self):
31 assert (
32 embyupdate.api_url(
33 "http://localhost",
34 self.config["emby"]["port"].get(),
35 "/Library/Refresh",
36 )
37 == "http://localhost:8096/Library/Refresh?format=json"
38 )
39
40 def test_api_url_https(self):
41 assert (
42 embyupdate.api_url(
43 "https://localhost",
44 self.config["emby"]["port"].get(),
45 "/Library/Refresh",
46 )
47 == "https://localhost:8096/Library/Refresh?format=json"
48 )
49
50 def test_password_data(self):
51 assert embyupdate.password_data(
52 self.config["emby"]["username"].get(),
53 self.config["emby"]["password"].get(),
54 ) == {
55 "username": "username",
56 "password": "5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8",
57 "passwordMd5": "5f4dcc3b5aa765d61d8327deb882cf99",
58 }
59
60 def test_create_header_no_token(self):
61 assert embyupdate.create_headers(
62 "e8837bc1-ad67-520e-8cd2-f629e3155721"
63 ) == {
64 "x-emby-authorization": (
65 "MediaBrowser "
66 'UserId="e8837bc1-ad67-520e-8cd2-f629e3155721", '
67 'Client="other", '
68 'Device="beets", '
69 'DeviceId="beets", '
70 'Version="0.0.0"'
71 )
72 }
73
74 def test_create_header_with_token(self):
75 assert embyupdate.create_headers(
76 "e8837bc1-ad67-520e-8cd2-f629e3155721", token="abc123"
77 ) == {
78 "x-emby-authorization": (
79 "MediaBrowser "
80 'UserId="e8837bc1-ad67-520e-8cd2-f629e3155721", '
81 'Client="other", '
82 'Device="beets", '
83 'DeviceId="beets", '
84 'Version="0.0.0"'
85 ),
86 "x-mediabrowser-token": "abc123",
87 }
88
89 @responses.activate
90 def test_get_token(self):
91 body = (
92 '{"User":{"Name":"username", '
93 '"ServerId":"1efa5077976bfa92bc71652404f646ec",'
94 '"Id":"2ec276a2642e54a19b612b9418a8bd3b","HasPassword":true,'
95 '"HasConfiguredPassword":true,'
96 '"HasConfiguredEasyPassword":false,'
97 '"LastLoginDate":"2015-11-09T08:35:03.6357440Z",'
98 '"LastActivityDate":"2015-11-09T08:35:03.6665060Z",'
99 '"Configuration":{"AudioLanguagePreference":"",'
100 '"PlayDefaultAudioTrack":true,"SubtitleLanguagePreference":"",'
101 '"DisplayMissingEpisodes":false,'
102 '"DisplayUnairedEpisodes":false,'
103 '"GroupMoviesIntoBoxSets":false,'
104 '"DisplayChannelsWithinViews":[],'
105 '"ExcludeFoldersFromGrouping":[],"GroupedFolders":[],'
106 '"SubtitleMode":"Default","DisplayCollectionsView":true,'
107 '"DisplayFoldersView":false,"EnableLocalPassword":false,'
108 '"OrderedViews":[],"IncludeTrailersInSuggestions":true,'
109 '"EnableCinemaMode":true,"LatestItemsExcludes":[],'
110 '"PlainFolderViews":[],"HidePlayedInLatest":true,'
111 '"DisplayChannelsInline":false},'
112 '"Policy":{"IsAdministrator":true,"IsHidden":false,'
113 '"IsDisabled":false,"BlockedTags":[],'
114 '"EnableUserPreferenceAccess":true,"AccessSchedules":[],'
115 '"BlockUnratedItems":[],'
116 '"EnableRemoteControlOfOtherUsers":false,'
117 '"EnableSharedDeviceControl":true,'
118 '"EnableLiveTvManagement":true,"EnableLiveTvAccess":true,'
119 '"EnableMediaPlayback":true,'
120 '"EnableAudioPlaybackTranscoding":true,'
121 '"EnableVideoPlaybackTranscoding":true,'
122 '"EnableContentDeletion":false,'
123 '"EnableContentDownloading":true,"EnableSync":true,'
124 '"EnableSyncTranscoding":true,"EnabledDevices":[],'
125 '"EnableAllDevices":true,"EnabledChannels":[],'
126 '"EnableAllChannels":true,"EnabledFolders":[],'
127 '"EnableAllFolders":true,"InvalidLoginAttemptCount":0,'
128 '"EnablePublicSharing":true}},'
129 '"SessionInfo":{"SupportedCommands":[],'
130 '"QueueableMediaTypes":[],"PlayableMediaTypes":[],'
131 '"Id":"89f3b33f8b3a56af22088733ad1d76b3",'
132 '"UserId":"2ec276a2642e54a19b612b9418a8bd3b",'
133 '"UserName":"username","AdditionalUsers":[],'
134 '"ApplicationVersion":"Unknown version",'
135 '"Client":"Unknown app",'
136 '"LastActivityDate":"2015-11-09T08:35:03.6665060Z",'
137 '"DeviceName":"Unknown device","DeviceId":"Unknown device id",'
138 '"SupportsRemoteControl":false,"PlayState":{"CanSeek":false,'
139 '"IsPaused":false,"IsMuted":false,"RepeatMode":"RepeatNone"}},'
140 '"AccessToken":"4b19180cf02748f7b95c7e8e76562fc8",'
141 '"ServerId":"1efa5077976bfa92bc71652404f646ec"}'
142 )
143
144 responses.add(
145 responses.POST,
146 ("http://localhost:8096/Users/AuthenticateByName"),
147 body=body,
148 status=200,
149 content_type="application/json",
150 )
151
152 headers = {
153 "x-emby-authorization": (
154 "MediaBrowser "
155 'UserId="e8837bc1-ad67-520e-8cd2-f629e3155721", '
156 'Client="other", '
157 'Device="beets", '
158 'DeviceId="beets", '
159 'Version="0.0.0"'
160 )
161 }
162
163 auth_data = {
164 "username": "username",
165 "password": "5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8",
166 "passwordMd5": "5f4dcc3b5aa765d61d8327deb882cf99",
167 }
168
169 assert (
170 embyupdate.get_token("http://localhost", 8096, headers, auth_data)
171 == "4b19180cf02748f7b95c7e8e76562fc8"
172 )
173
174 @responses.activate
175 def test_get_user(self):
176 body = (
177 '[{"Name":"username",'
178 '"ServerId":"1efa5077976bfa92bc71652404f646ec",'
179 '"Id":"2ec276a2642e54a19b612b9418a8bd3b","HasPassword":true,'
180 '"HasConfiguredPassword":true,'
181 '"HasConfiguredEasyPassword":false,'
182 '"LastLoginDate":"2015-11-09T08:35:03.6357440Z",'
183 '"LastActivityDate":"2015-11-09T08:42:39.3693220Z",'
184 '"Configuration":{"AudioLanguagePreference":"",'
185 '"PlayDefaultAudioTrack":true,"SubtitleLanguagePreference":"",'
186 '"DisplayMissingEpisodes":false,'
187 '"DisplayUnairedEpisodes":false,'
188 '"GroupMoviesIntoBoxSets":false,'
189 '"DisplayChannelsWithinViews":[],'
190 '"ExcludeFoldersFromGrouping":[],"GroupedFolders":[],'
191 '"SubtitleMode":"Default","DisplayCollectionsView":true,'
192 '"DisplayFoldersView":false,"EnableLocalPassword":false,'
193 '"OrderedViews":[],"IncludeTrailersInSuggestions":true,'
194 '"EnableCinemaMode":true,"LatestItemsExcludes":[],'
195 '"PlainFolderViews":[],"HidePlayedInLatest":true,'
196 '"DisplayChannelsInline":false},'
197 '"Policy":{"IsAdministrator":true,"IsHidden":false,'
198 '"IsDisabled":false,"BlockedTags":[],'
199 '"EnableUserPreferenceAccess":true,"AccessSchedules":[],'
200 '"BlockUnratedItems":[],'
201 '"EnableRemoteControlOfOtherUsers":false,'
202 '"EnableSharedDeviceControl":true,'
203 '"EnableLiveTvManagement":true,"EnableLiveTvAccess":true,'
204 '"EnableMediaPlayback":true,'
205 '"EnableAudioPlaybackTranscoding":true,'
206 '"EnableVideoPlaybackTranscoding":true,'
207 '"EnableContentDeletion":false,'
208 '"EnableContentDownloading":true,'
209 '"EnableSync":true,"EnableSyncTranscoding":true,'
210 '"EnabledDevices":[],"EnableAllDevices":true,'
211 '"EnabledChannels":[],"EnableAllChannels":true,'
212 '"EnabledFolders":[],"EnableAllFolders":true,'
213 '"InvalidLoginAttemptCount":0,"EnablePublicSharing":true}}]'
214 )
215
216 responses.add(
217 responses.GET,
218 "http://localhost:8096/Users/Public",
219 body=body,
220 status=200,
221 content_type="application/json",
222 )
223
224 response = embyupdate.get_user("http://localhost", 8096, "username")
225
226 assert response[0]["Id"] == "2ec276a2642e54a19b612b9418a8bd3b"
227
228 assert response[0]["Name"] == "username"