コード例 #1
0
ファイル: pref_main.py プロジェクト: intermezzo-fr/onedrive-d
def add_personal_account():
    puts(colored.green('Link with an OneDrive Personal account:'))
    puts(
        colored.cyan(
            'Please use your browser to visit the following URL, sign in with your OneDrive account and '
            'authorize onedrive-d, then copy the callback URL back here. The callback URL is the URL at '
            'which the authorization page goes blank and usually starts with '
            + clients.PersonalClient.DEFAULT_REDIRECT_URI + '.'))
    puts()
    puts(colored.yellow('Please visit this URL: '))
    puts(personal_client.get_auth_uri())
    while True:
        try:
            url = prompt.query(
                str(
                    colored.yellow(
                        '\nPlease paste the callback URL or hit [Ctrl+C] to abort:'
                    )))
            account = accounts.get_personal_account(personal_client, uri=url)
            profile = account.profile
            account_store.add_account(account)
            puts(
                colored.green('Success: added account {} ({}).'.format(
                    profile.user_id, profile.name)))
            return
        except KeyboardInterrupt:
            puts(colored.red('Aborted.'))
            return
        except Exception as e:
            puts(colored.red('Error: ' + str(e)))
コード例 #2
0
    def test_get_account_success_by_code(self, args=DEFAULT_CALL_ARGS):
        """
        Test get_personal_account() by passing it a code.
        :param dict[str, str] args: Arguments to pass to get_personal_account().
        """
        with requests_mock.Mocker() as mock:
            def callback(request, context):
                self.assertIn('code=123', request.text)
                context.status_code = requests.codes.ok
                return PERSONAL_ACCOUNT_DATA

            mock.post(re.compile('//login\.live\.com\.*'), json=callback)
            client = get_sample_client()
            account = accounts.get_personal_account(client, **args)
            self.assert_account(account)
コード例 #3
0
    def test_get_account_success_by_code(self, args=DEFAULT_CALL_ARGS):
        """
        Test get_personal_account() by passing it a code.
        :param dict[str, str] args: Arguments to pass to get_personal_account().
        """
        with requests_mock.Mocker() as mock:
            def callback(request, context):
                self.assertIn('code=123', request.text)
                context.status_code = requests.codes.ok
                return PERSONAL_ACCOUNT_DATA

            mock.post(re.compile('//login\.live\.com\.*'), json=callback)
            client = get_sample_client()
            account = accounts.get_personal_account(client, **args)
            self.assert_account(account)
コード例 #4
0
ファイル: pref_main.py プロジェクト: remyj38/onedrive-d
def add_personal_account():
    puts(colored.green('Link with an OneDrive Personal account:'))
    puts(colored.cyan(
        'Please use your browser to visit the following URL, sign in with your OneDrive account and '
        'authorize onedrive-d, then copy the callback URL back here. The callback URL is the URL at '
        'which the authorization page goes blank and usually starts with ' +
        clients.PersonalClient.DEFAULT_REDIRECT_URI + '.'))
    puts()
    puts(colored.yellow('Please visit this URL: '))
    puts(personal_client.get_auth_uri())
    while True:
        try:
            url = prompt.query(str(colored.yellow('\nPlease paste the callback URL or hit [Ctrl+C] to abort:')))
            account = accounts.get_personal_account(personal_client, uri=url)
            profile = account.profile
            account_store.add_account(account)
            puts(colored.green('Success: added account {} ({}).'.format(profile.user_id, profile.name)))
            return
        except KeyboardInterrupt:
            puts(colored.red('Aborted.'))
            return
        except Exception as e:
            puts(colored.red('Error: ' + str(e)))