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
|
# This file is part of beets.
# Copyright 2016, Adrian Sampson.
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
"""Tests for the 'beatport' plugin."""
import unittest
from datetime import timedelta
from beets.test import _common
from beets.test.helper import BeetsTestCase
from beetsplug import beatport
class BeatportTest(BeetsTestCase):
def _make_release_response(self):
"""Returns a dict that mimics a response from the beatport API.
The results were retrieved from:
https://oauth-api.beatport.com/catalog/3/releases?id=1742984
The list of elements on the returned dict is incomplete, including just
those required for the tests on this class.
"""
results = {
"id": 1742984,
"type": "release",
"name": "Charade",
"slug": "charade",
"releaseDate": "2016-04-11",
"publishDate": "2016-04-11",
"audioFormat": "",
"category": "Release",
"currentStatus": "General Content",
"catalogNumber": "GR089",
"description": "",
"label": {
"id": 24539,
"name": "Gravitas Recordings",
"type": "label",
"slug": "gravitas-recordings",
},
"artists": [
{
"id": 326158,
"name": "Supersillyus",
"slug": "supersillyus",
"type": "artist",
}
],
"genres": [
{"id": 9, "name": "Breaks", "slug": "breaks", "type": "genre"}
],
}
return results
def _make_tracks_response(self):
"""Return a list that mimics a response from the beatport API.
The results were retrieved from:
https://oauth-api.beatport.com/catalog/3/tracks?releaseId=1742984
The list of elements on the returned list is incomplete, including just
those required for the tests on this class.
"""
results = [
{
"id": 7817567,
"type": "track",
"sku": "track-7817567",
"name": "Mirage a Trois",
"trackNumber": 1,
"mixName": "Original Mix",
"title": "Mirage a Trois (Original Mix)",
"slug": "mirage-a-trois-original-mix",
"releaseDate": "2016-04-11",
"publishDate": "2016-04-11",
"currentStatus": "General Content",
"length": "7:05",
"lengthMs": 425421,
"bpm": 90,
"key": {
"standard": {
"letter": "G",
"sharp": False,
"flat": False,
"chord": "minor",
},
"shortName": "Gmin",
},
"artists": [
{
"id": 326158,
"name": "Supersillyus",
"slug": "supersillyus",
"type": "artist",
}
],
"genres": [
{
"id": 9,
"name": "Breaks",
"slug": "breaks",
"type": "genre",
}
],
"subGenres": [
{
"id": 209,
"name": "Glitch Hop",
"slug": "glitch-hop",
"type": "subgenre",
}
],
"release": {
"id": 1742984,
"name": "Charade",
"type": "release",
"slug": "charade",
},
"label": {
"id": 24539,
"name": "Gravitas Recordings",
"type": "label",
"slug": "gravitas-recordings",
"status": True,
},
},
{
"id": 7817568,
"type": "track",
"sku": "track-7817568",
"name": "Aeon Bahamut",
"trackNumber": 2,
"mixName": "Original Mix",
"title": "Aeon Bahamut (Original Mix)",
"slug": "aeon-bahamut-original-mix",
"releaseDate": "2016-04-11",
"publishDate": "2016-04-11",
"currentStatus": "General Content",
"length": "7:38",
"lengthMs": 458000,
"bpm": 100,
"key": {
"standard": {
"letter": "G",
"sharp": False,
"flat": False,
"chord": "major",
},
"shortName": "Gmaj",
},
"artists": [
{
"id": 326158,
"name": "Supersillyus",
"slug": "supersillyus",
"type": "artist",
}
],
"genres": [
{
"id": 9,
"name": "Breaks",
"slug": "breaks",
"type": "genre",
}
],
"subGenres": [
{
"id": 209,
"name": "Glitch Hop",
"slug": "glitch-hop",
"type": "subgenre",
}
],
"release": {
"id": 1742984,
"name": "Charade",
"type": "release",
"slug": "charade",
},
"label": {
"id": 24539,
"name": "Gravitas Recordings",
"type": "label",
"slug": "gravitas-recordings",
"status": True,
},
},
{
"id": 7817569,
"type": "track",
"sku": "track-7817569",
"name": "Trancendental Medication",
"trackNumber": 3,
"mixName": "Original Mix",
"title": "Trancendental Medication (Original Mix)",
"slug": "trancendental-medication-original-mix",
"releaseDate": "2016-04-11",
"publishDate": "2016-04-11",
"currentStatus": "General Content",
"length": "1:08",
"lengthMs": 68571,
"bpm": 141,
"key": {
"standard": {
"letter": "F",
"sharp": False,
"flat": False,
"chord": "major",
},
"shortName": "Fmaj",
},
"artists": [
{
"id": 326158,
"name": "Supersillyus",
"slug": "supersillyus",
"type": "artist",
}
],
"genres": [
{
"id": 9,
"name": "Breaks",
"slug": "breaks",
"type": "genre",
}
],
"subGenres": [
{
"id": 209,
"name": "Glitch Hop",
"slug": "glitch-hop",
"type": "subgenre",
}
],
"release": {
"id": 1742984,
"name": "Charade",
"type": "release",
"slug": "charade",
},
"label": {
"id": 24539,
"name": "Gravitas Recordings",
"type": "label",
"slug": "gravitas-recordings",
"status": True,
},
},
{
"id": 7817570,
"type": "track",
"sku": "track-7817570",
"name": "A List of Instructions for When I'm Human",
"trackNumber": 4,
"mixName": "Original Mix",
"title": "A List of Instructions for When I'm Human (Original Mix)",
"slug": "a-list-of-instructions-for-when-im-human-original-mix",
"releaseDate": "2016-04-11",
"publishDate": "2016-04-11",
"currentStatus": "General Content",
"length": "6:57",
"lengthMs": 417913,
"bpm": 88,
"key": {
"standard": {
"letter": "A",
"sharp": False,
"flat": False,
"chord": "minor",
},
"shortName": "Amin",
},
"artists": [
{
"id": 326158,
"name": "Supersillyus",
"slug": "supersillyus",
"type": "artist",
}
],
"genres": [
{
"id": 9,
"name": "Breaks",
"slug": "breaks",
"type": "genre",
}
],
"subGenres": [
{
"id": 209,
"name": "Glitch Hop",
"slug": "glitch-hop",
"type": "subgenre",
}
],
"release": {
"id": 1742984,
"name": "Charade",
"type": "release",
"slug": "charade",
},
"label": {
"id": 24539,
"name": "Gravitas Recordings",
"type": "label",
"slug": "gravitas-recordings",
"status": True,
},
},
{
"id": 7817571,
"type": "track",
"sku": "track-7817571",
"name": "The Great Shenanigan",
"trackNumber": 5,
"mixName": "Original Mix",
"title": "The Great Shenanigan (Original Mix)",
"slug": "the-great-shenanigan-original-mix",
"releaseDate": "2016-04-11",
"publishDate": "2016-04-11",
"currentStatus": "General Content",
"length": "9:49",
"lengthMs": 589875,
"bpm": 123,
"key": {
"standard": {
"letter": "E",
"sharp": False,
"flat": True,
"chord": "major",
},
"shortName": "E♭maj",
},
"artists": [
{
"id": 326158,
"name": "Supersillyus",
"slug": "supersillyus",
"type": "artist",
}
],
"genres": [
{
"id": 9,
"name": "Breaks",
"slug": "breaks",
"type": "genre",
}
],
"subGenres": [
{
"id": 209,
"name": "Glitch Hop",
"slug": "glitch-hop",
"type": "subgenre",
}
],
"release": {
"id": 1742984,
"name": "Charade",
"type": "release",
"slug": "charade",
},
"label": {
"id": 24539,
"name": "Gravitas Recordings",
"type": "label",
"slug": "gravitas-recordings",
"status": True,
},
},
{
"id": 7817572,
"type": "track",
"sku": "track-7817572",
"name": "Charade",
"trackNumber": 6,
"mixName": "Original Mix",
"title": "Charade (Original Mix)",
"slug": "charade-original-mix",
"releaseDate": "2016-04-11",
"publishDate": "2016-04-11",
"currentStatus": "General Content",
"length": "7:05",
"lengthMs": 425423,
"bpm": 123,
"key": {
"standard": {
"letter": "A",
"sharp": False,
"flat": False,
"chord": "major",
},
"shortName": "Amaj",
},
"artists": [
{
"id": 326158,
"name": "Supersillyus",
"slug": "supersillyus",
"type": "artist",
}
],
"genres": [
{
"id": 9,
"name": "Breaks",
"slug": "breaks",
"type": "genre",
}
],
"subGenres": [
{
"id": 209,
"name": "Glitch Hop",
"slug": "glitch-hop",
"type": "subgenre",
}
],
"release": {
"id": 1742984,
"name": "Charade",
"type": "release",
"slug": "charade",
},
"label": {
"id": 24539,
"name": "Gravitas Recordings",
"type": "label",
"slug": "gravitas-recordings",
"status": True,
},
},
]
return results
def setUp(self):
super().setUp()
# Set up 'album'.
response_release = self._make_release_response()
self.album = beatport.BeatportRelease(response_release)
# Set up 'tracks'.
response_tracks = self._make_tracks_response()
self.tracks = [beatport.BeatportTrack(t) for t in response_tracks]
# Set up 'test_album'.
self.test_album = self.mk_test_album()
# Set up 'test_tracks'
self.test_tracks = self.test_album.items()
def mk_test_album(self):
items = [_common.item() for _ in range(6)]
for item in items:
item.album = "Charade"
item.catalognum = "GR089"
item.label = "Gravitas Recordings"
item.artist = "Supersillyus"
item.year = 2016
item.comp = False
item.label_name = "Gravitas Recordings"
item.genre = "Glitch Hop"
item.year = 2016
item.month = 4
item.day = 11
item.mix_name = "Original Mix"
items[0].title = "Mirage a Trois"
items[1].title = "Aeon Bahamut"
items[2].title = "Trancendental Medication"
items[3].title = "A List of Instructions for When I'm Human"
items[4].title = "The Great Shenanigan"
items[5].title = "Charade"
items[0].length = timedelta(minutes=7, seconds=5).total_seconds()
items[1].length = timedelta(minutes=7, seconds=38).total_seconds()
items[2].length = timedelta(minutes=1, seconds=8).total_seconds()
items[3].length = timedelta(minutes=6, seconds=57).total_seconds()
items[4].length = timedelta(minutes=9, seconds=49).total_seconds()
items[5].length = timedelta(minutes=7, seconds=5).total_seconds()
items[0].url = "mirage-a-trois-original-mix"
items[1].url = "aeon-bahamut-original-mix"
items[2].url = "trancendental-medication-original-mix"
items[3].url = "a-list-of-instructions-for-when-im-human-original-mix"
items[4].url = "the-great-shenanigan-original-mix"
items[5].url = "charade-original-mix"
counter = 0
for item in items:
counter += 1
item.track_number = counter
items[0].bpm = 90
items[1].bpm = 100
items[2].bpm = 141
items[3].bpm = 88
items[4].bpm = 123
items[5].bpm = 123
items[0].initial_key = "Gmin"
items[1].initial_key = "Gmaj"
items[2].initial_key = "Fmaj"
items[3].initial_key = "Amin"
items[4].initial_key = "E♭maj"
items[5].initial_key = "Amaj"
for item in items:
self.lib.add(item)
album = self.lib.add_album(items)
album.store()
return album
# Test BeatportRelease.
def test_album_name_applied(self):
assert self.album.name == self.test_album["album"]
def test_catalog_number_applied(self):
assert self.album.catalog_number == self.test_album["catalognum"]
def test_label_applied(self):
assert self.album.label_name == self.test_album["label"]
def test_category_applied(self):
assert self.album.category == "Release"
def test_album_url_applied(self):
assert self.album.url == "https://beatport.com/release/charade/1742984"
# Test BeatportTrack.
def test_title_applied(self):
for track, test_track in zip(self.tracks, self.test_tracks):
assert track.name == test_track.title
def test_mix_name_applied(self):
for track, test_track in zip(self.tracks, self.test_tracks):
assert track.mix_name == test_track.mix_name
def test_length_applied(self):
for track, test_track in zip(self.tracks, self.test_tracks):
assert int(track.length.total_seconds()) == int(test_track.length)
def test_track_url_applied(self):
# Specify beatport ids here because an 'item.id' is beets-internal.
ids = [
7817567,
7817568,
7817569,
7817570,
7817571,
7817572,
]
# Concatenate with 'id' to pass strict equality test.
for track, test_track, id in zip(self.tracks, self.test_tracks, ids):
assert (
track.url == f"https://beatport.com/track/{test_track.url}/{id}"
)
def test_bpm_applied(self):
for track, test_track in zip(self.tracks, self.test_tracks):
assert track.bpm == test_track.bpm
def test_initial_key_applied(self):
for track, test_track in zip(self.tracks, self.test_tracks):
assert track.initial_key == test_track.initial_key
def test_genre_applied(self):
for track, test_track in zip(self.tracks, self.test_tracks):
assert track.genre == test_track.genre
class BeatportResponseEmptyTest(unittest.TestCase):
def _make_tracks_response(self):
results = [
{
"id": 7817567,
"name": "Mirage a Trois",
"genres": [
{
"id": 9,
"name": "Breaks",
"slug": "breaks",
"type": "genre",
}
],
"subGenres": [
{
"id": 209,
"name": "Glitch Hop",
"slug": "glitch-hop",
"type": "subgenre",
}
],
}
]
return results
def setUp(self):
super().setUp()
# Set up 'tracks'.
self.response_tracks = self._make_tracks_response()
self.tracks = [beatport.BeatportTrack(t) for t in self.response_tracks]
# Make alias to be congruent with class `BeatportTest`.
self.test_tracks = self.response_tracks
def test_response_tracks_empty(self):
response_tracks = []
tracks = [beatport.BeatportTrack(t) for t in response_tracks]
assert tracks == []
def test_sub_genre_empty_fallback(self):
"""No 'sub_genre' is provided. Test if fallback to 'genre' works."""
self.response_tracks[0]["subGenres"] = []
tracks = [beatport.BeatportTrack(t) for t in self.response_tracks]
self.test_tracks[0]["subGenres"] = []
assert tracks[0].genre == self.test_tracks[0]["genres"][0]["name"]
def test_genre_empty(self):
"""No 'genre' is provided. Test if 'sub_genre' is applied."""
self.response_tracks[0]["genres"] = []
tracks = [beatport.BeatportTrack(t) for t in self.response_tracks]
self.test_tracks[0]["genres"] = []
assert tracks[0].genre == self.test_tracks[0]["subGenres"][0]["name"]
|