예제 #1
0
    def should_raise_exception_on_connection_error(self):
        self.requests.get.side_effect = requests.ConnectionError()

        with pytest.raises(EchoNestError) as e:
            get_track_analysis('foo')

        assert e.value.message == 'Error connecting to the Echonest API'
예제 #2
0
    def should_raise_exception_no_summary(self):
        self.requests.get.return_value = mock.MagicMock(
            status_code=httplib.OK, json=mock.MagicMock(return_value={}))

        with pytest.raises(EchoNestError) as e:
            get_track_analysis('foo')

        assert e.value.message == 'Response payload does not contain response element'
예제 #3
0
    def should_raise_exception_not_200_response(self):
        self.requests.get.return_value = mock.MagicMock(
            status_code=httplib.NOT_FOUND)

        with pytest.raises(EchoNestError) as e:
            get_track_analysis('foo')

        assert e.value.message == 'Echonest API response code was 404 not 200'
예제 #4
0
    def should_raise_exception_on_json_decode_error(self):
        self.requests.get.return_value = mock.MagicMock(
            status_code=httplib.OK,
            json=mock.MagicMock(side_effect=JSONDecodeError('foo', 'bar', 0)))

        with pytest.raises(EchoNestError) as e:
            get_track_analysis('foo')

        assert e.value.message == 'Unable to decode response data to dict'
예제 #5
0
파일: track.py 프로젝트: thisissoon/FM-API
def update_analysis(pk):
    """ Task for updating an existing tracks analysis asynchronously from
    Echo Nest.

    pk : str
        The UUID Primary Key of the Track
    """

    track = Track.query.get(pk)
    if track is None:
        # TODO: Log This
        return False

    # Call Echo Nest
    try:
        analysis = get_track_analysis(track.spotify_uri)
    except EchoNestError:
        # TODO: Log This
        return False

    # commit analysis data to Track model
    track.audio_summary = analysis

    db.session.add(track)
    db.session.commit()

    return True
예제 #6
0
    def should_return_audio_summary(self):
        analysis = get_track_analysis('foo')

        assert type(analysis) == dict
        assert analysis['danceability'] == 0.5164314670162907