Skip to content

Commit

Permalink
Fix mapping test
Browse files Browse the repository at this point in the history
  • Loading branch information
mayhem committed Apr 11, 2022
1 parent 47dfe74 commit dc1b7f9
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
1 change: 1 addition & 0 deletions troi/musicbrainz/mbid_mapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ def read(self, inputs):
r.add_note("recording mbid %s overwritten by mbid_lookup" % (r.mbid))
r.mbid = row['recording_mbid']
r.name = row['recording_name']
r.year = row['year']

if r.artist.artist_credit_id:
r.artist.add_note("artist_credit_id %d overwritten by mbid_lookup" % (r.artist.artist_credit_id))
Expand Down
27 changes: 21 additions & 6 deletions troi/musicbrainz/tests/test_mbid_mapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,33 @@
"recording_mbid": "97e69767-5d34-4c97-b36a-f3b2b1ef9dae",
"recording_name": "Trigger Hippie",
"release_mbid": "9db51cd6-38f6-3b42-8ad5-559963d68f35",
"release_name": "Who Can You Trust?"
"release_name": "Who Can You Trust?",
"year": 1996
}
]


def mocked_requests_post(*args, **kwargs):
class MockResponse:
def __init__(self, json_data, status_code):
self.json_data = json_data
self.status_code = status_code

def json(self):
return self.json_data

e = troi.musicbrainz.mbid_mapping.MBIDMappingLookupElement()
if args[0] == e.SERVER_URL:
return MockResponse(return_data, 200)

return MockResponse(None, 404)


class TestMBIDMapping(unittest.TestCase):

@unittest.mock.patch('requests.post')
@unittest.mock.patch('requests.post', side_effect=mocked_requests_post)
def test_read(self, req):

mock = unittest.mock.MagicMock()
mock.status_code = 200
mock.text = json.dumps(return_data)
req.return_value = mock
e = troi.musicbrainz.mbid_mapping.MBIDMappingLookupElement()

r = [ troi.Recording("trigger hippie", artist=troi.Artist("morcheeba")) ]
Expand All @@ -41,6 +55,7 @@ def test_read(self, req):
assert entities[0].release.name == "Who Can You Trust?"
assert entities[0].mbid == "97e69767-5d34-4c97-b36a-f3b2b1ef9dae"
assert entities[0].name == "Trigger Hippie"
assert entities[0].year == 1996


@unittest.mock.patch('requests.post')
Expand Down

0 comments on commit dc1b7f9

Please sign in to comment.