This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
import http.client
|
||||
import os
|
||||
import threading
|
||||
import unittest
|
||||
from unittest.mock import patch
|
||||
|
||||
from server import ProxyStaticHandler
|
||||
|
||||
|
||||
class FakeUpstream:
|
||||
def __init__(self, *args, **kwargs):
|
||||
self.response = type('Response', (), {
|
||||
'status': 200,
|
||||
'reason': 'OK',
|
||||
'getheaders': lambda self: [('Content-Type', 'application/json'), ('Set-Cookie', 'session=abc; Path=/')],
|
||||
'read': lambda self: b'{"status":"ok"}',
|
||||
})()
|
||||
def request(self, method, path, body=None, headers=None):
|
||||
self.method, self.path, self.body, self.headers = method, path, body, headers
|
||||
def getresponse(self):
|
||||
return self.response
|
||||
def close(self):
|
||||
pass
|
||||
|
||||
|
||||
class ProxyServerTests(unittest.TestCase):
|
||||
def test_api_requests_are_forwarded_to_internal_upstream(self):
|
||||
server = ProxyStaticHandler
|
||||
self.assertTrue(hasattr(server, 'proxy_api'))
|
||||
with patch('server.http.client.HTTPConnection', FakeUpstream):
|
||||
self.assertTrue(server.proxy_api)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user