Пример #1
0
def test_remove(HttpMock):
    client = init_client()
    test_member_id = get_random_md5()
    test_playlist_id = get_random_md5()
    test_playlist_name = 'test playlist'
    test_track_id = get_random_md5()

    return_values = [
        (200, """<?xml version="1.0" encoding="utf-8"?>
                 <ResponsePlaylists>
                    <playlists>
                        <playlist id="%(test_playlist_id)s" name="%(test_playlist_name)s">
                            <tracks>
                                <track tracknumber="001" time="02:50" lengthseconds="170" comment="Make sure you’re
                                down the front for this fiery Post Punk workout."
                                composer="&quot;S. Milton, J. Wygens&quot;" publisher="HM"
                                name="Guerilla Pop" id="%(test_track_id)s" keywords=""
                                lyrics="" displaytitle="Guerilla Pop" genre="Pop / Rock" tempo=""
                                instrumentation="" bpm="" mixout="" frequency="44100" bitrate="1411" />
                            </tracks>
                        </playlist>
                    </playlists>
                </ResponsePlaylists>""" % locals()),
        (200, """<?xml version="1.0" encoding="utf-8"?>
                 <responsecode xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
                    <code>OK</code>
                 </responsecode>""",),
    ]

    http = build_http_mock(HttpMock, responses=return_values)
    member = Member(_client=client)
    member.id = test_member_id
    playlists = member.get_playlists()
    playlists[0].remove()
Пример #2
0
def test_send_password(HttpMock):
    client = init_client()
    test_username = '******'

    content = """<?xml version="1.0" encoding="utf-8"?>
        <responsecode xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
            <code>OK</code>
        </responsecode>"""

    http = build_http_mock(HttpMock, content=content)
    Member.send_password(test_username, client)
Пример #3
0
def test_send_password(HttpMock):
    client = init_client()
    test_username = '******'

    content = """<?xml version="1.0" encoding="utf-8"?>
        <responsecode xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
            <code>OK</code>
        </responsecode>"""

    http = build_http_mock(HttpMock, content=content)
    Member.send_password(test_username, client)
Пример #4
0
def test_from_xml():
    client = init_client()
    test_member_id = get_random_md5()
    username = '******'
    firstname = 'Test'
    lastname = 'User'
    email = '*****@*****.**'

    xml_str = """<memberaccount id="%(test_member_id)s">
                    <username>%(username)s</username>
                    <firstname>%(firstname)s</firstname>
                    <lastname>%(lastname)s</lastname>
                    <email>%(email)s</email>
                </memberaccount>""" % \
                    {'test_member_id': test_member_id,
                     'username': username,
                     'firstname': firstname,
                     'lastname': lastname,
                     'email': email}

    member_xml = ET.fromstring(xml_str)
    member = Member._from_xml(member_xml, client)

    assert member.id == test_member_id
    assert member.firstname == firstname
Пример #5
0
def test_register_no_client(HttpMock):
    client = init_client()
    test_member_id = get_random_md5()
    username = '******'
    first_name = 'Test'
    last_name = 'User'
    email = '*****@*****.**'

    xml_response = """<?xml version="1.0" encoding="utf-8"?>
     <ResponseMember>
        <memberaccount id="%(test_member_id)s">
            <username>%(username)s</username>
            <first_name>%(first_name)s</first_name>
            <last_name>%(last_name)s</last_name>
            <email>%(email)s</email>
        </memberaccount>
    </ResponseMember>""" % {'test_member_id': test_member_id,
                            'username': username,
                            'first_name': first_name,
                            'last_name': last_name,
                            'email': email}

    username = username
    first_name = first_name
    last_name = last_name
    email = email
    termsaccept = 'true'
    fileformat = 'MP3'

    http = build_http_mock(HttpMock, content=xml_response)
    member = Member.register(username=username, first_name=first_name,
                             last_name=last_name, email=email, termsaccept=termsaccept,
                             fileformat=fileformat)
Пример #6
0
def test_from_xml():
    client = init_client()
    test_member_id = get_random_md5()
    username = '******'
    firstname = 'Test'
    lastname = 'User'
    email = '*****@*****.**'

    xml_str = """<memberaccount id="%(test_member_id)s">
                    <username>%(username)s</username>
                    <firstname>%(firstname)s</firstname>
                    <lastname>%(lastname)s</lastname>
                    <email>%(email)s</email>
                </memberaccount>""" % \
                    {'test_member_id': test_member_id,
                     'username': username,
                     'firstname': firstname,
                     'lastname': lastname,
                     'email': email}

    member_xml = ET.fromstring(xml_str)
    member = Member._from_xml(member_xml, client)

    assert member.id == test_member_id
    assert member.firstname == firstname
Пример #7
0
def test_remove_track(HttpMock):
    client = init_client()
    test_member_id = get_random_md5()
    username = '******'
    firstname = 'Test'
    lastname = 'User'
    email = '*****@*****.**'

    xml_str = """<memberaccount id="%(test_member_id)s">
                    <username>%(username)s</username>
                    <firstname>%(firstname)s</firstname>
                    <lastname>%(lastname)s</lastname>
                    <email>%(email)s</email>
                </memberaccount>""" % \
                    {'test_member_id': test_member_id,
                     'username': username,
                     'firstname': firstname,
                     'lastname': lastname,
                     'email': email}

    member_xml = ET.fromstring(xml_str)
    member = Member._from_xml(member_xml, client)

    xml_response = """<?xml version="1.0" encoding="utf-8"?>
        <responsecode xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
            <code>OK</code>
        </responsecode>"""

    http = build_http_mock(HttpMock, content=xml_response)
    test_track_id = get_random_md5()
    member.remove_favourite(test_track_id)
Пример #8
0
def test_remove_track(HttpMock):
    client = init_client()
    test_member_id = get_random_md5()
    username = '******'
    firstname = 'Test'
    lastname = 'User'
    email = '*****@*****.**'

    xml_str = """<memberaccount id="%(test_member_id)s">
                    <username>%(username)s</username>
                    <firstname>%(firstname)s</firstname>
                    <lastname>%(lastname)s</lastname>
                    <email>%(email)s</email>
                </memberaccount>""" % \
                    {'test_member_id': test_member_id,
                     'username': username,
                     'firstname': firstname,
                     'lastname': lastname,
                     'email': email}

    member_xml = ET.fromstring(xml_str)
    member = Member._from_xml(member_xml, client)

    xml_response = """<?xml version="1.0" encoding="utf-8"?>
        <responsecode xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
            <code>OK</code>
        </responsecode>"""

    http = build_http_mock(HttpMock, content=xml_response)
    test_track_id = get_random_md5()
    member.remove_favourite(test_track_id)
Пример #9
0
def test_get_member_playlists(HttpMock):
    client = init_client()
    test_member_id = get_random_md5()
    username = '******'
    firstname = 'Test'
    lastname = 'User'
    email = '*****@*****.**'

    member_xml = ET.fromstring("""<memberaccount id="%(test_member_id)s">
                                    <username>%(username)s</username>
                                    <firstname>%(firstname)s</firstname>
                                    <lastname>%(lastname)s</lastname>
                                    <email>%(email)s</email>
                                </memberaccount>""" % {'test_member_id': test_member_id,
                                                       'username': username,
                                                       'firstname': firstname,
                                                       'lastname': lastname,
                                                       'email': email})

    member = Member._from_xml(member_xml, client)

    test_playlist_id = get_random_md5()
    test_playlist_name = 'test playlist'

    content = """<?xml version="1.0" encoding="utf-8"?>
                     <ResponsePlaylists>
                        <playlists>
                            <playlist id="%(id)s" name="%(name)s">
                                <tracks>
                                    <track tracknumber="001" time="02:50" lengthseconds="170" comment="Make sure
                                        you’re down the front for this fiery Post Punk workout."
                                        composer="&quot;S. Milton, J. Wygens&quot;" publisher="HM"
                                        name="Guerilla Pop" id="17376d36f309f18d" keywords="" lyrics=""
                                        displaytitle="Guerilla Pop" genre="Pop / Rock" tempo="" instrumentation=""
                                        bpm="" mixout="" frequency="44100" bitrate="1411" />
                                </tracks>
                            </playlist>
                        </playlists>
                    </ResponsePlaylists>""" % {'id': test_playlist_id,
                                            'name': test_playlist_name}

    http = build_http_mock(HttpMock, content=content)
    playlists = member.get_playlists()

    assert isinstance(playlists, list)

    playlist = playlists[0]

    assert playlist.id == test_playlist_id
    assert playlist.name == test_playlist_name
Пример #10
0
def test_member_authenticate_fail(HttpMock):
    client = init_client()
    test_username = '******'
    test_password = get_random_md5()

    content = """<?xml version="1.0" encoding="utf-8"?>
                    <responsemember>
                    <error>
                        <code>6</code>
                        <description>Invalid Login Details</description>
                    </error>
                 </responsemember>"""

    http = build_http_mock(HttpMock, content=content)
    member = Member.authenticate(test_username, test_password, client)
Пример #11
0
def test_member_authenticate_fail(HttpMock):
    client = init_client()
    test_username = '******'
    test_password = get_random_md5()

    content = """<?xml version="1.0" encoding="utf-8"?>
                    <responsemember>
                    <error>
                        <code>6</code>
                        <description>Invalid Login Details</description>
                    </error>
                 </responsemember>"""

    http = build_http_mock(HttpMock, content=content)
    member = Member.authenticate(test_username, test_password, client)
Пример #12
0
def test_get_member_favourites(HttpMock):
    client = init_client()
    test_member_id = get_random_md5()
    username = '******'
    firstname = 'Test'
    lastname = 'User'
    email = '*****@*****.**'

    member_xml = ET.fromstring("""<memberaccount id="%(test_member_id)s">
                                        <username>%(username)s</username>
                                        <firstname>%(firstname)s</firstname>
                                        <lastname>%(lastname)s</lastname>
                                        <email>%(email)s</email>
                                    </memberaccount>""" % \
                                    {'test_member_id': test_member_id,
                                     'username': username,
                                     'firstname': firstname,
                                     'lastname': lastname,
                                     'email': email})

    member = Member._from_xml(member_xml, client)

    test_track_id = get_random_md5()
    test_track_name = 'test track'

    xml_response = """<?xml version="1.0" encoding="utf-8"?>
                         <ResponseFavourites>
                            <favourites>
                                <tracks>
                                    <track id="%(id)s" name="%(name)s" />
                                </tracks>
                            </favourites>
                        </ResponseFavourites>""" % {
        'id': test_track_id,
        'name': test_track_name
    }

    http = build_http_mock(HttpMock, content=xml_response)
    favourites = member.get_favourites()

    assert isinstance(favourites, list)

    favourite = favourites[0]

    assert favourite.id == test_track_id
    assert favourite.name == test_track_name
Пример #13
0
def test_get_member_favourites(HttpMock):
    client = init_client()
    test_member_id = get_random_md5()
    username = '******'
    firstname = 'Test'
    lastname = 'User'
    email = '*****@*****.**'

    member_xml = ET.fromstring("""<memberaccount id="%(test_member_id)s">
                                        <username>%(username)s</username>
                                        <firstname>%(firstname)s</firstname>
                                        <lastname>%(lastname)s</lastname>
                                        <email>%(email)s</email>
                                    </memberaccount>""" % \
                                    {'test_member_id': test_member_id,
                                     'username': username,
                                     'firstname': firstname,
                                     'lastname': lastname,
                                     'email': email})

    member = Member._from_xml(member_xml, client)

    test_track_id = get_random_md5()
    test_track_name = 'test track'

    xml_response = """<?xml version="1.0" encoding="utf-8"?>
                         <ResponseFavourites>
                            <favourites>
                                <tracks>
                                    <track id="%(id)s" name="%(name)s" />
                                </tracks>
                            </favourites>
                        </ResponseFavourites>""" % {'id': test_track_id,
                                                   'name': test_track_name}

    http = build_http_mock(HttpMock, content=xml_response)
    favourites = member.get_favourites()

    assert isinstance(favourites, list)

    favourite = favourites[0]

    assert favourite.id == test_track_id
    assert favourite.name == test_track_name
Пример #14
0
def test_register_member(HttpMock):
    client = init_client()
    test_member_id = get_random_md5()
    username = '******'
    first_name = 'Test'
    last_name = 'User'
    email = '*****@*****.**'

    xml_response = """<?xml version="1.0" encoding="utf-8"?>
     <ResponseMember>
        <memberaccount id="%(test_member_id)s">
            <username>%(username)s</username>
            <first_name>%(first_name)s</first_name>
            <last_name>%(last_name)s</last_name>
            <email>%(email)s</email>
        </memberaccount>
    </ResponseMember>""" % {
        'test_member_id': test_member_id,
        'username': username,
        'first_name': first_name,
        'last_name': last_name,
        'email': email
    }

    username = username
    first_name = first_name
    last_name = last_name
    email = email
    termsaccept = 'true'
    fileformat = 'MP3'

    http = build_http_mock(HttpMock, content=xml_response)
    member = Member.register(_client=client,
                             username=username,
                             firstname=first_name,
                             lastname=last_name,
                             email=email,
                             termsaccept=termsaccept,
                             fileformat=fileformat)

    assert member.id == test_member_id
    assert member.username == username
Пример #15
0
def test_member_authenticate(HttpMock):
    client = init_client()
    test_member_id = get_random_md5()
    test_username = '******'
    test_password = get_random_md5()
    test_firstname = 'first'
    test_lastname = 'last'
    test_email = '*****@*****.**'

    content = """<?xml version="1.0" encoding="utf-8"?>
                 <ResponseMember>
                    <memberaccount id="%(test_member_id)s">
                        <username>%(test_username)s</username>
                        <firstname>%(test_firstname)s</firstname>
                        <lastname>%(test_lastname)s</lastname>
                        <email>%(test_email)s</email>
                    </memberaccount>
                </ResponseMember>""" % locals()

    http = build_http_mock(HttpMock, content=content)
    member = Member.authenticate(test_username, test_password, client)
    assert member.id == test_member_id
Пример #16
0
def test_member_authenticate(HttpMock):
    client = init_client()
    test_member_id = get_random_md5()
    test_username = '******'
    test_password = get_random_md5()
    test_firstname = 'first'
    test_lastname = 'last'
    test_email = '*****@*****.**'

    content = """<?xml version="1.0" encoding="utf-8"?>
                 <ResponseMember>
                    <memberaccount id="%(test_member_id)s">
                        <username>%(test_username)s</username>
                        <firstname>%(test_firstname)s</firstname>
                        <lastname>%(test_lastname)s</lastname>
                        <email>%(test_email)s</email>
                    </memberaccount>
                </ResponseMember>""" % locals()

    http = build_http_mock(HttpMock, content=content)
    member = Member.authenticate(test_username, test_password, client)
    assert member.id == test_member_id
Пример #17
0
from harvestmedia.api.config import Config
from harvestmedia.api.client import Client
from harvestmedia.api.member import Member

api_key = 'e1d5d645d2d984e499e816a7a314dfbd610149f124c3373455c37ad75ab3ffccf444a04a10953b62'
webservice_url = 'https://service.harvestmedia.net/HMP-WS.svc'

client = Client(api_key=api_key, debug_level='DEBUG')

#member = Member(client)
#member.username = '******'
#member.email = '*****@*****.**'
#member.firstname = 'Ryan1'
#member.lastname = 'Roemmich1'
#member.create()

#member = Member(client)
#member.send_password('test')

member = Member(client)
authenticated = member.authenticate('test', 'test', client)
print authenticated

playlists = member.get_playlists()

for playlist in playlists:
    print playlist.id + ': ' + playlist.name