def testGetPayload_badscript(self): string_buffer = StringIO.StringIO(_BAD_SCRIPT) header = string_buffer.readline() command_sequence = client_replay.CommandSequence() command_sequence._parser = client_replay._Parser(string_buffer) payload_string = command_sequence._parser._GetPayloadString(header) self.assertEqual(payload_string, '{"param2": "))}\\})}/{)}({(})}"\n}\n')
def testHandleGetSessions(self): string_buffer = StringIO.StringIO(_MULTI_SESSION) command_sequence = client_replay.CommandSequence(string_buffer) first_command = command_sequence._parser.GetNext() command = command_sequence._HandleGetSessions(first_command) responses = command_sequence._last_response self.assertEqual(command.name, "GetSessions") self.assertEqual(command.GetPayloadPrimitive(), {}) self.assertEqual(command.session_id, _SESSION_ID) self.assertEqual(responses.name, "GetSessions") self.assertEqual(responses.GetPayloadPrimitive(), [{ "capabilities": { "param2": 42 }, "id": _SESSION_ID }, { "capabilities": { "param2": 42 }, "id": _SESSION_ID_ALT }]) self.assertEqual(responses.session_id, "") self.assertEqual(command_sequence._parser._saved_log_entry.name, "GetTitle")
def testGetPayload_simple(self): string_buffer = StringIO.StringIO(_RESPONSE_ONLY) header = string_buffer.readline() command_sequence = client_replay.CommandSequence() command_sequence._parser = client_replay._Parser(string_buffer) payload_string = command_sequence._parser._GetPayloadString(header) self.assertEqual(payload_string, '{"param2": 42\n}\n')
def testIngestRealResponseNone(self): real_resp = {'value': None} command_sequence = client_replay.CommandSequence() command_sequence._IngestRealResponse(real_resp) self.assertEqual(command_sequence._last_response, None)
def testGetPayload_script(self): string_buffer = StringIO.StringIO(_PAYLOAD_SCRIPT) header = string_buffer.readline() command_sequence = client_replay.CommandSequence() command_sequence._parser = client_replay._Parser(string_buffer) payload_string = command_sequence._parser._GetPayloadString(header) self.assertEqual(payload_string, '{"param2": "function(){func()}"\n}\n')
def testGetNextClientHeaderLine_readableTime(self): string_buffer = StringIO.StringIO(_PAYLOAD_READABLE_TIME) command_sequence = client_replay.CommandSequence() command_sequence._parser = client_replay._Parser(string_buffer) self.assertEquals(command_sequence._parser._GetNextClientHeaderLine(), ("[08-12-2019_15:45:34.824002][INFO]:" " [b15232d5497ec0d8300a5a1ea56f33ce] RESPONSE GetTitle {\n"))
def testGetNextClientHeaderLine(self): string_buffer = StringIO.StringIO(_PAYLOAD_SCRIPT) command_sequence = client_replay.CommandSequence() command_sequence._parser = client_replay._Parser(string_buffer) self.assertEquals(command_sequence._parser._GetNextClientHeaderLine(), ("[1531428670.535][INFO]: [b15232d5497ec0d8300a5a1ea56f33ce]" " RESPONSE GetTitle {\n"))
def testParserGetNext(self): string_buffer = StringIO.StringIO(_WITH_PARAMS) command_sequence = client_replay.CommandSequence() command_sequence._parser = client_replay._Parser(string_buffer) command = command_sequence._parser.GetNext() self.assertEqual(command.name, "GetTitle") self.assertEqual(command.GetPayloadPrimitive(), {"param1": 7}) self.assertEqual(command.session_id, _SESSION_ID)
def testIngestLoggedResponse(self): string_buffer = StringIO.StringIO(_RESPONSE_ONLY) command_sequence = client_replay.CommandSequence() command_sequence._parser = client_replay._Parser(string_buffer) response = command_sequence._parser.GetNext() self.assertEqual(response.name, "GetTitle") self.assertEqual(response.GetPayloadPrimitive(), {"param2": 42}) self.assertEqual(response.session_id, _SESSION_ID)
def testIngestRealResponseInt(self): real_resp = {'value': 1} command_sequence = client_replay.CommandSequence() command_sequence._IngestRealResponse(real_resp) #last response is not changed by IngestRealResponse, #but we want to verify that int response content does not #cause error. self.assertEqual(command_sequence._last_response, None)
def testNextCommandEmptyParams(self): string_buffer = StringIO.StringIO(_NO_PARAMS) command_sequence = client_replay.CommandSequence() command_sequence._parser = client_replay._Parser(string_buffer) command = command_sequence.NextCommand(None) response = command_sequence._last_response self.assertEqual(command.name, "GetTitle") self.assertEqual(command.GetPayloadPrimitive(), {"sessionId": _SESSION_ID}) self.assertEqual(command.session_id, _SESSION_ID) self.assertEqual(response.name, "GetTitle") self.assertEqual(response.GetPayloadPrimitive(), None) self.assertEqual(response.session_id, _SESSION_ID)
def testIngestRealResponseInitSession(self): real_resp = {u'value': { u'sessionId': u'b15232d5497ec0d8300a5a1ea56f33ce', u'capabilities': { u'browserVersion': u'76.0.3809.100', u'browserName': u'chrome', } }} command_sequence = client_replay.CommandSequence() command_sequence._staged_logged_session_id = _SESSION_ID_ALT command_sequence._IngestRealResponse(real_resp) self.assertEqual( command_sequence._id_map[_SESSION_ID_ALT], _SESSION_ID) self.assertEqual(command_sequence._staged_logged_session_id, None)
def testParseResponse_false(self): string_buffer = StringIO.StringIO(_COMMAND_ONLY) command_sequence = client_replay.CommandSequence() command_sequence._parser = client_replay._Parser(string_buffer) self.assertFalse(command_sequence._parser.GetNext().IsResponse())
def testParseResponse_true(self): string_buffer = StringIO.StringIO(_RESPONSE_ONLY) command_sequence = client_replay.CommandSequence() command_sequence._parser = client_replay._Parser(string_buffer) self.assertTrue(command_sequence._parser.GetNext().IsResponse())
def testParseCommand_true(self): string_buffer = StringIO.StringIO(_COMMAND_ONLY) command_sequence = client_replay.CommandSequence() command_sequence._parser = client_replay._Parser(string_buffer) self.assertTrue(command_sequence._parser.GetNext().IsCommand())
def testParseCommand_false(self): string_buffer = io.StringIO(_RESPONSE_ONLY) command_sequence = client_replay.CommandSequence() command_sequence._parser = client_replay._Parser(string_buffer) self.assertFalse(command_sequence._parser.GetNext().IsCommand())