<s> from quandl . connection import Connection <EOL> from quandl . api_config import ApiConfig <EOL> from quandl . errors . quandl_error import ( <EOL> QuandlError , LimitExceededError , InternalServerError , <EOL> AuthenticationError , ForbiddenError , InvalidRequestError , <EOL> NotFoundError , ServiceUnavailableError ) <EOL> import unittest2 <EOL> from test . helpers . httpretty_extension import httpretty <EOL> import json <EOL> from mock import patch , call <EOL> class ConnectionTest ( unittest2 . TestCase ) : <EOL> @ httpretty . activate <EOL> def test_quandl_exceptions ( self ) : <EOL> quandl_errors = [ ( '<STR_LIT>' , <NUM_LIT> , LimitExceededError ) , <EOL> ( '<STR_LIT>' , <NUM_LIT> , InternalServerError ) , <EOL> ( '<STR_LIT>' , <NUM_LIT> , AuthenticationError ) , <EOL> ( '<STR_LIT>' , <NUM_LIT> , ForbiddenError ) , <EOL> ( '<STR_LIT>' , <NUM_LIT> , InvalidRequestError ) , <EOL> ( '<STR_LIT>' , <NUM_LIT> , NotFoundError ) , <EOL> ( '<STR_LIT>' , <NUM_LIT> , ServiceUnavailableError ) , <EOL> ( '<STR_LIT>' , <NUM_LIT> , QuandlError ) ] <EOL> httpretty . register_uri ( httpretty . GET , <EOL> "<STR_LIT>" , <EOL> responses = [ httpretty . Response ( body = json . dumps ( <EOL> { '<STR_LIT>' : <EOL> { '<STR_LIT:code>' : x [ <NUM_LIT:0> ] , '<STR_LIT:message>' : '<STR_LIT>' } } ) , <EOL> status = x [ <NUM_LIT:1> ] ) for x in quandl_errors ] <EOL> ) <EOL> for expected_error in quandl_errors : <EOL> self . assertRaises ( <EOL> expected_error [ <NUM_LIT:2> ] , lambda : Connection . request ( '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> @ httpretty . activate <EOL> def test_parse_error ( self ) : <EOL> httpretty . register_uri ( httpretty . GET , <EOL> "<STR_LIT>" , <EOL> body = "<STR_LIT>" , status = <NUM_LIT> ) <EOL> self . assertRaises ( <EOL> QuandlError , lambda : Connection . request ( '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> @ httpretty . activate <EOL> @ patch ( '<STR_LIT>' ) <EOL> def test_build_request ( self , mock ) : <EOL> ApiConfig . api_key = '<STR_LIT>' <EOL> ApiConfig . api_version = '<STR_LIT>' <EOL> params = { '<STR_LIT>' : <NUM_LIT:10> , '<STR_LIT>' : <NUM_LIT:2> } <EOL> headers = { '<STR_LIT>' : '<STR_LIT>' } <EOL> Connection . request ( '<STR_LIT>' , '<STR_LIT>' , headers = headers , params = params ) <EOL> expected = call ( '<STR_LIT>' , '<STR_LIT>' , <EOL> headers = { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : ( '<STR_LIT>' <EOL> '<STR_LIT>' ) , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' } , <EOL> params = { '<STR_LIT>' : <NUM_LIT:10> , '<STR_LIT>' : <NUM_LIT:2> } ) <EOL> self . assertEqual ( mock . call_args , expected ) </s>
