def test_incorrect_input_data_missing_description(HttpMock): api_key = get_random_md5() content = """<?xml version="1.0" encoding="utf-8"?> <memberaccount> <error> <code>2</code> </error> </memberaccount>""" http = build_http_mock(HttpMock, content=content) client = harvestmedia.api.client.Client(api_key=api_key) libraries = Library.get_libraries(client)
def test_invalid_token(HttpMock): api_key = get_random_md5() content = """<?xml version="1.0" encoding="utf-8"?> <memberaccount> <error> <code>5</code> <description>Invalid Token</description> </error> </memberaccount>""" http = build_http_mock(HttpMock, content=content) client = harvestmedia.api.client.Client(api_key=api_key) libraries = Library.get_libraries(client)
def test_get_library_logo_url(HttpMock): client = init_client() width = 200 height = 400 library_id = '11235813' library_logo_url = "http://download.harvestmedia.net/wslibrarylogo/8185d768cd8fcaa7/{id}/{width}/{height}" library_xml = ET.fromstring(textwrap.dedent("""<library detail="" name="" id="%(library_id)s" location="Talent, Oregon" website="http://risefromyourgrave.com" librarylogourl="%(library_logo_url)s" />""" % locals())) library = Library._from_xml(library_xml, client) library_logo_url = library.get_logo_url(width, height) expected_url = library_logo_url.replace('{id}', library_id).replace('{width}', str(width)).replace('{height}]', str(height)) assert library_logo_url == expected_url
def test_get_library_logo_url(HttpMock): client = init_client() width = 200 height = 400 library_id = '11235813' library_logo_url = "http://download.harvestmedia.net/wslibrarylogo/8185d768cd8fcaa7/{id}/{width}/{height}" library_xml = ET.fromstring( textwrap.dedent( """<library detail="" name="" id="%(library_id)s" location="Talent, Oregon" website="http://risefromyourgrave.com" librarylogourl="%(library_logo_url)s" />""" % locals())) library = Library._from_xml(library_xml, client) library_logo_url = library.get_logo_url(width, height) expected_url = library_logo_url.replace('{id}', library_id).replace( '{width}', str(width)).replace('{height}]', str(height)) assert library_logo_url == expected_url
def test_invalid_remote_token(HttpMock): api_key = get_random_md5() expiry = datetime.datetime.now() expiry += datetime.timedelta(hours=22) # offset for HM timezone test_token = get_random_md5() return_values = [ (200, """<?xml version="1.0" encoding="utf-8"?> <responseservicetoken> <token value="%s" expiry="%s"/> </responseservicetoken>""" % \ (test_token, expiry.strftime("%Y-%m-%dT%H:%M:%S"))), (200, """<memberaccount> <error> <code>5</code> <description>Invalid Token</description> </error> </memberaccount>"""), ] http = build_http_mock(HttpMock, responses=return_values) client = harvestmedia.api.client.Client(api_key=api_key) libraries = Library.get_libraries(client)