def test_resolve_user_url(app):
    """Tests that it resolves a user url"""
    with app.test_request_context():
        db = get_db()
        with db.scoped_session() as session:
            session.add(
                Block(
                    blockhash=
                    "0x2969e88561fac17ca19c1749cb3e614211ba15c8e471be55de47d0b8ca6acf5f",
                    parenthash="0x0000000000000000000000000000000000000000",
                    number=16914541,
                    is_current=True,
                ))
            session.flush()
            session.add(
                User(
                    blockhash=
                    "0x2969e88561fac17ca19c1749cb3e614211ba15c8e471be55de47d0b8ca6acf5f",
                    is_current=True,
                    updated_at=datetime.now(),
                    created_at=datetime.now(),
                    blocknumber=16914541,
                    handle="Urbanbankai",
                    handle_lc="urbanbankai",
                    user_id=42727,
                    primary_id=1,
                    secondary_ids=[2, 3],
                ))
            url = "https://audius.co/urbanbankai"
            resolved_url = resolve_url(session, url)

            assert resolved_url == "/v1/users/DE677"
示例#2
0
def test_resolve_non_fully_qualified_url(db_mock, app):
    """Tests that it resolves a track url when not fully qualified"""
    with app.test_request_context():
        with db_mock.scoped_session() as session:
            url = '/urbanbankai/mb-shola-vivienne-%22westwood%22-87325'
            resolved_url = resolve_url(session, url)

            assert resolved_url == '/v1/tracks/799Yv'
示例#3
0
def test_resolve_playlist_url(db_mock, app):
    """Tests that it resolves a playlist url"""
    with app.test_request_context():
        with db_mock.scoped_session() as session:
            url = 'https://audius.co/urbanbankai/playlist/up-next-atl-august-2020-9801'
            resolved_url = resolve_url(session, url)

            assert resolved_url == '/v1/playlists/ePkW0'
示例#4
0
def test_resolve_track_url(db_mock, app):
    """Tests that it resolves a track url"""
    with app.test_request_context():
        with db_mock.scoped_session() as session:
            url = 'https://audius.co/urbanbankai/mb-shola-vivienne-%22westwood%22-87325'
            resolved_url = resolve_url(session, url)

            assert resolved_url == '/v1/tracks/799Yv'
def test_resolve_playlist_url(app):
    """Tests that it resolves a playlist url"""
    with app.test_request_context():
        db = get_db()
        with db.scoped_session() as session:
            url = "https://audius.co/urbanbankai/playlist/up-next-atl-august-2020-9801"
            resolved_url = resolve_url(session, url)

            assert resolved_url == "/v1/playlists/ePkW0"
def test_resolve_track_url(app):
    """Tests that it resolves a track url"""
    with app.test_request_context():
        db = get_db()
        with db.scoped_session() as session:
            url = 'https://audius.co/urbanbankai/mb-shola-vivienne-"westwood"-87325'
            resolved_url = resolve_url(session, url)

            assert (
                resolved_url ==
                "/v1/tracks?slug=mb-shola-vivienne-%22westwood%22-87325&handle=urbanbankai"
            )
def test_resolve_non_fully_qualified_url(app):
    """Tests that it resolves a track url when not fully qualified"""
    with app.test_request_context():
        db = get_db()
        with db.scoped_session() as session:
            url = '/urbanbankai/mb-shola-vivienne-"westwood"-87325'
            resolved_url = resolve_url(session, url)

            assert (
                resolved_url ==
                "/v1/tracks?slug=mb-shola-vivienne-%22westwood%22-87325&handle=urbanbankai"
            )
示例#8
0
def test_resolve_user_url(db_mock, app):
    """Tests that it resolves a user url"""
    with app.test_request_context():
        with db_mock.scoped_session() as session:
            User.__table__.create(db_mock._engine)
            session.add(
                User(
                    blockhash=
                    "0x2969e88561fac17ca19c1749cb3e614211ba15c8e471be55de47d0b8ca6acf5f",
                    is_current=True,
                    updated_at=datetime.now(),
                    created_at=datetime.now(),
                    blocknumber=16914541,
                    handle="Urbanbankai",
                    handle_lc="urbanbankai",
                    user_id=42727))
            url = 'https://audius.co/urbanbankai'
            resolved_url = resolve_url(session, url)

            assert resolved_url == '/v1/users/DE677'
示例#9
0
    def get(self):
        """
        Resolves and redirects a provided Audius app URL to the API resource URL it represents.

        This endpoint allows you to lookup and access API resources when you only know the
        audius.co URL.
        Tracks, Playlists, and Users are supported.
        """
        args = resolve_route_parser.parse_args()
        url = args.get("url")
        if not url:
            abort_bad_request_param("url", ns)
        try:
            db = db_session.get_db_read_replica()
            with db.scoped_session() as session:
                resolved_url = resolve_url(session, url)
                if not resolved_url:
                    return abort_not_found(url, ns)

                return redirect(resolved_url, code=302)

        except Exception as e:
            logger.warning(e)
            abort_not_found(url, ns)