7
7
import pytest
8
8
9
9
from ndtoolbox .app import DuplicateProcessor
10
+ from ndtoolbox .config import config
10
11
from ndtoolbox .model import Album , Annotation , Artist , MediaFile
11
- from ndtoolbox .utils import ToolboxConfig
12
12
13
- ND_DATABASE_PATH = "test/data/navidrome.db"
14
- ND_DATA_FILE = "data/nd-toolbox-data.json"
15
- ND_DATA_FILE = "test/data/nd-toolbox-data.json"
16
- DATA_DIR = "test/data"
17
- BEETS_BASE_PATH = "/app/music"
18
- ND_BASE_PATH = "/music/library"
13
+ config .set_file ("test/config/config.yaml" )
19
14
20
15
FILES = [
21
16
MediaFile (
31
26
album_id = None ,
32
27
album_name = None ,
33
28
mbz_recording_id = "recording-1" ,
29
+ beets_path = "/music/path/library/to/file1.mp3" ,
34
30
),
35
31
MediaFile (
36
32
id = "22" ,
45
41
album_id = None ,
46
42
album_name = None ,
47
43
mbz_recording_id = "recording-2" ,
44
+ beets_path = "/music/path/library/to/file2 2.mp3" ,
48
45
),
49
46
MediaFile (
50
47
id = "33" ,
59
56
album_id = None ,
60
57
album_name = None ,
61
58
mbz_recording_id = "recording-3" ,
59
+ beets_path = "/music/path/library/to/file3.mp3" ,
62
60
),
63
61
MediaFile (
64
62
id = "44" ,
73
71
album_id = None ,
74
72
album_name = None ,
75
73
mbz_recording_id = "recording-3" ,
74
+ beets_path = "/music/path/library/to/file4.mp3" ,
76
75
),
77
76
]
78
77
# Set annotations for each file
91
90
@pytest .fixture (scope = "session" )
92
91
def processor ():
93
92
"""Fixture to create a DuplicateProcessor instance."""
94
- config = ToolboxConfig (False )
95
- config .navidrome_db_path = ND_DATABASE_PATH
96
- config .data_folder = DATA_DIR
97
- config .source_base = BEETS_BASE_PATH
98
- config .target_base = ND_BASE_PATH
99
- processor = DuplicateProcessor (config )
93
+ processor = DuplicateProcessor ()
100
94
yield processor
101
95
102
96
103
97
def test_encode_decode_json_pickle (processor : DuplicateProcessor ):
104
98
"""Test encoding and decoding of JSON using jsonpickle."""
105
99
file_path = "test/data/test-data.json"
106
- data = {"dups_media_files " : FILES , "stats" : "bbb" , "errors" : []}
100
+ data = {"duplicates " : FILES , "stats" : "bbb" , "errors" : []}
107
101
with open (file_path , "w" , encoding = "utf-8" ) as file :
108
102
file .write (jsonpickle .encode (data , indent = 4 , keys = True ))
109
103
@@ -124,6 +118,7 @@ def test_merge_annotation_data(processor: DuplicateProcessor):
124
118
album_id = None ,
125
119
album_name = None ,
126
120
mbz_recording_id = "recording-1" ,
121
+ beets_path = "/music/path/library/to/file1.mp3" ,
127
122
)
128
123
a .annotation = Annotation (
129
124
item_id = "1" ,
@@ -148,6 +143,7 @@ def test_merge_annotation_data(processor: DuplicateProcessor):
148
143
album_id = None ,
149
144
album_name = None ,
150
145
mbz_recording_id = "recording-2" ,
146
+ beets_path = "/music/path/library/to/file1.mp3" ,
151
147
)
152
148
b .annotation = Annotation (
153
149
item_id = "2" ,
@@ -172,6 +168,7 @@ def test_merge_annotation_data(processor: DuplicateProcessor):
172
168
album_id = None ,
173
169
album_name = None ,
174
170
mbz_recording_id = "recording-2" ,
171
+ beets_path = "/music/path/library/to/file3.mp3" ,
175
172
)
176
173
c .annotation = Annotation (
177
174
item_id = "3" ,
@@ -280,6 +277,7 @@ def test_get_keepable_media(processor: DuplicateProcessor):
280
277
album_id = 0 ,
281
278
album_name = None ,
282
279
mbz_recording_id = None ,
280
+ beets_path = "/music/path/library/to/file1.mp3" ,
283
281
),
284
282
MediaFile (
285
283
id = "12" ,
@@ -294,6 +292,7 @@ def test_get_keepable_media(processor: DuplicateProcessor):
294
292
album_id = 0 ,
295
293
album_name = None ,
296
294
mbz_recording_id = None ,
295
+ beets_path = "/music/path/library/to/file1.mp3" ,
297
296
),
298
297
MediaFile (
299
298
id = "13" ,
@@ -308,6 +307,7 @@ def test_get_keepable_media(processor: DuplicateProcessor):
308
307
album_id = 0 ,
309
308
album_name = None ,
310
309
mbz_recording_id = None ,
310
+ beets_path = "/music/path/library/to/file3.mp3" ,
311
311
),
312
312
MediaFile (
313
313
id = "14" ,
@@ -322,6 +322,7 @@ def test_get_keepable_media(processor: DuplicateProcessor):
322
322
album_id = 0 ,
323
323
album_name = None ,
324
324
mbz_recording_id = None ,
325
+ beets_path = "/music/path/library/to/file4.mp3" ,
325
326
),
326
327
MediaFile (
327
328
id = "15" ,
@@ -336,6 +337,7 @@ def test_get_keepable_media(processor: DuplicateProcessor):
336
337
album_id = 0 ,
337
338
album_name = None ,
338
339
mbz_recording_id = None ,
340
+ beets_path = "/music/path/library/to/file4.mp3" ,
339
341
),
340
342
MediaFile (
341
343
id = "16" ,
@@ -350,6 +352,7 @@ def test_get_keepable_media(processor: DuplicateProcessor):
350
352
album_id = 0 ,
351
353
album_name = None ,
352
354
mbz_recording_id = "musicBrainzID" ,
355
+ beets_path = "/music/path/library/to/file4.mp3" ,
353
356
),
354
357
MediaFile (
355
358
id = "17" ,
@@ -364,6 +367,7 @@ def test_get_keepable_media(processor: DuplicateProcessor):
364
367
album_id = 0 ,
365
368
album_name = None ,
366
369
mbz_recording_id = "musicBrainzID" ,
370
+ beets_path = "/music/path/library/to/file4.mp3" ,
367
371
),
368
372
# That's a keeper:
369
373
MediaFile (
@@ -379,6 +383,7 @@ def test_get_keepable_media(processor: DuplicateProcessor):
379
383
album_id = 0 ,
380
384
album_name = None ,
381
385
mbz_recording_id = "musicBrainzID" ,
386
+ beets_path = "/music/path/library/to/file4.mp3" ,
382
387
),
383
388
]
384
389
@@ -397,6 +402,7 @@ def test_get_keepable_media(processor: DuplicateProcessor):
397
402
album_id = 0 ,
398
403
album_name = None ,
399
404
mbz_recording_id = "musicBrainzID" ,
405
+ beets_path = "/music/path/library/to/file4.mp3" ,
400
406
),
401
407
MediaFile (
402
408
id = "2000" ,
@@ -411,6 +417,7 @@ def test_get_keepable_media(processor: DuplicateProcessor):
411
417
album_id = 0 ,
412
418
album_name = None ,
413
419
mbz_recording_id = None ,
420
+ beets_path = "/music/path/library/to/file4.mp3" ,
414
421
),
415
422
]
416
423
@@ -429,6 +436,7 @@ def test_get_keepable_media(processor: DuplicateProcessor):
429
436
album_id = 0 ,
430
437
album_name = None ,
431
438
mbz_recording_id = None ,
439
+ beets_path = "/music/path/library/to/file4.mp3" ,
432
440
),
433
441
MediaFile (
434
442
id = "artist_keeper_id" ,
@@ -443,6 +451,7 @@ def test_get_keepable_media(processor: DuplicateProcessor):
443
451
album_id = 0 ,
444
452
album_name = None ,
445
453
mbz_recording_id = None ,
454
+ beets_path = "/music/path/library/to/file4.mp3" ,
446
455
),
447
456
]
448
457
@@ -459,15 +468,17 @@ def test_get_keepable_media(processor: DuplicateProcessor):
459
468
keeper = processor ._get_keepable_media (dups2 )
460
469
assert keeper .id == dups2 [0 ].id
461
470
assert keeper .album is not None
462
- assert keeper .album .has_keepable is True
471
+ assert keeper .folder is not None
472
+ assert keeper .folder .has_keepable is True
463
473
assert keeper .title == "The Song"
464
474
assert keeper .bitrate == 1024
465
475
466
476
# Now, eval the first list
467
477
keeper = processor ._get_keepable_media (dups )
468
478
assert keeper .id == dups [7 ].id
469
479
assert keeper .album is not None
470
- assert keeper .album .has_keepable is True
480
+ assert keeper .folder is not None
481
+ assert keeper .folder .has_keepable is True
471
482
assert keeper .title == "File 8"
472
483
assert keeper .bitrate == 320
473
484
0 commit comments