# Path: pushmanager/testing/mocksettings.py



import mock
import testify as T
import tornado.httpserver
from pushmanager.core.requesthandler import RequestHandler
from pushmanager.core.requesthandler import get_base_url
from pushmanager.core.settings import Settings
from pushmanager.testing.mocksettings import MockedSettings


class RequestHandlerTest(T.TestCase):

    def test_get_api_page(self):
        MockedSettings['api_app'] = {'port': 8043, 'servername': 'push.test.com'}
        with mock.patch.dict(Settings, MockedSettings):
            T.assert_equal(
                RequestHandler.get_api_page("pushes"),
                "http://push.test.com:8043/api/pushes"
            )

    def test_get_base_url_empty_headers(self):
        MockedSettings['main_app'] = {'port': 1111, 'servername': 'example.com'}
        request = tornado.httpserver.HTTPRequest('GET', '')
        request.protocol = 'https'

        with mock.patch.dict(Settings, MockedSettings):
            T.assert_equal(
                get_base_url(request),
                'https://example.com:1111'
            )

            Settings['main_app']['port'] = 443
            T.assert_equal(
                get_base_url(request),
                'https://example.com'
            )

    def test_get_base_url_proto_header(self):

# Path: pushmanager/testing/mocksettings.py



# Path: pushmanager/tests/test_core_requesthandler.py
import mock
import testify as T
import tornado.httpserver
from pushmanager.core.requesthandler import RequestHandler
from pushmanager.core.requesthandler import get_base_url
from pushmanager.core.settings import Settings
from pushmanager.testing.mocksettings import MockedSettings



class RequestHandlerTest(T.TestCase):

    def test_get_api_page(self):
        MockedSettings['api_app'] = {'port': 8043, 'servername': 'push.test.com'}
        with mock.patch.dict(Settings, MockedSettings):
            T.assert_equal(
                RequestHandler.get_api_page("pushes"),
                "http://push.test.com:8043/api/pushes"
            )

    def test_get_base_url_empty_headers(self):
        MockedSettings['main_app'] = {'port': 1111, 'servername': 'example.com'}
        request = tornado.httpserver.HTTPRequest('GET', '')
        request.protocol = 'https'

        with mock.patch.dict(Settings, MockedSettings):
            T.assert_equal(
                get_base_url(request),
                'https://example.com:1111'
            )

            Settings['main_app']['port'] = 443
            T.assert_equal(
                get_base_url(request),
                'https://example.com'
            )

    def test_get_base_url_proto_header(self):

        MockedSettings['main_app'] = {'port': 1111, 'servername': 'example.com'}