Ejemplo n.º 1
0
    def test_get_account_fail_bad_code(self):
        with requests_mock.Mocker() as mock:
            def callback(request, context):
                self.assertIn('code=123', request.text)
                context.status_code = requests.codes.bad
                return {
                    'error': 'dummy error',
                    'error_description': 'dummy description'
                }

            mock.post(re.compile('//login\.live\.com\.*'), json=callback)
            client = get_sample_client()
            self.assertRaises(ValueError, accounts.get_personal_account, client, uri='http://foo/bar?code=123')
Ejemplo n.º 2
0
    def test_get_account_fail_bad_code(self):
        with requests_mock.Mocker() as mock:
            def callback(request, context):
                self.assertIn('code=123', request.text)
                context.status_code = requests.codes.bad
                return {
                    'error': 'dummy error',
                    'error_description': 'dummy description'
                }

            mock.post(re.compile('//login\.live\.com\.*'), json=callback)
            client = get_sample_client()
            self.assertRaises(ValueError, accounts.get_personal_account, client, uri='http://foo/bar?code=123')
Ejemplo n.º 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)
Ejemplo n.º 4
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)
Ejemplo n.º 5
0
 def test_parse_expire_time(self):
     expires_at = time.time() + 3600
     client = get_sample_client()
     account = accounts.PersonalAccount(client, PERSONAL_ACCOUNT_DATA, expires_at)
     self.assertEqual(expires_at, account.expires_at)
Ejemplo n.º 6
0
 def test_get_account_fail_no_code(self):
     client = get_sample_client()
     self.assertRaises(ValueError, accounts.get_personal_account, client, uri='http://foo/bar?error=123')
Ejemplo n.º 7
0
 def test_parse_expire_time(self):
     expires_at = 1234
     client = get_sample_client()
     account = accounts.PersonalAccount(client, PERSONAL_ACCOUNT_DATA, expires_at)
     self.assertEqual(expires_at, account.expires_at)
Ejemplo n.º 8
0
 def test_get_account_fail_no_code(self):
     client = get_sample_client()
     self.assertRaises(ValueError, accounts.get_personal_account, client, uri='http://foo/bar?error=123')