Example #1
0
 def test_socket_as_context_manager(self):
     addr = ("localhost", 80)
     Mocket.register(MocketEntry(addr, ["Show me.\r\n"]))
     with Mocketizer():
         with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as _so:
             _so.connect(addr)
             _so.sendall(encode_to_bytes("Whatever..."))
             data = _so.recv(4096)
             self.assertEqual(data, encode_to_bytes("Show me.\r\n"))
Example #2
0
 def test_makefile(self):
     addr = ("localhost", 80)
     Mocket.register(MocketEntry(addr, ["Show me.\r\n"]))
     with Mocketizer():
         _so = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
         _so.connect(addr)
         fp = _so.makefile("rb")
         _so.sendall(encode_to_bytes("...\r\n"))
         self.assertEqual(fp.read().strip(), encode_to_bytes("Show me."))
         self.assertEqual(len(Mocket.request_list()), 1)
Example #3
0
 def __getattr__(self, name):
     if name == "last_request":
         last_request = getattr(Mocket, "last_request")()
         last_request.body = encode_to_bytes(last_request.body)
         return last_request
     elif name == "latest_requests":
         return getattr(Mocket, "_requests")
     else:
         return getattr(Entry, name)
Example #4
0
 def __getattr__(self, name):
     if name == 'last_request':
         last_request = getattr(Mocket, 'last_request')()
         last_request.body = encode_to_bytes(last_request.body)
         return last_request
     elif name == 'latest_requests':
         return getattr(Mocket, '_requests')
     else:
         return getattr(Entry, name)
Example #5
0
 def __getattr__(self, name):
     if name == 'last_request':
         last_request = getattr(Mocket, 'last_request')()
         last_request.body = encode_to_bytes(last_request.body)
         return last_request
     elif name == 'latest_requests':
         return getattr(Mocket, '_requests')
     else:
         return getattr(Entry, name)
Example #6
0
 def test_empty_getresponse(self):
     entry = MocketEntry(('localhost', 8080), [])
     self.assertEqual(entry.get_response(), encode_to_bytes(''))
Example #7
0
 def test_getresponse(self):
     entry = MocketEntry(('localhost', 8080), ['Show me.\r\n'])
     self.assertEqual(entry.get_response(), encode_to_bytes('Show me.\r\n'))
Example #8
0
 def test_getresponse(self):
     entry = MocketEntry(("localhost", 8080), ["Show me.\r\n"])
     self.assertEqual(entry.get_response(), encode_to_bytes("Show me.\r\n"))
Example #9
0
 def test_empty_getresponse(self):
     entry = MocketEntry(('localhost', 8080), [])
     self.assertEqual(entry.get_response(), encode_to_bytes(''))
Example #10
0
 def test_getresponse(self):
     entry = MocketEntry(('localhost', 8080), ['Show me.\r\n'])
     self.assertEqual(entry.get_response(), encode_to_bytes('Show me.\r\n'))