<s> import shopify <EOL> from test . test_helper import TestCase <EOL> from pyactiveresource . activeresource import ActiveResource <EOL> from mock import patch <EOL> import threading <EOL> class BaseTest ( TestCase ) : <EOL> @ classmethod <EOL> def setUpClass ( self ) : <EOL> self . session1 = shopify . Session ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . session2 = shopify . Session ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> def setUp ( self ) : <EOL> super ( BaseTest , self ) . setUp ( ) <EOL> def tearDown ( self ) : <EOL> shopify . ShopifyResource . clear_session ( ) <EOL> def test_activate_session_should_set_site_and_headers_for_given_session ( self ) : <EOL> shopify . ShopifyResource . activate_session ( self . session1 ) <EOL> self . assertIsNone ( ActiveResource . site ) <EOL> self . assertEqual ( '<STR_LIT>' , shopify . ShopifyResource . site ) <EOL> self . assertEqual ( '<STR_LIT>' , shopify . Shop . site ) <EOL> self . assertIsNone ( ActiveResource . headers ) <EOL> self . assertEqual ( '<STR_LIT>' , shopify . ShopifyResource . headers [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( '<STR_LIT>' , shopify . Shop . headers [ '<STR_LIT>' ] ) <EOL> def test_clear_session_should_clear_site_and_headers_from_Base ( self ) : <EOL> shopify . ShopifyResource . activate_session ( self . session1 ) <EOL> shopify . ShopifyResource . clear_session ( ) <EOL> self . assertIsNone ( ActiveResource . site ) <EOL> self . assertIsNone ( shopify . ShopifyResource . site ) <EOL> self . assertIsNone ( shopify . Shop . site ) <EOL> self . assertIsNone ( ActiveResource . headers ) <EOL> self . assertFalse ( '<STR_LIT>' in shopify . ShopifyResource . headers ) <EOL> self . assertFalse ( '<STR_LIT>' in shopify . Shop . headers ) <EOL> def test_activate_session_with_one_session_then_clearing_and_activating_with_another_session_shoul_request_to_correct_shop ( self ) : <EOL> shopify . ShopifyResource . activate_session ( self . session1 ) <EOL> shopify . ShopifyResource . clear_session ( ) <EOL> shopify . ShopifyResource . activate_session ( self . session2 ) <EOL> self . assertIsNone ( ActiveResource . site ) <EOL> self . assertEqual ( '<STR_LIT>' , shopify . ShopifyResource . site ) <EOL> self . assertEqual ( '<STR_LIT>' , shopify . Shop . site ) <EOL> self . assertIsNone ( ActiveResource . headers ) <EOL> self . assertEqual ( '<STR_LIT>' , shopify . ShopifyResource . headers [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( '<STR_LIT>' , shopify . Shop . headers [ '<STR_LIT>' ] ) <EOL> def test_delete_should_send_custom_headers_with_request ( self ) : <EOL> shopify . ShopifyResource . activate_session ( self . session1 ) <EOL> org_headers = shopify . ShopifyResource . headers <EOL> shopify . ShopifyResource . set_headers ( { '<STR_LIT>' : '<STR_LIT:abc>' } ) <EOL> with patch ( '<STR_LIT>' ) as mock : <EOL> url = shopify . ShopifyResource . _custom_method_collection_url ( '<STR_LIT:1>' , { } ) <EOL> shopify . ShopifyResource . delete ( '<STR_LIT:1>' ) <EOL> mock . assert_called_with ( url , { '<STR_LIT>' : '<STR_LIT:abc>' } ) <EOL> shopify . ShopifyResource . set_headers ( org_headers ) <EOL> def test_headers_includes_user_agent ( self ) : <EOL> self . assertTrue ( '<STR_LIT>' in shopify . ShopifyResource . headers ) <EOL> t = threading . Thread ( target = lambda : self . assertTrue ( '<STR_LIT>' in shopify . ShopifyResource . headers ) ) <EOL> t . start ( ) <EOL> t . join ( ) <EOL> def test_headers_is_thread_safe ( self ) : <EOL> def testFunc ( ) : <EOL> shopify . ShopifyResource . headers [ '<STR_LIT>' ] = '<STR_LIT:abc>' <EOL> self . assertTrue ( '<STR_LIT>' in shopify . ShopifyResource . headers ) <EOL> t1 = threading . Thread ( target = testFunc ) <EOL> t1 . start ( ) <EOL> t1 . join ( ) <EOL> t2 = threading . Thread ( target = lambda : self . assertFalse ( '<STR_LIT>' in shopify . ShopifyResource . headers ) ) <EOL> t2 . start ( ) <EOL> t2 . join ( ) </s>
