<s> import unittest <EOL> from bigcommerce . resources import Mapping , Orders , ApiResource , OrderShipments , Products , CountryStates , OrderCoupons , Webhooks , GoogleProductSearchMappings <EOL> from mock import MagicMock <EOL> class TestMapping ( unittest . TestCase ) : <EOL> def test_init ( self ) : <EOL> result = { <EOL> '<STR_LIT>' : { '<STR_LIT:url>' : '<STR_LIT>' } , <EOL> '<STR_LIT:id>' : <NUM_LIT:1> <EOL> } <EOL> map = Orders ( result ) <EOL> self . assertEqual ( map . id , <NUM_LIT:1> ) <EOL> self . assertEqual ( map [ '<STR_LIT:id>' ] , <NUM_LIT:1> ) <EOL> self . assertNotIsInstance ( map . coupons , dict ) <EOL> def test_str ( self ) : <EOL> map = Mapping ( { '<STR_LIT:id>' : <NUM_LIT:1> , '<STR_LIT>' : MagicMock ( ) } ) <EOL> self . assertEqual ( str ( map ) , str ( { '<STR_LIT:id>' : <NUM_LIT:1> } ) ) <EOL> class TestApiResource ( unittest . TestCase ) : <EOL> def test_create_object ( self ) : <EOL> result = { '<STR_LIT:id>' : <NUM_LIT:1> } <EOL> object = ApiResource . _create_object ( result , MagicMock ( ) ) <EOL> self . assertEqual ( object . id , <NUM_LIT:1> ) <EOL> results = [ { '<STR_LIT:id>' : <NUM_LIT:1> } , { '<STR_LIT:id>' : <NUM_LIT:2> } , { '<STR_LIT:id>' : <NUM_LIT:3> } ] <EOL> objects = ApiResource . _create_object ( results , MagicMock ) <EOL> self . assertIsInstance ( objects , list ) <EOL> for object in objects : <EOL> self . assertIsNotNone ( object . id ) <EOL> self . assertIsNotNone ( object . _connection ) <EOL> def test_get ( self ) : <EOL> connection = MagicMock ( ) <EOL> connection . make_request . return_value = { '<STR_LIT:id>' : <NUM_LIT:1> } <EOL> result = Orders . get ( <NUM_LIT:1> , connection ) <EOL> self . assertIsInstance ( result , Orders ) <EOL> self . assertEqual ( result . id , <NUM_LIT:1> ) <EOL> connection . make_request . assert_called_once_with ( '<STR_LIT:GET>' , '<STR_LIT>' , None , { } , { } ) <EOL> class TestApiSubResource ( unittest . TestCase ) : <EOL> def test_get ( self ) : <EOL> connection = MagicMock ( ) <EOL> connection . make_request . return_value = { '<STR_LIT:id>' : <NUM_LIT:2> } <EOL> result = OrderCoupons . get ( <NUM_LIT:1> , <NUM_LIT:2> , connection ) <EOL> self . assertIsInstance ( result , OrderCoupons ) <EOL> self . assertEqual ( result . id , <NUM_LIT:2> ) <EOL> connection . make_request . assert_called_once_with ( '<STR_LIT:GET>' , '<STR_LIT>' , None , { } , { } ) <EOL> def test_parent_id ( self ) : <EOL> coupon = OrderCoupons ( { '<STR_LIT:id>' : <NUM_LIT:2> , '<STR_LIT>' : <NUM_LIT:1> } ) <EOL> self . assertEqual ( coupon . parent_id ( ) , <NUM_LIT:1> ) <EOL> class TestCreateableApiResource ( unittest . TestCase ) : <EOL> def test_create ( self ) : <EOL> connection = MagicMock ( ) <EOL> connection . make_request . return_value = { '<STR_LIT:id>' : <NUM_LIT:1> } <EOL> result = Orders . create ( connection , name = "<STR_LIT>" ) <EOL> self . assertIsInstance ( result , Orders ) <EOL> self . assertEqual ( result . id , <NUM_LIT:1> ) <EOL> connection . make_request . assert_called_once_with ( '<STR_LIT:POST>' , '<STR_LIT>' , { '<STR_LIT:name>' : '<STR_LIT>' } , { } , { } ) <EOL> class TestCreateableApiSubResource ( unittest . TestCase ) : <EOL> def test_create ( self ) : <EOL> connection = MagicMock ( ) <EOL> connection . make_request . return_value = { '<STR_LIT:id>' : <NUM_LIT:2> } <EOL> result = OrderShipments . create ( <NUM_LIT:1> , connection , name = "<STR_LIT>" ) <EOL> self . assertIsInstance ( result , OrderShipments ) <EOL> self . assertEqual ( result . id , <NUM_LIT:2> ) <EOL> connection . make_request . assert_called_once_with ( '<STR_LIT:POST>' , '<STR_LIT>' , { '<STR_LIT:name>' : '<STR_LIT>' } , { } , { } ) <EOL> class TestListableApiResource ( unittest . TestCase ) : <EOL> def test_all ( self ) : <EOL> connection = MagicMock ( ) <EOL> connection . make_request . return_value = [ { '<STR_LIT:id>' : <NUM_LIT:1> } , { '<STR_LIT:id>' : <NUM_LIT:2> } ] <EOL> result = Orders . all ( connection , limit = <NUM_LIT:2> ) <EOL> self . assertEqual ( len ( result ) , <NUM_LIT:2> ) <EOL> connection . make_request . assert_called_once_with ( '<STR_LIT:GET>' , '<STR_LIT>' , None , { '<STR_LIT>' : <NUM_LIT:2> } , { } ) <EOL> class TestListableApiSubResource ( unittest . TestCase ) : <EOL> def test_all ( self ) : <EOL> connection = MagicMock ( ) <EOL> connection . make_request . return_value = [ { '<STR_LIT:id>' : <NUM_LIT:1> } , { '<STR_LIT:id>' : <NUM_LIT:2> } ] <EOL> result = OrderCoupons . all ( <NUM_LIT:1> , connection , limit = <NUM_LIT:2> ) <EOL> self . assertEqual ( len ( result ) , <NUM_LIT:2> ) <EOL> connection . make_request . assert_called_once_with ( '<STR_LIT:GET>' , '<STR_LIT>' , None , { '<STR_LIT>' : <NUM_LIT:2> } , { } ) <EOL> def test_google_mappings ( self ) : <EOL> connection = MagicMock ( ) <EOL> connection . make_request . return_value = [ { '<STR_LIT:id>' : <NUM_LIT:1> } , { '<STR_LIT:id>' : <NUM_LIT:2> } ] <EOL> result = GoogleProductSearchMappings . all ( <NUM_LIT:1> , connection , limit = <NUM_LIT:2> ) <EOL> self . assertEqual ( len ( result ) , <NUM_LIT:2> ) <EOL> connection . make_request . assert_called_once_with ( '<STR_LIT:GET>' , '<STR_LIT>' , None , { '<STR_LIT>' : <NUM_LIT:2> } , { } ) <EOL> class TestUpdateableApiResource ( unittest . TestCase ) : <EOL> def test_update ( self ) : <EOL> connection = MagicMock ( ) <EOL> connection . make_request . return_value = { '<STR_LIT:id>' : <NUM_LIT:1> } <EOL> order = Orders ( { '<STR_LIT:id>' : <NUM_LIT:1> } , _connection = connection ) <EOL> new_order = order . update ( name = '<STR_LIT>' ) <EOL> self . assertIsInstance ( new_order , Orders ) <EOL> connection . make_request . assert_called_once_with ( '<STR_LIT>' , '<STR_LIT>' , { '<STR_LIT:name>' : '<STR_LIT>' } , { } , { } ) <EOL> class TestUpdateableApiSubResource ( unittest . TestCase ) : <EOL> def test_update ( self ) : <EOL> connection = MagicMock ( ) <EOL> connection . make_request . return_value = { '<STR_LIT:id>' : <NUM_LIT:1> } <EOL> order = OrderShipments ( { '<STR_LIT:id>' : <NUM_LIT:1> , '<STR_LIT>' : <NUM_LIT:2> } , _connection = connection ) <EOL> new_order = order . update ( tracking_number = '<STR_LIT>' ) <EOL> self . assertIsInstance ( new_order , OrderShipments ) <EOL> connection . make_request . assert_called_once_with ( '<STR_LIT>' , '<STR_LIT>' , { '<STR_LIT>' : '<STR_LIT>' } , <EOL> { } , { } ) <EOL> class TestDeleteableApiResource ( unittest . TestCase ) : <EOL> def test_delete_all ( self ) : <EOL> connection = MagicMock ( ) <EOL> connection . make_request . return_value = { } <EOL> self . assertEqual ( Orders . delete_all ( connection ) , { } ) <EOL> connection . make_request . assert_called_once_with ( '<STR_LIT>' , '<STR_LIT>' , None , { } , { } ) <EOL> def test_delete ( self ) : <EOL> connection = MagicMock ( ) <EOL> connection . make_request . return_value = { } <EOL> order = Orders ( { '<STR_LIT:id>' : <NUM_LIT:1> } , _connection = connection ) <EOL> self . assertEqual ( order . delete ( ) , { } ) <EOL> connection . make_request . assert_called_once_with ( '<STR_LIT>' , '<STR_LIT>' , None , { } , { } ) <EOL> class TestDeleteableApiSubResource ( unittest . TestCase ) : <EOL> def test_delete_all ( self ) : <EOL> connection = MagicMock ( ) <EOL> connection . make_request . return_value = { } <EOL> self . assertEqual ( OrderShipments . delete_all ( <NUM_LIT:1> , connection = connection ) , { } ) <EOL> connection . make_request . assert_called_once_with ( '<STR_LIT>' , '<STR_LIT>' , None , { } , { } ) <EOL> def test_delete ( self ) : <EOL> connection = MagicMock ( ) <EOL> connection . make_request . return_value = { } <EOL> shipment = OrderShipments ( { '<STR_LIT:id>' : <NUM_LIT:1> , '<STR_LIT>' : <NUM_LIT:2> , '<STR_LIT>' : connection } ) <EOL> self . assertEqual ( shipment . delete ( ) , { } ) <EOL> connection . make_request . assert_called_once_with ( '<STR_LIT>' , '<STR_LIT>' , None , { } , { } ) <EOL> class TestCountableApiResource ( unittest . TestCase ) : <EOL> def test_count ( self ) : <EOL> connection = MagicMock ( ) <EOL> connection . make_request . return_value = { '<STR_LIT:count>' : <NUM_LIT:2> } <EOL> self . assertEqual ( Products . count ( connection , is_visible = True ) , <NUM_LIT:2> ) <EOL> connection . make_request . assert_called_once_with ( '<STR_LIT:GET>' , '<STR_LIT>' , None , { '<STR_LIT>' : True } , { } ) <EOL> class TestCountableApiSubResource ( unittest . TestCase ) : <EOL> def test_count ( self ) : <EOL> connection = MagicMock ( ) <EOL> connection . make_request . return_value = { '<STR_LIT:count>' : <NUM_LIT:2> } <EOL> self . assertEqual ( CountryStates . count ( <NUM_LIT:1> , connection = connection , is_visible = True ) , <NUM_LIT:2> ) <EOL> connection . make_request . assert_called_once_with ( '<STR_LIT:GET>' , '<STR_LIT>' , None , { '<STR_LIT>' : True } , { } ) <EOL> def test_count_with_custom_count_path ( self ) : <EOL> connection = MagicMock ( ) <EOL> connection . make_request . return_value = { '<STR_LIT:count>' : <NUM_LIT:2> } <EOL> self . assertEqual ( OrderShipments . count ( connection = connection , is_visible = True ) , <NUM_LIT:2> ) <EOL> connection . make_request . assert_called_once_with ( '<STR_LIT:GET>' , '<STR_LIT>' , None , { '<STR_LIT>' : True } , { } ) </s>
