def test_base_client_read(): """ test cases: method default (get) - other we already tested format json|yaml ( should produce error) codes 200|400|401|403|404|500 """ public_key = 'public' secret_key = 'secret' bc = BaseClient(public_key, secret_key) test_url = 'http://test.url' #produce error on format other then json class NotJsonException(Exception): pass try: bc.read(url=test_url, format='yaml') raise NotJsonException() except NotJsonException, e: assert 0, "BaseClient.read() doesn't produce error on yaml format"
def test_base_client_read(): """ test cases: method default (get) - other we already tested format json|yaml ( should produce error) codes 200|400|401|403|404|500 """ public_key = 'public' secret_key = 'secret' bc = BaseClient(public_key, secret_key) test_url = 'http://test.url' #produce error on format other then json class NotJsonException(Exception): pass try: bc.read(url=test_url, format='yaml') raise NotJsonException() except NotJsonException as e: assert 0, "BaseClient.read() doesn't produce error on yaml format" except: pass #test get, all ok result = bc.read(url=test_url) assert result == sample_json_dict, result #test get, 400 error try: result = base_client_read_400(bc=bc, url=test_url) except HTTP400BadRequestError as e: pass except Exception as e: assert 0, "Incorrect exception raised for 400 code: " + str(e) #test get, 401 error try: result = base_client_read_401(bc=bc, url=test_url) except HTTP401UnauthorizedError as e: pass except Exception as e: assert 0, "Incorrect exception raised for 401 code: " + str(e) #test get, 403 error try: result = base_client_read_403(bc=bc, url=test_url) except HTTP403ForbiddenError as e: pass except Exception as e: assert 0, "Incorrect exception raised for 403 code: " + str(e) #test get, 404 error try: result = base_client_read_404(bc=bc, url=test_url) except HTTP404NotFoundError as e: pass except Exception as e: assert 0, "Incorrect exception raised for 404 code: " + str(e) #test get, 500 error try: result = base_client_read_500(bc=bc, url=test_url) except urllib2.HTTPError as e: if e.code == 500: pass else: assert 0, "Incorrect exception raised for 500 code: " + str(e) except Exception as e: assert 0, "Incorrect exception raised for 500 code: " + str(e)