<s> from mock import Mock <EOL> from nose . tools import assert_equal , raises <EOL> from steamcondenser . community import WebApi , WebApiError <EOL> import __builtin__ <EOL> import urllib <EOL> import urllib2 <EOL> class TestWebApi ( object ) : <EOL> """<STR_LIT>""" <EOL> @ classmethod <EOL> def setup_class ( cls ) : <EOL> WebApi . api_key = '<STR_LIT>' <EOL> def test_get_api_key ( self ) : <EOL> assert_equal ( '<STR_LIT>' , WebApi . api_key ) <EOL> def test_set_api_key ( self ) : <EOL> WebApi . api_key = '<STR_LIT>' <EOL> assert_equal ( '<STR_LIT>' , WebApi . api_key ) <EOL> @ raises ( WebApiError ) <EOL> def test_set_invalid_api_key ( self ) : <EOL> WebApi . api_key = '<STR_LIT:test>' <EOL> def test_json ( self ) : <EOL> WebApi . get = Mock ( ) <EOL> WebApi . json ( '<STR_LIT>' , '<STR_LIT>' , <NUM_LIT:2> , test = '<STR_LIT>' ) <EOL> WebApi . get . assert_called_once_with ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <NUM_LIT:2> , <EOL> test = '<STR_LIT>' ) <EOL> def test_get ( self ) : <EOL> urllib2 . urlopen = Mock ( return_value = __builtin__ ) <EOL> urllib . urlencode = Mock ( return_value = '<STR_LIT>' ) <EOL> __builtin__ . read = Mock ( return_value = '<STR_LIT:data>' ) <EOL> assert_equal ( '<STR_LIT:data>' , WebApi . get ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <NUM_LIT:2> , <EOL> test = '<STR_LIT>' ) ) <EOL> urllib2 . urlopen . assert_called_once_with ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' ) <EOL> urllib . urlencode . assert_called_once_with ( <EOL> { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT:key>' : '<STR_LIT>' , <EOL> '<STR_LIT:test>' : '<STR_LIT>' } <EOL> ) <EOL> @ raises ( WebApiError ) <EOL> def test_get_error ( self ) : <EOL> urllib2 . urlopen = Mock ( side_effect = urllib2 . HTTPError ( '<STR_LIT>' , <NUM_LIT> , <EOL> '<STR_LIT>' , <EOL> None , None ) ) <EOL> WebApi . get ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <NUM_LIT:2> , test = '<STR_LIT>' ) </s>
