36 lines
1.1 KiB
Python
36 lines
1.1 KiB
Python
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()
|