Commit 42ac3daf by Sheng

Updated test_handler.py

parent acc3b47e
import unittest
import sys
from handler import MixinHandler
......@@ -17,11 +18,26 @@ class RequestMock(object):
class TestMixinHandler(unittest.TestCase):
def test_get_real_client_addr(self):
def test_get_real_client_addr_without_nginx_config(self):
handler = MixinHandler()
handler.request = RequestMock()
self.assertIsNone(handler.get_real_client_addr())
def test_get_real_client_addr_with_correct_nginx_config(self):
handler = MixinHandler()
handler.request = RequestMock()
ip = '127.0.0.1'
handler.request.set_ip(ip)
handler.request.set_port('12345')
self.assertEqual(handler.get_real_client_addr(), (ip, 12345))
@unittest.skipIf(sys.version_info < (3,),
reason='assertLogs not supported in Python 2')
def test_get_real_client_addr_with_bad_nginx_config(self):
handler = MixinHandler()
handler.request = RequestMock()
ip = '127.0.0.1'
handler.request.set_ip(ip)
with self.assertLogs() as cm:
......@@ -32,6 +48,3 @@ class TestMixinHandler(unittest.TestCase):
with self.assertLogs() as cm:
handler.get_real_client_addr()
self.assertEqual(cm.output, ['WARNING:root:Bad nginx configuration.'])
handler.request.set_port('12345')
self.assertEqual(handler.get_real_client_addr(), (ip, 12345))
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment