Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
W
webssh
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
郑天保
webssh
Commits
42ac3daf
Commit
42ac3daf
authored
Apr 24, 2018
by
Sheng
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Updated test_handler.py
parent
acc3b47e
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
17 additions
and
4 deletions
+17
-4
test_handler.py
tests/test_handler.py
+17
-4
No files found.
tests/test_handler.py
View file @
42ac3daf
import
unittest
import
unittest
import
sys
from
handler
import
MixinHandler
from
handler
import
MixinHandler
...
@@ -17,11 +18,26 @@ class RequestMock(object):
...
@@ -17,11 +18,26 @@ class RequestMock(object):
class
TestMixinHandler
(
unittest
.
TestCase
):
class
TestMixinHandler
(
unittest
.
TestCase
):
def
test_get_real_client_addr
(
self
):
def
test_get_real_client_addr
_without_nginx_config
(
self
):
handler
=
MixinHandler
()
handler
=
MixinHandler
()
handler
.
request
=
RequestMock
()
handler
.
request
=
RequestMock
()
self
.
assertIsNone
(
handler
.
get_real_client_addr
())
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'
ip
=
'127.0.0.1'
handler
.
request
.
set_ip
(
ip
)
handler
.
request
.
set_ip
(
ip
)
with
self
.
assertLogs
()
as
cm
:
with
self
.
assertLogs
()
as
cm
:
...
@@ -32,6 +48,3 @@ class TestMixinHandler(unittest.TestCase):
...
@@ -32,6 +48,3 @@ class TestMixinHandler(unittest.TestCase):
with
self
.
assertLogs
()
as
cm
:
with
self
.
assertLogs
()
as
cm
:
handler
.
get_real_client_addr
()
handler
.
get_real_client_addr
()
self
.
assertEqual
(
cm
.
output
,
[
'WARNING:root:Bad nginx configuration.'
])
self
.
assertEqual
(
cm
.
output
,
[
'WARNING:root:Bad nginx configuration.'
])
handler
.
request
.
set_port
(
'12345'
)
self
.
assertEqual
(
handler
.
get_real_client_addr
(),
(
ip
,
12345
))
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment