@@ -468,3 +468,68 @@ def test_successful_translation(self, web_track_mock):
468
468
assert track .track_no == 7
469
469
assert track .disc_no == 1
470
470
assert track .length == 174300
471
+
472
+ def test_sets_bitrate (self , web_track_mock ):
473
+ track = translator .web_to_track (web_track_mock , bitrate = 100 )
474
+
475
+ assert track .bitrate == 100
476
+
477
+ def test_sets_specified_album (self , web_track_mock ):
478
+ alt_album = models .Album (uri = "spotify:album:xyz" , name = "XYZ 789" )
479
+
480
+ track = translator .web_to_track (web_track_mock , album = alt_album )
481
+
482
+ assert track .album .uri == "spotify:album:xyz"
483
+ assert track .album .name == "XYZ 789"
484
+
485
+ def test_filters_out_none_artists (self , web_track_mock ):
486
+ web_track_mock ["artists" ].insert (0 , {})
487
+ web_track_mock ["artists" ].insert (0 , {"foo" : "bar" })
488
+
489
+ track = translator .web_to_track (web_track_mock )
490
+ artists = [models .Artist (uri = "spotify:artist:abba" , name = "ABBA" )]
491
+
492
+ assert list (track .artists ) == artists
493
+
494
+ def test_ignores_missing_album (self , web_track_mock ):
495
+ del web_track_mock ["album" ]
496
+
497
+ track = translator .web_to_track (web_track_mock )
498
+
499
+ assert track .name == "ABC 123"
500
+ assert track .length == 174300
501
+ assert track .album is None
502
+
503
+ def test_ignores_invalid_album (self , web_track_mock ):
504
+ web_track_mock ["album" ]["uri" ] = None
505
+
506
+ track = translator .web_to_track (web_track_mock )
507
+
508
+ assert track .name == "ABC 123"
509
+ assert track .album is None
510
+
511
+ @pytest .mark .parametrize (
512
+ "data" ,
513
+ [
514
+ (123 ),
515
+ (123.0 ),
516
+ ("123" ),
517
+ ("123.0" ),
518
+ ],
519
+ )
520
+ def test_int_or_none_number (self , data ):
521
+ assert translator .int_or_none (data ) == 123
522
+
523
+ def test_int_or_none_none (self ):
524
+ assert translator .int_or_none (None ) is None
525
+
526
+ def test_ints_might_be_floats (self , web_track_mock ):
527
+ web_track_mock ["duration_ms" ] = 123.0
528
+ web_track_mock ["disc_number" ] = "456.0"
529
+ web_track_mock ["track_number" ] = 99.9
530
+
531
+ track = translator .web_to_track (web_track_mock )
532
+
533
+ assert track .length == 123
534
+ assert track .disc_no == 456
535
+ assert track .track_no == 99
0 commit comments