-
Notifications
You must be signed in to change notification settings - Fork 273
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Set default attributes on WebRequest (#406)
- Loading branch information
1 parent
6a50939
commit eae1ff0
Showing
2 changed files
with
51 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import unittest | ||
|
||
from daphne.http_protocol import WebRequest | ||
|
||
|
||
class MockServer: | ||
""" | ||
Mock server object for testing. | ||
""" | ||
|
||
def protocol_connected(self, *args, **kwargs): | ||
pass | ||
|
||
|
||
class MockFactory: | ||
""" | ||
Mock factory object for testing. | ||
""" | ||
|
||
def __init__(self): | ||
self.server = MockServer() | ||
|
||
|
||
class MockChannel: | ||
""" | ||
Mock channel object for testing. | ||
""" | ||
|
||
def __init__(self): | ||
self.factory = MockFactory() | ||
self.transport = None | ||
|
||
def getPeer(self, *args, **kwargs): | ||
return "peer" | ||
|
||
def getHost(self, *args, **kwargs): | ||
return "host" | ||
|
||
|
||
class TestHTTPProtocol(unittest.TestCase): | ||
""" | ||
Tests the HTTP protocol classes. | ||
""" | ||
|
||
def test_web_request_initialisation(self): | ||
channel = MockChannel() | ||
request = WebRequest(channel) | ||
self.assertIsNone(request.client_addr) | ||
self.assertIsNone(request.server_addr) |