Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_init(self):
result = {
'coupons': {'url': 'blah'},
'id': 1
}
map = Orders(result)
self.assertEqual(map.id, 1)
self.assertEqual(map['id'], 1)
self.assertNotIsInstance(map.coupons, dict)
def test_create_basic(self):
api = bigcommerce.api.BigcommerceApi(host='store.mybigcommerce.com', basic_auth=('admin', 'abcdef'))
self.assertIsInstance(api.connection, Connection)
self.assertNotIsInstance(api.connection, OAuthConnection)
self.assertRaises(Exception, lambda: bigcommerce.api.BigcommerceApi(client_id='123', basic_auth=('admin', 'token')))
def test_full_path(self):
connection = OAuthConnection(client_id='123', store_hash='abcdef')
self.assertEqual(connection.full_path('time'), 'https://api.bigcommerce.com/stores/abcdef/v2/time')
def test_alternate_api_endpoint(self):
connection = OAuthConnection(client_id='123', store_hash='abcdef', host='barbaz.com')
self.assertEqual(connection.full_path('time'), 'https://barbaz.com/stores/abcdef/v2/time')
def test_fetch_token(self):
client_id = 'abc123'
client_secret = '123abc'
code = 'hellosecret'
context = 'stores/abc'
scope = 'store_v2_products'
redirect_uri = 'http://localhost/callback'
result = {'access_token': '12345abcdef'}
connection = OAuthConnection(client_id, store_hash='abc')
connection.post = MagicMock()
connection.post.return_value = result
res = connection.fetch_token(client_secret, code, context, scope, redirect_uri)
self.assertEqual(res, result)
self.assertDictEqual(connection._session.headers,
{'X-Auth-Client': 'abc123', 'X-Auth-Token': '12345abcdef',
'Accept': 'application/json', 'Accept-Encoding': 'gzip'})
connection.post.assert_called_once_with('https://login.bigcommerce.com/oauth2/token',
{
'client_id': client_id,
'client_secret': client_secret,
'code': code,
'context': context,
'scope': scope,
'grant_type': 'authorization_code',
def test_create_basic(self):
api = bigcommerce.api.BigcommerceApi(host='store.mybigcommerce.com', basic_auth=('admin', 'abcdef'))
self.assertIsInstance(api.connection, Connection)
self.assertNotIsInstance(api.connection, OAuthConnection)
def test_create_oauth(self):
api = bigcommerce.api.BigcommerceApi(client_id='123456', store_hash='abcdef', access_token='123abc')
self.assertIsInstance(api.connection, OAuthConnection)
def test_create(self):
connection = Connection(host='store.mybigcommerce.com', auth=('user', 'abcdef'))
self.assertTupleEqual(connection._session.auth, ('user', 'abcdef'))
def test_full_path(self):
connection = Connection(host='store.mybigcommerce.com', auth=('user', 'abcdef'))
self.assertEqual(connection.full_path('time'), 'https://store.mybigcommerce.com/api/v2/time')