# Path: yithlibraryserver/testing.py
# MONGO_URI = 'mongodb://localhost:27017/test-yith-library'
# class FakeRequest(DummyRequest):
# class TestCase(unittest.TestCase):
#     def __init__(self, *args, **kwargs):
#     def setUp(self):
#     def tearDown(self):
#     def set_user_cookie(self, user_id):
#     def add_to_session(self, data):
#     def get_session(self, response):


import os
from mock import patch
from yithlibraryserver import testing
        res = self.testapp.get('/twitter/callback?oauth_token=123456789',
                               status=400)
        self.assertEqual(res.status, '400 Bad Request')
        res.mustcontain('Missing required oauth_verifier')

        good_url = '/twitter/callback?oauth_token=123456789&oauth_verifier=abc'
        res = self.testapp.get(good_url, status=400)
        self.assertEqual(res.status, '400 Bad Request')
        res.mustcontain('No oauth_token was found in the session')

        # bad request because oauth tokens are different
        with patch('requests.post') as fake:
            response = fake.return_value
            response.status_code = 200
            response.text = 'oauth_callback_confirmed=true&oauth_token=987654321'
            self.testapp.get('/twitter/login')

            res = self.testapp.get(good_url, status=401)
            self.assertEqual(res.status, '401 Unauthorized')
            res.mustcontain("OAuth tokens don't match")

        # good request, twitter is not happy with us
        with patch('requests.post') as fake:
            response = fake.return_value
            response.status_code = 200
            response.text = 'oauth_callback_confirmed=true&oauth_token=123456789'
            self.testapp.get('/twitter/login')

            response = fake.return_value
            response.status_code = 401

# Path: yithlibraryserver/testing.py
# MONGO_URI = 'mongodb://localhost:27017/test-yith-library'
# class FakeRequest(DummyRequest):
# class TestCase(unittest.TestCase):
#     def __init__(self, *args, **kwargs):
#     def setUp(self):
#     def tearDown(self):
#     def set_user_cookie(self, user_id):
#     def add_to_session(self, data):
#     def get_session(self, response):


# Path: yithlibraryserver/twitter/tests/test_views.py
import os
from mock import patch
from yithlibraryserver import testing

        res = self.testapp.get('/twitter/callback?oauth_token=123456789',
                               status=400)
        self.assertEqual(res.status, '400 Bad Request')
        res.mustcontain('Missing required oauth_verifier')

        good_url = '/twitter/callback?oauth_token=123456789&oauth_verifier=abc'
        res = self.testapp.get(good_url, status=400)
        self.assertEqual(res.status, '400 Bad Request')
        res.mustcontain('No oauth_token was found in the session')

        # bad request because oauth tokens are different
        with patch('requests.post') as fake:
            response = fake.return_value
            response.status_code = 200
            response.text = 'oauth_callback_confirmed=true&oauth_token=987654321'
            self.testapp.get('/twitter/login')

            res = self.testapp.get(good_url, status=401)
            self.assertEqual(res.status, '401 Unauthorized')
            res.mustcontain("OAuth tokens don't match")

        # good request, twitter is not happy with us
        with patch('requests.post') as fake:
            response = fake.return_value
            response.status_code = 200
            response.text = 'oauth_callback_confirmed=true&oauth_token=123456789'
            self.testapp.get('/twitter/login')

            response = fake.return_value
            response.status_code = 401

            response.text = 'Invalid token'