"""Track handler tests.""" import json from owsresponse import response from participant.handlers import track # noqa from participant.logic import label_participant as label_participant_logic mock_participant_response = { 'name': 'L.G. Wise', 'vendorId': 8759, 'subaccountId': 0, 'spotifyId': '5xaT2601i5MC4h6yZa7EOD', 'id': 786281, 'appleMusicId': 111000530, } def test_get_label_participant_by_track_id(mocker, test_client): """Test label participant get by related track id success.""" mocker.patch( 'participant.logic.label_participant.get_label_participants_by_related_track_id', # noqa return_value=response.Response(mock_participant_response, status=202), ) handler_response = test_client.get('/tracks/7654/label-participants') result = json.loads(handler_response.data.decode()) label_participant_logic.get_label_participants_by_related_track_id.assert_called_with( # noqa 7654 ) assert handler_response.status_code == 202 assert result == mock_participant_response def test_get_participant_by_track_id_sends_400_on_non_int(mocker, test_client): """Test participant get by related track id fail non int for id in url.""" mocker.patch( 'participant.logic.label_participant.get_label_participants_by_related_track_id', # noqa return_value=response.Response(mock_participant_response, status=202), ) handler_response = test_client.get('/tracks/123notint/label-participants') label_participant_logic.get_label_participants_by_related_track_id.assert_not_called() # noqa assert handler_response.status_code == 400