Example #1
0
    def test_init(self):
        session_manager = Oauth1SessionManager(
            consumer_key='key',
            consumer_secret='secret',
            access_token='token',
            access_token_secret='tokensecret',
        )

        self.assertEquals(session_manager.consumer_key, 'key')
        self.assertEquals(session_manager.consumer_secret, 'secret')
        self.assertEquals(session_manager.access_token, 'token')
        self.assertEquals(session_manager.access_token_secret, 'tokensecret')
    def setUp(self):
        self.session_manager = Oauth1SessionManager(
            sandbox=True,
            consumer_key=os.environ.get('CONSUMER_KEY'),
            consumer_secret=os.environ.get('CONSUMER_SECRET'),
            access_token=os.environ.get('ACCESS_TOKEN'),
            access_token_secret=os.environ.get('ACCESS_TOKEN_SECRET'),
        )

        self.qb_client = QuickBooks(session_manager=self.session_manager,
                                    sandbox=True,
                                    company_id=os.environ.get('COMPANY_ID'))
Example #3
0
    def test_start_session(self):
        session_manager = Oauth1SessionManager(
            consumer_key='key',
            consumer_secret='secret',
            access_token='token',
            access_token_secret='tokensecret',
            sandbox=True)

        session = session_manager.start_session()

        self.assertEqual(session.access_token, 'token')
        self.assertEqual(session.access_token_secret, 'tokensecret')
        self.assertEqual(session_manager.started, True)
Example #4
0
    def setUp(self):
        self.session_manager = Oauth1SessionManager(
            sandbox=True,
            consumer_key="update_consumer_key",
            consumer_secret="update_consumer_secret",
            access_token="update_access_token",
            access_token_secret="update_access_token_secret",
        )

        self.qb_client = client.QuickBooks(
            session_manager=self.session_manager,
            sandbox=True,
            company_id="COMPANY_ID")
Example #5
0
    def setUp(self):
        self.session_manager = Oauth1SessionManager(
            sandbox=True,
            consumer_key=os.environ.get('CONSUMER_KEY'),
            consumer_secret=os.environ.get('CONSUMER_SECRET'),
            access_token=os.environ.get('ACCESS_TOKEN'),
            access_token_secret=os.environ.get('ACCESS_TOKEN_SECRET'),
        )

        self.qb_client = QuickBooks(session_manager=self.session_manager,
                                    sandbox=True,
                                    company_id=os.environ.get('COMPANY_ID'))

        self.name = "TaxCode {0}".format(datetime.now().strftime('%d%H%M'))
Example #6
0
    def build_server(cls, consumer_key, consumer_secret, sandbox, port, oauth_version):
        callback_url = 'http://localhost:{0}'.format(port)
        if oauth_version == 1:
            client = Oauth1SessionManager(
                sandbox=sandbox,
                consumer_key=consumer_key,
                consumer_secret=consumer_secret,
            )

            qb_data = {
                'authorize_url': client.get_authorize_url(callback_url),
                'request_token': client.request_token,
                'request_token_secret': client.request_token_secret,
                'consumer_key': consumer_key,
                'consumer_secret': consumer_secret,
                'sandbox': sandbox,
                'oauth_version': oauth_version,
            }

        elif oauth_version == 2:
            client = Oauth2SessionManager(
                sandbox=sandbox,
                client_id=consumer_key,
                client_secret=consumer_secret,
                base_url='http://localhost:{0}'.format(port),
            )

            qb_data = {
                'authorize_url': client.get_authorize_url(callback_url),
                'access_token': client.access_token,
                'refresh_token': client.refresh_token,
                'consumer_key': consumer_key,
                'consumer_secret': consumer_secret,
                'token_type': client.token_type,
                'expires_in': client.expires_in,
                'x_refresh_token_expires_in': client.x_refresh_token_expires_in,
                'sandbox': sandbox,
                'oauth_version': oauth_version,
                'callback_url': 'http://localhost:{0}'.format(port),
                'base_url': 'http://localhost:{0}'.format(port),
            }

        else:
            raise Exception('Invalid OAuth version number. Version number must be 1 or 2.')

        instance = cls(('', port), QuickBooksAuthHandler)
        instance.qb_data = qb_data

        return instance
Example #7
0
    def test_start_session_no_access_token(self):
        session_manager = Oauth1SessionManager(
            consumer_key='key',
            consumer_secret='secret',
            access_token='',
            access_token_secret='tokensecret',
        )

        try:
            with self.assertRaises(QuickbooksException) as error:
                session_manager.start_session()

            self.assertEqual(error.exception.message,
                             "Access Token missing. Cannot create session.")
        except:
            self.failUnlessRaises(QuickbooksException, session_manager.start_session)

        self.assertEqual(session_manager.started, False)
Example #8
0
    def get_oauth_1(self):
        self._set_headers()
        qb_data = self.server.qb_data

        GET = parse_qs(urlparse(self.path).query)

        oauth_verifier = GET.get('oauth_verifier')
        realm_id = GET.get('realmId')

        if type(realm_id) is list and len(realm_id) == 1:
            realm_id = realm_id[0]

        if oauth_verifier and realm_id:
            client = Oauth1SessionManager(
                sandbox=qb_data['sandbox'],
                consumer_key=qb_data['consumer_key'],
                consumer_secret=qb_data['consumer_secret']
            )

            client.authorize_url = qb_data['authorize_url']
            client.request_token = qb_data['request_token']
            client.request_token_secret = qb_data['request_token_secret']
            client.get_access_tokens(oauth_verifier)

            self.wfile.write(
                bytes('<h1>QuickBooks auth handled with success!</h1>',
                      'UTF-8'))
            self.wfile.write(
                bytes('<p><b>Sandbox:</b> {0}</p>'.format(qb_data['sandbox']),
                      'UTF-8'))
            self.wfile.write(
                bytes('<p><b>Realm Id:</b> {0}</p>'.format(realm_id), 'UTF-8'))

            self.wfile.write(
                bytes('<p><b>Access Token:</b> {0}</p>'.format(
                    client.access_token), 'UTF-8'))
            self.wfile.write(
                bytes('<p><b>Access Token Secret:</b> {0}</p>'.format(
                    client.access_token_secret), 'UTF-8'))
        else:
            self.wfile.write(
                bytes('<h1>QuickBooks auth failed, try again.</h1>', 'UTF-8'))
    def setUp(self):
        self.session_manager = Oauth1SessionManager(
            sandbox=True,
            consumer_key=os.environ.get('CONSUMER_KEY'),
            consumer_secret=os.environ.get('CONSUMER_SECRET'),
            access_token=os.environ.get('ACCESS_TOKEN'),
            access_token_secret=os.environ.get('ACCESS_TOKEN_SECRET'),
        )

        self.qb_client = QuickBooks(
            session_manager=self.session_manager,
            sandbox=True,
            company_id=os.environ.get('COMPANY_ID')
        )

        self.title = "Mr"
        self.given_name = "James"
        self.middle_name = "B"
        self.family_name = "King"
        self.suffix = "Jr"
        self.fully_qualified_name = datetime.now().strftime('%d%H%M%S')
        self.company_name = datetime.now().strftime('%d%H%M%S')
        self.display_name = datetime.now().strftime('%d%H%M%S')
Example #10
0
    def setUp(self):
        self.session_manager = Oauth1SessionManager(
            sandbox=True,
            consumer_key=os.environ.get('CONSUMER_KEY'),
            consumer_secret=os.environ.get('CONSUMER_SECRET'),
            access_token=os.environ.get('ACCESS_TOKEN'),
            access_token_secret=os.environ.get('ACCESS_TOKEN_SECRET'),
        )

        self.qb_client = QuickBooks(
            session_manager=self.session_manager,
            sandbox=True,
            company_id=os.environ.get('COMPANY_ID')
        )

        self.account_number = datetime.now().strftime('%d%H%M')
        self.name = "Test Item {0}".format(self.account_number)

        self.income_account = Account.where(
            "AccountType = 'Income' and AccountSubType = 'SalesOfProductIncome'", max_results=1, qb=self.qb_client)[0]

        self.expense_account = Account.where(
            "AccountSubType = 'SuppliesMaterialsCogs'", max_results=1, qb=self.qb_client)[0]
        self.asset_account = Account.where("AccountSubType = 'Inventory'", max_results=1, qb=self.qb_client)[0]