conftest.py 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. import json
  2. import pytest
  3. from rest_framework.authtoken.models import Token
  4. from django.contrib.auth import get_user_model
  5. User = get_user_model()
  6. class MopidyRequest:
  7. name = "Same in the End"
  8. artist = "Sublime"
  9. album = "Sublime"
  10. track_number = 4
  11. run_time_ticks = 156604
  12. run_time = "156"
  13. playback_time_ticks = 15045
  14. musicbrainz_track_id = "54214d63-5adf-4909-87cd-c65c37a6d558"
  15. musicbrainz_album_id = "03b864cd-7761-314c-a892-05a89ddff00d"
  16. musicbrainz_artist_id = "95f5b748-d370-47fe-85bd-0af2dc450bc0"
  17. mopidy_uri = "local:track:Sublime%20-%20Sublime/Disc%201%20-%2004%20-%20Same%20in%20the%20End.mp3" # noqa
  18. status = "resumed"
  19. def __init__(self, **kwargs):
  20. self.request_data = {
  21. "name": kwargs.get("name", self.name),
  22. "artist": kwargs.get("artist", self.artist),
  23. "album": kwargs.get("album", self.album),
  24. "track_number": int(kwargs.get("track_number", self.track_number)),
  25. "run_time_ticks": int(
  26. kwargs.get("run_time_ticks", self.run_time_ticks)
  27. ),
  28. "run_time": int(kwargs.get("run_time", self.run_time)),
  29. "playback_time_ticks": int(
  30. kwargs.get("playback_time_ticks", self.playback_time_ticks)
  31. ),
  32. "musicbrainz_track_id": kwargs.get(
  33. "musicbrainz_track_id", self.musicbrainz_track_id
  34. ),
  35. "musicbrainz_album_id": kwargs.get(
  36. "musicbrainz_album_id", self.musicbrainz_album_id
  37. ),
  38. "musicbrainz_artist_id": kwargs.get(
  39. "musicbrainz_artist_id", self.musicbrainz_artist_id
  40. ),
  41. "mopidy_uri": kwargs.get("mopidy_uri", self.mopidy_uri),
  42. "status": kwargs.get("status", self.status),
  43. }
  44. def __eq__(self, other):
  45. for key in self.request_data.keys():
  46. if self.request_data[key] != getattr(self, key):
  47. return False
  48. return True
  49. @property
  50. def request_json(self):
  51. return json.dumps(self.request_data)
  52. @pytest.fixture
  53. def valid_auth_token():
  54. user = User.objects.create(email="test@exmaple.com")
  55. return Token.objects.create(user=user).key
  56. @pytest.fixture
  57. def mopidy_track_request_data():
  58. return MopidyRequest().request_json
  59. @pytest.fixture
  60. def mopidy_track_diff_album_request_data(**kwargs):
  61. mb_album_id = "0c56c457-afe1-4679-baab-759ba8dd2a58"
  62. return MopidyRequest(
  63. album="Gold", musicbrainz_album_id=mb_album_id
  64. ).request_json
  65. @pytest.fixture
  66. def mopidy_podcast_request_data():
  67. mopidy_uri = "local:podcast:Up%20First/2022-01-01%20Up%20First.mp3"
  68. return MopidyRequest(mopidy_uri=mopidy_uri).request_json