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')
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)
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)
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')