forked from beetbox/beets
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_web.py
686 lines (525 loc) · 26.2 KB
/
test_web.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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
"""Tests for the 'web' plugin"""
import json
import unittest
import os.path
import shutil
from test import _common
from beets.library import Item, Album
from beetsplug import web
import platform
from beets import logging
class WebPluginTest(_common.LibTestCase):
def setUp(self):
super().setUp()
self.log = logging.getLogger('beets.web')
if platform.system() == 'Windows':
self.path_prefix = 'C:'
else:
self.path_prefix = ''
# Add fixtures
for track in self.lib.items():
track.remove()
# Add library elements. Note that self.lib.add overrides any "id=<n>"
# and assigns the next free id number.
# The following adds will create items #1, #2 and #3
path1 = self.path_prefix + os.sep + \
os.path.join(b'path_1').decode('utf-8')
self.lib.add(Item(title='title',
path=path1,
album_id=2,
artist='AAA Singers'))
path2 = self.path_prefix + os.sep + \
os.path.join(b'somewhere', b'a').decode('utf-8')
self.lib.add(Item(title='another title',
path=path2,
artist='AAA Singers'))
path3 = self.path_prefix + os.sep + \
os.path.join(b'somewhere', b'abc').decode('utf-8')
self.lib.add(Item(title='and a third',
testattr='ABC',
path=path3,
album_id=2))
# The following adds will create albums #1 and #2
self.lib.add(Album(album='album',
albumtest='xyz'))
path4 = self.path_prefix + os.sep + \
os.path.join(b'somewhere2', b'art_path_2').decode('utf-8')
self.lib.add(Album(album='other album',
artpath=path4))
web.app.config['TESTING'] = True
web.app.config['lib'] = self.lib
web.app.config['INCLUDE_PATHS'] = False
web.app.config['READONLY'] = True
self.client = web.app.test_client()
def test_config_include_paths_true(self):
web.app.config['INCLUDE_PATHS'] = True
response = self.client.get('/item/1')
res_json = json.loads(response.data.decode('utf-8'))
expected_path = self.path_prefix + os.sep \
+ os.path.join(b'path_1').decode('utf-8')
self.assertEqual(response.status_code, 200)
self.assertEqual(res_json['path'], expected_path)
web.app.config['INCLUDE_PATHS'] = False
def test_config_include_artpaths_true(self):
web.app.config['INCLUDE_PATHS'] = True
response = self.client.get('/album/2')
res_json = json.loads(response.data.decode('utf-8'))
expected_path = self.path_prefix + os.sep \
+ os.path.join(b'somewhere2', b'art_path_2').decode('utf-8')
self.assertEqual(response.status_code, 200)
self.assertEqual(res_json['artpath'], expected_path)
web.app.config['INCLUDE_PATHS'] = False
def test_config_include_paths_false(self):
web.app.config['INCLUDE_PATHS'] = False
response = self.client.get('/item/1')
res_json = json.loads(response.data.decode('utf-8'))
self.assertEqual(response.status_code, 200)
self.assertNotIn('path', res_json)
def test_config_include_artpaths_false(self):
web.app.config['INCLUDE_PATHS'] = False
response = self.client.get('/album/2')
res_json = json.loads(response.data.decode('utf-8'))
self.assertEqual(response.status_code, 200)
self.assertNotIn('artpath', res_json)
def test_get_all_items(self):
response = self.client.get('/item/')
res_json = json.loads(response.data.decode('utf-8'))
self.assertEqual(response.status_code, 200)
self.assertEqual(len(res_json['items']), 3)
def test_get_single_item_by_id(self):
response = self.client.get('/item/1')
res_json = json.loads(response.data.decode('utf-8'))
self.assertEqual(response.status_code, 200)
self.assertEqual(res_json['id'], 1)
self.assertEqual(res_json['title'], 'title')
def test_get_multiple_items_by_id(self):
response = self.client.get('/item/1,2')
res_json = json.loads(response.data.decode('utf-8'))
self.assertEqual(response.status_code, 200)
self.assertEqual(len(res_json['items']), 2)
response_titles = {item['title'] for item in res_json['items']}
self.assertEqual(response_titles, {'title', 'another title'})
def test_get_single_item_not_found(self):
response = self.client.get('/item/4')
self.assertEqual(response.status_code, 404)
def test_get_single_item_by_path(self):
data_path = os.path.join(_common.RSRC, b'full.mp3')
self.lib.add(Item.from_path(data_path))
response = self.client.get('/item/path/' + data_path.decode('utf-8'))
res_json = json.loads(response.data.decode('utf-8'))
self.assertEqual(response.status_code, 200)
self.assertEqual(res_json['title'], 'full')
def test_get_single_item_by_path_not_found_if_not_in_library(self):
data_path = os.path.join(_common.RSRC, b'full.mp3')
# data_path points to a valid file, but we have not added the file
# to the library.
response = self.client.get('/item/path/' + data_path.decode('utf-8'))
self.assertEqual(response.status_code, 404)
def test_get_item_empty_query(self):
""" testing item query: <empty> """
response = self.client.get('/item/query/')
res_json = json.loads(response.data.decode('utf-8'))
self.assertEqual(response.status_code, 200)
self.assertEqual(len(res_json['items']), 3)
def test_get_simple_item_query(self):
""" testing item query: another """
response = self.client.get('/item/query/another')
res_json = json.loads(response.data.decode('utf-8'))
self.assertEqual(response.status_code, 200)
self.assertEqual(len(res_json['results']), 1)
self.assertEqual(res_json['results'][0]['title'],
'another title')
def test_query_item_string(self):
""" testing item query: testattr:ABC """
response = self.client.get('/item/query/testattr%3aABC')
res_json = json.loads(response.data.decode('utf-8'))
self.assertEqual(response.status_code, 200)
self.assertEqual(len(res_json['results']), 1)
self.assertEqual(res_json['results'][0]['title'],
'and a third')
def test_query_item_regex(self):
""" testing item query: testattr::[A-C]+ """
response = self.client.get('/item/query/testattr%3a%3a[A-C]%2b')
res_json = json.loads(response.data.decode('utf-8'))
self.assertEqual(response.status_code, 200)
self.assertEqual(len(res_json['results']), 1)
self.assertEqual(res_json['results'][0]['title'],
'and a third')
def test_query_item_regex_backslash(self):
# """ testing item query: testattr::\w+ """
response = self.client.get('/item/query/testattr%3a%3a%5cw%2b')
res_json = json.loads(response.data.decode('utf-8'))
self.assertEqual(response.status_code, 200)
self.assertEqual(len(res_json['results']), 1)
self.assertEqual(res_json['results'][0]['title'],
'and a third')
def test_query_item_path(self):
# """ testing item query: path:\somewhere\a """
""" Note: path queries are special: the query item must match the path
from the root all the way to a directory, so this matches 1 item """
""" Note: filesystem separators in the query must be '\' """
response = self.client.get('/item/query/path:'
+ self.path_prefix
+ '\\somewhere\\a')
res_json = json.loads(response.data.decode('utf-8'))
self.assertEqual(response.status_code, 200)
self.assertEqual(len(res_json['results']), 1)
self.assertEqual(res_json['results'][0]['title'],
'another title')
def test_get_all_albums(self):
response = self.client.get('/album/')
res_json = json.loads(response.data.decode('utf-8'))
self.assertEqual(response.status_code, 200)
response_albums = [album['album'] for album in res_json['albums']]
self.assertCountEqual(response_albums, ['album', 'other album'])
def test_get_single_album_by_id(self):
response = self.client.get('/album/2')
res_json = json.loads(response.data.decode('utf-8'))
self.assertEqual(response.status_code, 200)
self.assertEqual(res_json['id'], 2)
self.assertEqual(res_json['album'], 'other album')
def test_get_multiple_albums_by_id(self):
response = self.client.get('/album/1,2')
res_json = json.loads(response.data.decode('utf-8'))
self.assertEqual(response.status_code, 200)
response_albums = [album['album'] for album in res_json['albums']]
self.assertCountEqual(response_albums, ['album', 'other album'])
def test_get_album_empty_query(self):
response = self.client.get('/album/query/')
res_json = json.loads(response.data.decode('utf-8'))
self.assertEqual(response.status_code, 200)
self.assertEqual(len(res_json['albums']), 2)
def test_get_simple_album_query(self):
response = self.client.get('/album/query/other')
res_json = json.loads(response.data.decode('utf-8'))
self.assertEqual(response.status_code, 200)
self.assertEqual(len(res_json['results']), 1)
self.assertEqual(res_json['results'][0]['album'],
'other album')
self.assertEqual(res_json['results'][0]['id'], 2)
def test_get_album_details(self):
response = self.client.get('/album/2?expand')
res_json = json.loads(response.data.decode('utf-8'))
self.assertEqual(response.status_code, 200)
self.assertEqual(len(res_json['items']), 2)
self.assertEqual(res_json['items'][0]['album'],
'other album')
self.assertEqual(res_json['items'][1]['album'],
'other album')
response_track_titles = {item['title'] for item in res_json['items']}
self.assertEqual(response_track_titles, {'title', 'and a third'})
def test_query_album_string(self):
""" testing query: albumtest:xy """
response = self.client.get('/album/query/albumtest%3axy')
res_json = json.loads(response.data.decode('utf-8'))
self.assertEqual(response.status_code, 200)
self.assertEqual(len(res_json['results']), 1)
self.assertEqual(res_json['results'][0]['album'],
'album')
def test_query_album_artpath_regex(self):
""" testing query: artpath::art_ """
response = self.client.get('/album/query/artpath%3a%3aart_')
res_json = json.loads(response.data.decode('utf-8'))
self.assertEqual(response.status_code, 200)
self.assertEqual(len(res_json['results']), 1)
self.assertEqual(res_json['results'][0]['album'],
'other album')
def test_query_album_regex_backslash(self):
# """ testing query: albumtest::\w+ """
response = self.client.get('/album/query/albumtest%3a%3a%5cw%2b')
res_json = json.loads(response.data.decode('utf-8'))
self.assertEqual(response.status_code, 200)
self.assertEqual(len(res_json['results']), 1)
self.assertEqual(res_json['results'][0]['album'],
'album')
def test_get_stats(self):
response = self.client.get('/stats')
res_json = json.loads(response.data.decode('utf-8'))
self.assertEqual(response.status_code, 200)
self.assertEqual(res_json['items'], 3)
self.assertEqual(res_json['albums'], 2)
def test_delete_item_id(self):
web.app.config['READONLY'] = False
# Create a temporary item
item_id = self.lib.add(Item(title='test_delete_item_id',
test_delete_item_id=1))
# Check we can find the temporary item we just created
response = self.client.get('/item/' + str(item_id))
res_json = json.loads(response.data.decode('utf-8'))
self.assertEqual(response.status_code, 200)
self.assertEqual(res_json['id'], item_id)
# Delete item by id
response = self.client.delete('/item/' + str(item_id))
res_json = json.loads(response.data.decode('utf-8'))
self.assertEqual(response.status_code, 200)
# Check the item has gone
response = self.client.get('/item/' + str(item_id))
self.assertEqual(response.status_code, 404)
# Note: if this fails, the item may still be around
# and may cause other tests to fail
def test_delete_item_without_file(self):
web.app.config['READONLY'] = False
# Create an item with a file
ipath = os.path.join(self.temp_dir, b'testfile1.mp3')
shutil.copy(os.path.join(_common.RSRC, b'full.mp3'), ipath)
self.assertTrue(os.path.exists(ipath))
item_id = self.lib.add(Item.from_path(ipath))
# Check we can find the temporary item we just created
response = self.client.get('/item/' + str(item_id))
res_json = json.loads(response.data.decode('utf-8'))
self.assertEqual(response.status_code, 200)
self.assertEqual(res_json['id'], item_id)
# Delete item by id, without deleting file
response = self.client.delete('/item/' + str(item_id))
res_json = json.loads(response.data.decode('utf-8'))
self.assertEqual(response.status_code, 200)
# Check the item has gone
response = self.client.get('/item/' + str(item_id))
self.assertEqual(response.status_code, 404)
# Check the file has not gone
self.assertTrue(os.path.exists(ipath))
os.remove(ipath)
def test_delete_item_with_file(self):
web.app.config['READONLY'] = False
# Create an item with a file
ipath = os.path.join(self.temp_dir, b'testfile2.mp3')
shutil.copy(os.path.join(_common.RSRC, b'full.mp3'), ipath)
self.assertTrue(os.path.exists(ipath))
item_id = self.lib.add(Item.from_path(ipath))
# Check we can find the temporary item we just created
response = self.client.get('/item/' + str(item_id))
res_json = json.loads(response.data.decode('utf-8'))
self.assertEqual(response.status_code, 200)
self.assertEqual(res_json['id'], item_id)
# Delete item by id, with file
response = self.client.delete('/item/' + str(item_id) + '?delete')
res_json = json.loads(response.data.decode('utf-8'))
self.assertEqual(response.status_code, 200)
# Check the item has gone
response = self.client.get('/item/' + str(item_id))
self.assertEqual(response.status_code, 404)
# Check the file has gone
self.assertFalse(os.path.exists(ipath))
def test_delete_item_query(self):
web.app.config['READONLY'] = False
# Create a temporary item
self.lib.add(Item(title='test_delete_item_query',
test_delete_item_query=1))
# Check we can find the temporary item we just created
response = self.client.get('/item/query/test_delete_item_query')
res_json = json.loads(response.data.decode('utf-8'))
self.assertEqual(response.status_code, 200)
self.assertEqual(len(res_json['results']), 1)
# Delete item by query
response = self.client.delete('/item/query/test_delete_item_query')
res_json = json.loads(response.data.decode('utf-8'))
self.assertEqual(response.status_code, 200)
# Check the item has gone
response = self.client.get('/item/query/test_delete_item_query')
res_json = json.loads(response.data.decode('utf-8'))
self.assertEqual(response.status_code, 200)
self.assertEqual(len(res_json['results']), 0)
def test_delete_item_all_fails(self):
""" DELETE is not supported for list all """
web.app.config['READONLY'] = False
# Delete all items
response = self.client.delete('/item/')
self.assertEqual(response.status_code, 405)
# Note: if this fails, all items have gone and rest of
# tests wil fail!
def test_delete_item_id_readonly(self):
web.app.config['READONLY'] = True
# Create a temporary item
item_id = self.lib.add(Item(title='test_delete_item_id_ro',
test_delete_item_id_ro=1))
# Check we can find the temporary item we just created
response = self.client.get('/item/' + str(item_id))
res_json = json.loads(response.data.decode('utf-8'))
self.assertEqual(response.status_code, 200)
self.assertEqual(res_json['id'], item_id)
# Try to delete item by id
response = self.client.delete('/item/' + str(item_id))
self.assertEqual(response.status_code, 405)
# Check the item has not gone
response = self.client.get('/item/' + str(item_id))
res_json = json.loads(response.data.decode('utf-8'))
self.assertEqual(response.status_code, 200)
self.assertEqual(res_json['id'], item_id)
# Remove it
self.lib.get_item(item_id).remove()
def test_delete_item_query_readonly(self):
web.app.config['READONLY'] = True
# Create a temporary item
item_id = self.lib.add(Item(title='test_delete_item_q_ro',
test_delete_item_q_ro=1))
# Check we can find the temporary item we just created
response = self.client.get('/item/query/test_delete_item_q_ro')
res_json = json.loads(response.data.decode('utf-8'))
self.assertEqual(response.status_code, 200)
self.assertEqual(len(res_json['results']), 1)
# Try to delete item by query
response = self.client.delete('/item/query/test_delete_item_q_ro')
self.assertEqual(response.status_code, 405)
# Check the item has not gone
response = self.client.get('/item/query/test_delete_item_q_ro')
res_json = json.loads(response.data.decode('utf-8'))
self.assertEqual(response.status_code, 200)
self.assertEqual(len(res_json['results']), 1)
# Remove it
self.lib.get_item(item_id).remove()
def test_delete_album_id(self):
web.app.config['READONLY'] = False
# Create a temporary album
album_id = self.lib.add(Album(album='test_delete_album_id',
test_delete_album_id=1))
# Check we can find the temporary album we just created
response = self.client.get('/album/' + str(album_id))
res_json = json.loads(response.data.decode('utf-8'))
self.assertEqual(response.status_code, 200)
self.assertEqual(res_json['id'], album_id)
# Delete album by id
response = self.client.delete('/album/' + str(album_id))
res_json = json.loads(response.data.decode('utf-8'))
self.assertEqual(response.status_code, 200)
# Check the album has gone
response = self.client.get('/album/' + str(album_id))
self.assertEqual(response.status_code, 404)
# Note: if this fails, the album may still be around
# and may cause other tests to fail
def test_delete_album_query(self):
web.app.config['READONLY'] = False
# Create a temporary album
self.lib.add(Album(album='test_delete_album_query',
test_delete_album_query=1))
# Check we can find the temporary album we just created
response = self.client.get('/album/query/test_delete_album_query')
res_json = json.loads(response.data.decode('utf-8'))
self.assertEqual(response.status_code, 200)
self.assertEqual(len(res_json['results']), 1)
# Delete album
response = self.client.delete('/album/query/test_delete_album_query')
res_json = json.loads(response.data.decode('utf-8'))
self.assertEqual(response.status_code, 200)
# Check the album has gone
response = self.client.get('/album/query/test_delete_album_query')
res_json = json.loads(response.data.decode('utf-8'))
self.assertEqual(response.status_code, 200)
self.assertEqual(len(res_json['results']), 0)
def test_delete_album_all_fails(self):
""" DELETE is not supported for list all """
web.app.config['READONLY'] = False
# Delete all albums
response = self.client.delete('/album/')
self.assertEqual(response.status_code, 405)
# Note: if this fails, all albums have gone and rest of
# tests wil fail!
def test_delete_album_id_readonly(self):
web.app.config['READONLY'] = True
# Create a temporary album
album_id = self.lib.add(Album(album='test_delete_album_id_ro',
test_delete_album_id_ro=1))
# Check we can find the temporary album we just created
response = self.client.get('/album/' + str(album_id))
res_json = json.loads(response.data.decode('utf-8'))
self.assertEqual(response.status_code, 200)
self.assertEqual(res_json['id'], album_id)
# Try to delete album by id
response = self.client.delete('/album/' + str(album_id))
self.assertEqual(response.status_code, 405)
# Check the item has not gone
response = self.client.get('/album/' + str(album_id))
res_json = json.loads(response.data.decode('utf-8'))
self.assertEqual(response.status_code, 200)
self.assertEqual(res_json['id'], album_id)
# Remove it
self.lib.get_album(album_id).remove()
def test_delete_album_query_readonly(self):
web.app.config['READONLY'] = True
# Create a temporary album
album_id = self.lib.add(Album(album='test_delete_album_query_ro',
test_delete_album_query_ro=1))
# Check we can find the temporary album we just created
response = self.client.get('/album/query/test_delete_album_query_ro')
res_json = json.loads(response.data.decode('utf-8'))
self.assertEqual(response.status_code, 200)
self.assertEqual(len(res_json['results']), 1)
# Try to delete album
response = self.client.delete(
'/album/query/test_delete_album_query_ro'
)
self.assertEqual(response.status_code, 405)
# Check the album has not gone
response = self.client.get('/album/query/test_delete_album_query_ro')
res_json = json.loads(response.data.decode('utf-8'))
self.assertEqual(response.status_code, 200)
self.assertEqual(len(res_json['results']), 1)
# Remove it
self.lib.get_album(album_id).remove()
def test_patch_item_id(self):
# Note: PATCH is currently only implemented for track items, not albums
web.app.config['READONLY'] = False
# Create a temporary item
item_id = self.lib.add(Item(title='test_patch_item_id',
test_patch_f1=1,
test_patch_f2="Old"))
# Check we can find the temporary item we just created
response = self.client.get('/item/' + str(item_id))
res_json = json.loads(response.data.decode('utf-8'))
self.assertEqual(response.status_code, 200)
self.assertEqual(res_json['id'], item_id)
self.assertEqual(
[res_json['test_patch_f1'], res_json['test_patch_f2']],
['1', 'Old'])
# Patch item by id
# patch_json = json.JSONEncoder().encode({"test_patch_f2": "New"}]})
response = self.client.patch('/item/' + str(item_id),
json={"test_patch_f2": "New"})
res_json = json.loads(response.data.decode('utf-8'))
self.assertEqual(response.status_code, 200)
self.assertEqual(res_json['id'], item_id)
self.assertEqual(
[res_json['test_patch_f1'], res_json['test_patch_f2']],
['1', 'New'])
# Check the update has really worked
response = self.client.get('/item/' + str(item_id))
res_json = json.loads(response.data.decode('utf-8'))
self.assertEqual(response.status_code, 200)
self.assertEqual(res_json['id'], item_id)
self.assertEqual(
[res_json['test_patch_f1'], res_json['test_patch_f2']],
['1', 'New'])
# Remove the item
self.lib.get_item(item_id).remove()
def test_patch_item_id_readonly(self):
# Note: PATCH is currently only implemented for track items, not albums
web.app.config['READONLY'] = True
# Create a temporary item
item_id = self.lib.add(Item(title='test_patch_item_id_ro',
test_patch_f1=2,
test_patch_f2="Old"))
# Check we can find the temporary item we just created
response = self.client.get('/item/' + str(item_id))
res_json = json.loads(response.data.decode('utf-8'))
self.assertEqual(response.status_code, 200)
self.assertEqual(res_json['id'], item_id)
self.assertEqual(
[res_json['test_patch_f1'], res_json['test_patch_f2']],
['2', 'Old'])
# Patch item by id
# patch_json = json.JSONEncoder().encode({"test_patch_f2": "New"})
response = self.client.patch('/item/' + str(item_id),
json={"test_patch_f2": "New"})
self.assertEqual(response.status_code, 405)
# Remove the item
self.lib.get_item(item_id).remove()
def test_get_item_file(self):
ipath = os.path.join(self.temp_dir, b'testfile2.mp3')
shutil.copy(os.path.join(_common.RSRC, b'full.mp3'), ipath)
self.assertTrue(os.path.exists(ipath))
item_id = self.lib.add(Item.from_path(ipath))
response = self.client.get('/item/' + str(item_id) + '/file')
self.assertEqual(response.status_code, 200)
def suite():
return unittest.TestLoader().loadTestsFromName(__name__)
if __name__ == '__main__':
unittest.main(defaultTest='suite')