# Path: yithlibraryserver/twitter/information.py
# def get_user_info(settings, user_id, oauth_token):
#     user_info_url = settings['twitter_user_info_url']
# 
#     params = (
#         ('oauth_token', oauth_token),
#         )
# 
#     auth = auth_header('GET', user_info_url, params, settings, oauth_token)
# 
#     response = requests.get(
#         user_info_url + '?' + url_encode({'user_id': user_id}),
#         headers={'Authorization': auth},
#         )
# 
#     if response.status_code != 200:
#         raise HTTPUnauthorized(response.text)
# 
#     return response.json()


import unittest
from mock import patch
from pyramid.httpexceptions import HTTPUnauthorized
from yithlibraryserver.twitter.information import get_user_info
# You should have received a copy of the GNU Affero General Public License
# along with Yith Library Server.  If not, see <http://www.gnu.org/licenses/>.





class InformationTests(unittest.TestCase):

    def test_get_user_info(self):
        settings = {
            'twitter_consumer_key': 'key',
            'twitter_consumer_secret': 'secret',
            'twitter_user_info_url': 'https://api.twitter.com/1/users/show.json'
            }

        with patch('requests.get') as fake:
            response = fake.return_value
            response.status_code = 200
            response.json = lambda: {'screen_name': 'John Doe'}

            info = get_user_info(settings, '1234', 'token')
            self.assertEqual(info, {'screen_name': 'John Doe'})

        with patch('requests.get') as fake:
            response = fake.return_value
            response.status_code = 400
            response.json = lambda: {'screen_name': 'John Doe'}

            self.assertRaises(HTTPUnauthorized,

# Path: yithlibraryserver/twitter/information.py
# def get_user_info(settings, user_id, oauth_token):
#     user_info_url = settings['twitter_user_info_url']
# 
#     params = (
#         ('oauth_token', oauth_token),
#         )
# 
#     auth = auth_header('GET', user_info_url, params, settings, oauth_token)
# 
#     response = requests.get(
#         user_info_url + '?' + url_encode({'user_id': user_id}),
#         headers={'Authorization': auth},
#         )
# 
#     if response.status_code != 200:
#         raise HTTPUnauthorized(response.text)
# 
#     return response.json()


# Path: yithlibraryserver/twitter/tests/test_information.py
import unittest
from mock import patch
from pyramid.httpexceptions import HTTPUnauthorized
from yithlibraryserver.twitter.information import get_user_info

# You should have received a copy of the GNU Affero General Public License
# along with Yith Library Server.  If not, see <http://www.gnu.org/licenses/>.





class InformationTests(unittest.TestCase):

    def test_get_user_info(self):
        settings = {
            'twitter_consumer_key': 'key',
            'twitter_consumer_secret': 'secret',
            'twitter_user_info_url': 'https://api.twitter.com/1/users/show.json'
            }

        with patch('requests.get') as fake:
            response = fake.return_value
            response.status_code = 200
            response.json = lambda: {'screen_name': 'John Doe'}

            info = get_user_info(settings, '1234', 'token')
            self.assertEqual(info, {'screen_name': 'John Doe'})

        with patch('requests.get') as fake:
            response = fake.return_value
            response.status_code = 400
            response.json = lambda: {'screen_name': 'John Doe'}

            self.assertRaises(HTTPUnauthorized,

                              get_user_info, settings, '1234', 'token')