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
acc3b47e
Commit
acc3b47e
authored
Apr 24, 2018
by
Sheng
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added test_handler.py
parent
5dd08a72
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
37 additions
and
0 deletions
+37
-0
test_handler.py
tests/test_handler.py
+37
-0
No files found.
tests/test_handler.py
0 → 100644
View file @
acc3b47e
import
unittest
from
handler
import
MixinHandler
class
RequestMock
(
object
):
def
__init__
(
self
):
self
.
headers
=
{}
def
set_ip
(
self
,
ip
):
self
.
headers
[
'X-Real-Ip'
]
=
ip
def
set_port
(
self
,
port
):
self
.
headers
[
'X-Real-Port'
]
=
port
class
TestMixinHandler
(
unittest
.
TestCase
):
def
test_get_real_client_addr
(
self
):
handler
=
MixinHandler
()
handler
.
request
=
RequestMock
()
self
.
assertIsNone
(
handler
.
get_real_client_addr
())
ip
=
'127.0.0.1'
handler
.
request
.
set_ip
(
ip
)
with
self
.
assertLogs
()
as
cm
:
handler
.
get_real_client_addr
()
self
.
assertEqual
(
cm
.
output
,
[
'WARNING:root:Bad nginx configuration.'
])
handler
.
request
.
set_port
(
'12345x'
)
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
))
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