def test_get_profile_raises_error_on_unknown_user(self): client = GithubClient() error = github.UnknownObjectException('test error', None) with mock.patch.object(client.client, 'get_user', side_effect=error): with self.assertRaises(UnknownProfileError) as cm: client.get_profile('foobar') self.assertEqual(str(cm.exception), 'No such GitHub account: foobar')
def test_get_profile_raises_error_on_rate_limit(self): client = GithubClient() error = github.RateLimitExceededException(None, None) with ExitStack() as stack: context_managers = ( mock.patch.object(client.client, 'get_user'), mock.patch.object(client, '_get_user_data', return_value={}), mock.patch.object(client, '_get_repository_data', side_effect=error), ) for context_manager in context_managers: stack.enter_context(context_manager) with self.assertRaises(RateLimitError) as cm: client.get_profile('foobar') self.assertEqual(str(cm.exception), 'Exceeded GitHub rate limit')
def test_get_profile_raises_error_on_bad_credentials(self): client = GithubClient() error = github.BadCredentialsException(None, None) with ExitStack() as stack: context_managers = ( mock.patch.object(client.client, 'get_user', side_effect=error), mock.patch.object(client, '_get_user_data', return_value={}), mock.patch.object(client, '_get_repository_data', return_value={}), ) for context_manager in context_managers: stack.enter_context(context_manager) with self.assertRaises(InvalidCredentialsError) as cm: client.get_profile('foobar') self.assertEqual(str(cm.exception), 'Cannot authenticate with given credentials')
def test_get_profile_assembles_profile_data(self): client = GithubClient() with ExitStack() as stack: context_managers = ( mock.patch.object(client.client, 'get_user'), mock.patch.object(client, '_get_user_data', return_value={'user': '******'}), mock.patch.object(client, '_get_repository_data', return_value={'repo': 'data'}), ) for context_manager in context_managers: stack.enter_context(context_manager) data = client.get_profile('foobar') client._get_user_data.assert_called_once_with( client.client.get_user.return_value) client._get_repository_data.assert_called_once_with( client.client.get_user.return_value) self.assertEqual(data, {'user': '******', 'repo': 'data'})