def setUp(self):
        self.api_url = 'https://test.bynder.com'
        self.consumer_key = 'AAAA'
        self.consumer_secret = 'BBBB'
        self.token = 'CCCC'
        self.token_secret = 'DDDD'

        self.bynder_client = BynderClient(base_url=self.api_url,
                                          consumer_key=self.consumer_key,
                                          consumer_secret=self.consumer_secret,
                                          token=self.token,
                                          token_secret=self.token_secret)
        self.bynder_client.bynder_request_handler.get = mock.MagicMock()
        self.bynder_client.bynder_request_handler.post = mock.MagicMock()
        self.bynder_client.bynder_request_handler.fetch_token = mock.MagicMock(
        )
        self.bynder_client.credentials.reset = mock.MagicMock()
Пример #2
0
    def setUp(self):
        self.api_url = 'https://test.bynder.com'
        self.consumer_key = 'AAAA'
        self.consumer_secret = 'BBBB'
        self.token = 'CCCC'
        self.token_secret = 'DDDD'

        self.bynder_client = BynderClient(base_url=self.api_url,
                                          consumer_key=self.consumer_key,
                                          consumer_secret=self.consumer_secret,
                                          token=self.token,
                                          token_secret=self.token_secret)
        self.asset_bank_client = self.bynder_client.asset_bank_client
        self.asset_bank_client.bynder_request_handler.get = mock.MagicMock()
        self.asset_bank_client.bynder_request_handler.post = mock.MagicMock()
        self.asset_bank_client.bynder_request_handler.delete = mock.MagicMock()
        self.asset_bank_client.upload_client.upload = mock.MagicMock()
class BynderClientTest(TestCase):
    """ Test the Bynder client.
    """
    def setUp(self):
        self.api_url = 'https://test.bynder.com'
        self.consumer_key = 'AAAA'
        self.consumer_secret = 'BBBB'
        self.token = 'CCCC'
        self.token_secret = 'DDDD'

        self.bynder_client = BynderClient(base_url=self.api_url,
                                          consumer_key=self.consumer_key,
                                          consumer_secret=self.consumer_secret,
                                          token=self.token,
                                          token_secret=self.token_secret)
        self.bynder_client.bynder_request_handler.get = mock.MagicMock()
        self.bynder_client.bynder_request_handler.post = mock.MagicMock()
        self.bynder_client.bynder_request_handler.fetch_token = mock.MagicMock(
        )
        self.bynder_client.credentials.reset = mock.MagicMock()

    def tearDown(self):
        self.bynder_client = None
        self.asset_bank_client = None
        self.collection_client = None

    def test_create_bynder_client(self):
        """ Test if the bynder client is not none.
        """
        self.assertIsNotNone(self.bynder_client)

    def test_bynder_client_set_base_url(self):
        """ Test if the bynder client has set the base url
        """
        self.assertIsNotNone(self.bynder_client.base_url)
        self.assertEqual(self.bynder_client.base_url, self.api_url)

    def test_bynder_client_set_credentials(self):
        """ Test if the bynder client has set the credentials
        """
        self.assertIsNotNone(self.bynder_client.credentials)
        self.assertEqual(self.bynder_client.credentials.consumer_key,
                         self.consumer_key)
        self.assertEqual(self.bynder_client.credentials.consumer_secret,
                         self.consumer_secret)
        self.assertEqual(self.bynder_client.credentials.token, self.token)
        self.assertEqual(self.bynder_client.credentials.token_secret,
                         self.token_secret)

    def test_bynder_client_set_request_handler(self):
        """ Test if the bynder client has set the request handler
        """
        self.assertIsNotNone(self.bynder_client.bynder_request_handler)

    def test_get_asset_bank_client(self):
        """ Test if the asset bank client is not none.
        """
        self.assertIsNotNone(self.bynder_client.asset_bank_client)

    def test_get_collection_client(self):
        """ Test if the collection client is not none.
        """
        self.assertIsNotNone(self.bynder_client.collection_client)

    def test_login(self):
        """ Test if when we call login it will use the correct payload for the
        request and returns successfully.
        """
        credentials = {'username': '******', 'password': '******'}
        self.bynder_client.login(credentials.get('username'),
                                 credentials.get('password'))
        self.bynder_client.bynder_request_handler.post.assert_called_with(
            endpoint='/api/v4/users/login/', payload=credentials)

    def test_authorise_url(self):
        """ Test if when we call authorise url it returns the right url.
        """
        authorise_url_endpoint = '/api/v4/oauth/authorise/?oauth_token={0}'.format(
            self.bynder_client.credentials.token)
        authorise_url = urljoin(self.bynder_client.base_url,
                                authorise_url_endpoint)
        self.assertEqual(self.bynder_client.authorise_url(), authorise_url)

        callback_url = 'https://bynder.com'
        self.assertEqual(
            self.bynder_client.authorise_url(callback_url),
            '{0}&callback={1}'.format(authorise_url, callback_url))

    def test_access_token(self):
        """ Test if when we call access token it will use the correct params for the
        request and returns successfully.
        """
        fetch_token = self.bynder_client.bynder_request_handler.fetch_token
        self.bynder_client.access_token()
        fetch_token.assert_called_with(endpoint='/api/v4/oauth/access_token/')

    def test_request_token(self):
        """ Test if when we call request token it will use the correct params for the
        request and returns successfully.
        """
        fetch_token = self.bynder_client.bynder_request_handler.fetch_token
        self.bynder_client.request_token()
        fetch_token.assert_called_with(endpoint='/api/v4/oauth/request_token/')

    def test_get_derivatives(self):
        """ Test if when we call derivatives it will use the correct params for the
        request and returns successfully.
        """
        self.bynder_client.derivatives()
        self.bynder_client.bynder_request_handler.get.assert_called_with(
            endpoint='/api/v4/derivatives/')

    def test_logout(self):
        """ Test if the reset method in credentials is called on logout.
        """
        self.bynder_client.logout()
        self.bynder_client.credentials.reset.assert_called_with()

    def test_update_tokens(self):
        """ Test if the tokens in the credentials are updated with
        the new tokens.
        """
        new_token = '123ABC'
        new_token_secret = '456DEF'

        self.bynder_client._update_tokens(new_token, new_token_secret)
        self.assertEqual(self.bynder_client.credentials.token, new_token)
        self.assertEqual(self.bynder_client.credentials.token_secret,
                         new_token_secret)
Пример #4
0
from bynder_sdk import BynderClient
import configparser

config = configparser.ConfigParser()
config.read('bynder.ini')

bynder_base_url = config.get('BYNDER_TOKENS', 'base_url'),
bynder_consumer_key = config.get('BYNDER_TOKENS', 'consumer_key'),
bynder_consumer_secret = config.get('BYNDER_TOKENS', 'consumer_secret'),
bynder_token = config.get('BYNDER_TOKENS', 'token'),
bynder_token_secret = config.get('BYNDER_TOKENS', 'token_secret')

bynder_client = BynderClient(
    base_url=config.get('BYNDER_TOKENS', 'base_url'),
    consumer_key=config.get('BYNDER_TOKENS', 'consumer_key'),
    consumer_secret=config.get('BYNDER_TOKENS', 'consumer_secret'),
    token=config.get('BYNDER_TOKENS', 'token'),
    token_secret=config.get('BYNDER_TOKENS', 'token_secret'))

# Get the asset bank client
asset_bank_client = bynder_client.asset_bank_client

# Get the collections client
collection_client = bynder_client.collection_client

# Get brands
# brands = asset_bank_client.brands()
# print(brands)

# Get tags
# tags = asset_bank_client.tags()
Пример #5
0
def byn_conn():
    bynder_client = BynderClient(
            domain='xx.xxxx.com',
            permanent_token='a35e984ead758e959e43f994d55cf8da4fcc928ff81edc9dda740f728d377761'
            )
    return bynder_client.asset_bank_client
Пример #6
0
import time
import configparser
import webbrowser
from bynder_sdk import BynderClient

# Get your tokens from .ini file
config = configparser.ConfigParser()
config.read('settings.ini')

HAS_TOKENS = False

# Create the BynderClient with your tokens
bynder_client = BynderClient(base_url=config.get('api', 'url'),
                             consumer_key=config.get('oauth', 'consumer_key'),
                             consumer_secret=config.get(
                                 'oauth', 'consumer_secret'),
                             token=config.get('oauth', 'token'),
                             token_secret=config.get('oauth', 'token_secret'))

# Generate tokens if you don't have them
if not HAS_TOKENS:
    # Generate request token
    bynder_client.request_token()

    # Get the authorise url
    authorise_url = bynder_client.authorise_url()
    print(authorise_url)
    webbrowser.open_new_tab(authorise_url)

    # Sleep for a while to give you time to login using the authorise url
    time.sleep(20)
Пример #7
0
import pprint

from bynder_sdk import BynderClient

pp = pprint.PrettyPrinter()

# When using Permanent Tokens

bynder_client = BynderClient(domain='portal.getbynder.com', permanent_token='')

# When using OAuth2

token = None
""" If we already have a token, it can be passed to the BynderClient
initialization.

    token = {
        'access_token': '...',
        'expires_at': 123456789,
        'expires_in': 3599,
        'id_token': '...',
        'refresh_token': '...',
        'scope': ['offline'],
        'token_type': 'bearer'
    }
"""


def token_saver(token):
    """ This function will be called by oauthlib-requests when a new
    token is retrieved, either after the initial login or refreshing an