def setUp(self):
        """
        Setup GAE testbed.
        """
        self.testbed = testbed.Testbed()
        self.testbed.activate()
        self.testbed.init_memcache_stub()
        self.testbed.init_datastore_v3_stub()
        self.testbed.init_urlfetch_stub()

        linker.app.config['TESTING'] = True
        self.app = linker.app.test_client()
        self.provider_configs = {
            'qbo':
            ProviderConfig(id="qbo",
                           provider="qbo",
                           app_family="local_host_family",
                           client_id="coopers_pale_ale",
                           client_secret="ninja_300").put(),
            'xerov2':
            ProviderConfig(id='xerov2',
                           provider="xerov2",
                           app_family="local_host_family",
                           client_id="test",
                           client_secret="fyre",
                           additional_auth_attributes=json.dumps(
                               {'application_type': 'public'})).put(),
            'zuora':
            ProviderConfig(id='zuora',
                           provider='zuora',
                           app_family='local_host_family').put()
        }
 def setUp(self):
     """
     Setup GAE testbed.
     """
     self.testbed = testbed.Testbed()
     self.testbed.activate()
     self.testbed.init_memcache_stub()
     self.testbed.init_datastore_v3_stub()
     self.testbed.init_urlfetch_stub()
     self.test_provider_config = ProviderConfig(
         id="qbo",
         provider="qbo",
         app_family="local_host_family",
         client_id="coopers_pale_ale",
         client_secret="ninja_300").put()
Exemplo n.º 3
0
def connect(provider, org_uid):
    """
    The first endpoint to be invoked by a client wishing to connect a new data source. Redirects the client to the data
    provider authorisation and sets relevant org statuses. The client can pass in a redirect URL to which the user
    should be redirected to after the second step of the auth flow (this url is stored in datastore and used in the
    second step, ie. oauth function).

    Args:
        provider(str): the data provider to which org_uid should be connected to
        org_uid(str): org/connection identifier

    Returns:
        (str, int): redirect to data provider
    """
    logging.info("initiating connect for {} (provider {})".format(
        org_uid, provider))

    if provider in API_PROVIDERS:
        app_family = request.args.get('app_family')
        if not app_family:
            return 'No app family specified', 422

        provider_config = ProviderConfig.find(provider, app_family)
        if not provider_config:
            return 'No configuration found for provider {} and app family {}'.format(
                provider, app_family), 422

        session = client_factory.get_authorization_session(
            provider, org_uid, provider_config,
            request.args.get('redirect_url'))

        if request.data:
            data = json.loads(request.data)
            username = data.get('username')
            password = data.get('password')
            # No redirect to login page needed if username and password are supplied in body
            return basic_auth(provider, org_uid, username, password)
        else:
            return redirect(session.get_authorization_url())

    if provider in MANUAL_PROVIDERS:
        create_manual_provider_org(org_uid, provider)
        return '', 204

    logging.info("invalid provider '{}' for org '{}'".format(
        provider, org_uid))
    return '', 404
Exemplo n.º 4
0
 def setUp(self):
     """
     Setup GAE testbed.
     """
     self.testbed = testbed.Testbed()
     self.testbed.activate()
     self.testbed.init_memcache_stub()
     self.testbed.init_datastore_v3_stub()
     self.testbed.init_urlfetch_stub()
     self.test_provider_config = ProviderConfig(
             id='xerov2',
             provider="xerov2",
             app_family="local_host_family",
             client_id="test",
             client_secret="fyre",
             additional_auth_attributes=json.dumps({'application_type': 'public'})
         ).put()
     adapter.app.config['TESTING'] = True
     self.app = adapter.app.test_client()
    def setUp(self):
        """
        Setup GAE testbed.
        """
        self.testbed = testbed.Testbed()
        self.testbed.activate()
        self.testbed.init_memcache_stub()
        self.testbed.init_datastore_v3_stub()
        self.testbed.init_urlfetch_stub()

        root_path = os.path.dirname(os.path.dirname(os.path.dirname(__file__)))
        self.testbed.init_taskqueue_stub(root_path=root_path + '/..')
        self.taskqueue = self.testbed.get_stub(testbed.TASKQUEUE_SERVICE_NAME)
        self.provider_configs = {
            'qbo':
            ProviderConfig(id='qbo',
                           provider='qbo',
                           app_family='local_host_family',
                           client_id='coopers_pale_ale',
                           client_secret='ninja_300').put()
        }

        adapter.app.config['TESTING'] = True
        self.app = adapter.app.test_client()
Exemplo n.º 6
0
def warmup():

    # Load datastore with provider configs if running locally
    if not os.getenv('SERVER_SOFTWARE', '').startswith('Google App Engine/'):

        if not ProviderConfig.get_by_id('qbo'):
            logging.info('Creating provider config for qbo')

            ProviderConfig(
                id='qbo',
                provider='qbo',
                app_family='local_host_family',
                client_id=os.environ.get('QBO_CLIENT_ID'),
                client_secret=os.environ.get('QBO_CLIENT_SECRET')
            ).put()

        if not ProviderConfig.get_by_id('xerov2'):
            logging.info('Creating provider config for xero')
            ProviderConfig(
                id='xerov2',
                provider='xerov2',
                app_family='local_host_family',
                client_id=os.environ.get('XERO_CONSUMER_KEY'),
                client_secret=os.environ.get('XERO_CONSUMER_SECRET'),
                additional_auth_attributes=json.dumps({'application_type': 'public'})
            ).put()

        if not ProviderConfig.get_by_id('zuora'):
            logging.info('Creating provider config for zuora')
            ProviderConfig(
                id='zuora',
                provider='zuora',
                app_family='local_host_family',
            ).put()

        return '', 204