MCPcopy Index your code
hub / github.com/PyGithub/PyGithub / testRecordAndReplay

Function testRecordAndReplay

tests/Connection.py:79–116  ·  view source on GitHub ↗
(replaying_connection_class, protocol, response_body, expected_recording)

Source from the content-addressed store, hash-verified

77)
78@responses.activate
79def testRecordAndReplay(replaying_connection_class, protocol, response_body, expected_recording):
80 file = StringIO()
81 host = "api.github.com"
82 verb = "GET"
83 url = "/user"
84 headers = {"Authorization": "Basic p4ssw0rd", "User-Agent": "PyGithub/Python"}
85
86 response = Mock()
87 response.status = 200
88 response.getheaders.return_value = {}
89 response.read.return_value = response_body
90
91 connection = Mock()
92 connection.getresponse.return_value = response
93
94 # write mock response to buffer
95 rdf = Framework.ReplayDataFile("string", file)
96 RecordingMockConnection.setOpenFile(lambda mode: rdf)
97 recording_connection = RecordingMockConnection(protocol, host, None, lambda *args, **kwds: connection)
98 recording_connection.request(verb, url, None, headers)
99 recording_connection.getresponse()
100 recording_connection.close()
101
102 # validate contents of buffer
103 file_value_lines = file.getvalue().split("\n")
104 expected_recording_lines = (protocol + expected_recording).split("\n")
105 assert file_value_lines[:5] == expected_recording_lines[:5]
106 assert eval(file_value_lines[5]) == eval(expected_recording_lines[5])
107 # dict literal, so keys not in guaranteed order
108 assert file_value_lines[6:] == expected_recording_lines[6:]
109
110 # rewind buffer and attempt to replay response from it
111 file.seek(0)
112 rdf = Framework.ReplayDataFile("string", file)
113 replaying_connection_class.setOpenFile(lambda mode: rdf)
114 replaying_connection = replaying_connection_class(host=host, port=None)
115 replaying_connection.request(verb, url, None, headers)
116 replaying_connection.getresponse()

Callers

nothing calls this directly

Calls 5

setOpenFileMethod · 0.80
requestMethod · 0.45
getresponseMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…