def DNP3results(request):
	#if 'msg' in request.GET and request.GET['msg']: #consider error-checking later
	userData = request.GET['inputByText']
	userFileContents = request.GET['fileContents']
	printBool = request.GET['printPass']
	
	messages = parseData(userData, userFileContents) #passing input into parseData to strip out the messages (and get rid of extra data)
	if messages != "": #if it's not empty #example message = "05 64 05 C0 01 00 0A 00"
		decodedReports = []
		reportBuilder = DNPReportBuilder()
		
		messages2 = [] #changing 3-part tuple -> (message, crc, request bool STRING)
		for msg in messages: #Decoding each message and getting Report objects back
			messages2.append( msg[0] )
			
		decodedReports = reportBuilder.translate(messages2, True)
		#Convert Report list to HTML collapsible list
		
		if printBool == "false":
			outty = makeCollapsibleList(decodedReports)
		else:
			outty = makePrintableList(decodedReports)
	else:
		outty = 'Failed to parse out any messages'
		
	#outty = []
	#for i in decodedReports:
		#outty.append(str(i))
	return render(request, 'DNP3results.html', {'decodedStuff':outty}) #not using originalMessage for now
	
 def test_pasted_tx_message_with_message_bytes_and_parens_around_crc(self):
     'Verifies the result for a pasted message with parenthesis around the crc bytes'
     input_data = '05 64 05 C0 01 00 0A 00 (E0 8C)'
     output_data = input_data.replace(' ', '')
     paren_location = output_data.find('(')
     expected_output = [(output_data[:paren_location], "True")]
     exit_value = parseInput.parseData(input_data, '')
     self.assertEqual(exit_value, expected_output)
 def test_pasted_tx_message_with_message_bytes_and_parens_around_crc(self):
     'Verifies the result for a pasted message with parenthesis around the crc bytes'
     input_data = '05 64 05 C0 01 00 0A 00 (E0 8C)'
     output_data = input_data.replace(' ', '')
     paren_location = output_data.find('(')
     expected_output = [(output_data[:paren_location], "True")]
     exit_value = parseInput.parseData(input_data, '')
     self.assertEqual(exit_value, expected_output)
 def test_ParseLogFile(self):
     logFile = "----------- ** Capture Session Started 12//09//2011 14:10:21 ** ------------\n" \
         + "(Port 23): No Response for Control\n" \
         + "(Port 23): Response Timeout for TB#1 Reg B CL-6, waited: 1000\n" \
         + "(Port 23):  \n" \
         + "(Port 23): DNP TX Analog Command - VOLTREDUCTION PERCENT @TB#1 Reg A CL-6 Point #16: Value -32768\n" \
         + "(Port 23)TX[25]: 05 64 12 C4 02 00 64 00 (FF B7)-CRC\n" \
         + "F8 C8 05 29 02 28 01 00 10 00 00 80 00 (E8 57)-CRC\n"
     parsedData = parseInput.parseData(logFile, "")
     result = [("056412C402006400","FFB7","True"),("F8C80529022801001000008000","E857","True")]
     assert result == parsedData
 def test_file_message(self):
     'Verifies the result for a series of messages from a file'
     input_data = (
         ''
         '----------- ** Capture Session Started 02/11/2013 13:20:00 ** ------------\n'
         '(Port 1): Response Timeout for Device 2, waited: 1000\n'
         '(Port 1): Consecutive Failures from Device Device 2: 22\n'
         '(Port 1): Setting All Points for Device Device 2: Offline\n'
         '(Port 1):  \n'
         '(Port 1): Reset Remote Link - Device 2 Address 1 \n'
         '(Port 1)TX[10]: 05 64 05 C0 01 00 0A 00 (E0 8C)-CRC\n'
         '(Port 1): Response Timeout for Device 2, waited: 1000\n'
         '(Port 1): Consecutive Failures from Device Device 2: 23\n'
         '(Port 1): Setting All Points for Device Device 2: Offline\n'
         '(Port 1):  \n'
         '(Port 1): Reset Remote Link - Device 2 Address 1 \n'
         '(Port 1)TX[10]: 05 64 05 C0 01 00 0A 00 (E0 8C)-CRC\n'
         '(Port 1): Response Timeout for Device 2, waited: 1000\n'
         '(Port 1): Consecutive Failures from Device Device 2: 24\n'
         '(Port 1): Setting All Points for Device Device 2: Offline\n'
         '(Port 1):  \n'
         '(Port 1): Reset Remote Link - Device 2 Address 1 \n'
         '(Port 1)TX[10]: 05 64 05 C0 01 00 0A 00 (E0 8C)-CRC\n'
         '(Port 1): Response Timeout for Device 2, waited: 1000\n'
         '(Port 1): Consecutive Failures from Device Device 2: 25\n'
         '(Port 1): Setting All Points for Device Device 2: Offline\n'
         '(Port 1):  \n'
         '(Port 1): Reset Remote Link - Device 2 Address 1 \n'
         '(Port 1)TX[10]: 05 64 05 C0 01 00 0A 00 (E0 8C)-CRC\n'
         '(Port 1): Response Timeout for Device 2, waited: 1000\n'
         '(Port 1): Consecutive Failures from Device Device 2: 26\n'
         '(Port 1): Setting All Points for Device Device 2: Offline\n'
         '(Port 1):  \n'
         '(Port 1): Reset Remote Link - Device 2 Address 1 \n'
         '(Port 1)TX[10]: 05 64 05 C0 01 00 0A 00 (E0 8C)-CRC\n'
         '(Port 1): Response Timeout for Device 2, waited: 1000\n'
         '(Port 1): Consecutive Failures from Device Device 2: 27\n'
         '(Port 1): Setting All Points for Device Device 2: Offline\n'
         '(Port 1):  \n'
         '(Port 1): Reset Remote Link - Device 2 Address 1 \n'
         '(Port 1)TX[10]: 05 64 05 C0 01 00 0A 00 (E0 8C)-CRC\n')
     output_data = input_data.replace(' ', '')
     expected_output = [('056405C001000A00', 'E08C', 'True'),
                        ('056405C001000A00', 'E08C', 'True'),
                        ('056405C001000A00', 'E08C', 'True'),
                        ('056405C001000A00', 'E08C', 'True'),
                        ('056405C001000A00', 'E08C', 'True'),
                        ('056405C001000A00', 'E08C', 'True')]
     exit_value = parseInput.parseData('', input_data)
     self.assertEqual(exit_value, expected_output)
 def test_pasted_tx_message_with_message_bytes_and_parens_around_crc_and_leading_tx(
         self):
     'Verifies the result for a pasted message with leading TX[xx]: and parenthesis around the crc bytes'
     input_data = 'TX[10]: 05 64 05 C0 01 00 0A 00 (E0 8C)\n'
     output_data = input_data.replace(' ', '')
     open_paren_location = output_data.find('(')
     close_paren_location = output_data.find(')')
     colon_location = output_data.find(':')
     expected_output = [
         (output_data[colon_location + 1:open_paren_location],
          output_data[open_paren_location + 1:close_paren_location], "True")
     ]
     exit_value = parseInput.parseData(input_data, '')
     self.assertEqual(exit_value, expected_output)
 def test_pasted_tx_message_with_message_bytes_and_parens_around_crc_and_leading_tx(self):
     'Verifies the result for a pasted message with leading TX[xx]: and parenthesis around the crc bytes'
     input_data = 'TX[10]: 05 64 05 C0 01 00 0A 00 (E0 8C)\n'
     output_data = input_data.replace(' ', '')
     open_paren_location = output_data.find('(')
     close_paren_location = output_data.find(')')
     colon_location = output_data.find(':')
     expected_output = [
         (
             output_data[colon_location + 1:open_paren_location],
             output_data[open_paren_location + 1:close_paren_location],
             "True"
         )]
     exit_value = parseInput.parseData(input_data, '')
     self.assertEqual(exit_value, expected_output)
 def test_pasted_rx_message_with_message_bytes_and_parens_around_crc_and_leading_tx(
         self):
     'Verifies the result for a pasted message with leading TX[xx]: and parenthesis around the crc bytes'
     input_data = ('RX[17]: 05 64 0A 44 83 00 BF 00 (B1 4A)-CRC\n'
                   'E9 C1 81 00 00 (66 44)\n')
     output_data = input_data.replace(' ', '')
     open_paren_location = output_data.find('(')
     close_paren_location = output_data.find(')')
     colon_location = output_data.find(':')
     expected_output = [
         (output_data[colon_location + 1:open_paren_location],
          output_data[open_paren_location + 1:close_paren_location],
          "False"), ('E9C1810000', '6644', 'False')
     ]
     exit_value = parseInput.parseData(input_data, '')
     self.assertEqual(exit_value, expected_output)
 def test_pasted_rx_message_with_message_bytes_and_parens_around_crc_and_leading_tx(self):
     'Verifies the result for a pasted message with leading TX[xx]: and parenthesis around the crc bytes'
     input_data = ('RX[17]: 05 64 0A 44 83 00 BF 00 (B1 4A)-CRC\n'
                   'E9 C1 81 00 00 (66 44)\n')
     output_data = input_data.replace(' ', '')
     open_paren_location = output_data.find('(')
     close_paren_location = output_data.find(')')
     colon_location = output_data.find(':')
     expected_output = [
         (
             output_data[colon_location + 1:open_paren_location],
             output_data[open_paren_location + 1:close_paren_location],
             "False"
         ),
         (
             'E9C1810000',
             '6644',
             'False'
         )
     ]
     exit_value = parseInput.parseData(input_data, '')
     self.assertEqual(exit_value, expected_output)
 def test_file_message(self):
     'Verifies the result for a series of messages from a file'
     input_data = (''
         '----------- ** Capture Session Started 02/11/2013 13:20:00 ** ------------\n'
         '(Port 1): Response Timeout for Device 2, waited: 1000\n'
         '(Port 1): Consecutive Failures from Device Device 2: 22\n'
         '(Port 1): Setting All Points for Device Device 2: Offline\n'
         '(Port 1):  \n'
         '(Port 1): Reset Remote Link - Device 2 Address 1 \n'
         '(Port 1)TX[10]: 05 64 05 C0 01 00 0A 00 (E0 8C)-CRC\n'
         '(Port 1): Response Timeout for Device 2, waited: 1000\n'
         '(Port 1): Consecutive Failures from Device Device 2: 23\n'
         '(Port 1): Setting All Points for Device Device 2: Offline\n'
         '(Port 1):  \n'
         '(Port 1): Reset Remote Link - Device 2 Address 1 \n'
         '(Port 1)TX[10]: 05 64 05 C0 01 00 0A 00 (E0 8C)-CRC\n'
         '(Port 1): Response Timeout for Device 2, waited: 1000\n'
         '(Port 1): Consecutive Failures from Device Device 2: 24\n'
         '(Port 1): Setting All Points for Device Device 2: Offline\n'
         '(Port 1):  \n'
         '(Port 1): Reset Remote Link - Device 2 Address 1 \n'
         '(Port 1)TX[10]: 05 64 05 C0 01 00 0A 00 (E0 8C)-CRC\n'
         '(Port 1): Response Timeout for Device 2, waited: 1000\n'
         '(Port 1): Consecutive Failures from Device Device 2: 25\n'
         '(Port 1): Setting All Points for Device Device 2: Offline\n'
         '(Port 1):  \n'
         '(Port 1): Reset Remote Link - Device 2 Address 1 \n'
         '(Port 1)TX[10]: 05 64 05 C0 01 00 0A 00 (E0 8C)-CRC\n'
         '(Port 1): Response Timeout for Device 2, waited: 1000\n'
         '(Port 1): Consecutive Failures from Device Device 2: 26\n'
         '(Port 1): Setting All Points for Device Device 2: Offline\n'
         '(Port 1):  \n'
         '(Port 1): Reset Remote Link - Device 2 Address 1 \n'
         '(Port 1)TX[10]: 05 64 05 C0 01 00 0A 00 (E0 8C)-CRC\n'
         '(Port 1): Response Timeout for Device 2, waited: 1000\n'
         '(Port 1): Consecutive Failures from Device Device 2: 27\n'
         '(Port 1): Setting All Points for Device Device 2: Offline\n'
         '(Port 1):  \n'
         '(Port 1): Reset Remote Link - Device 2 Address 1 \n'
         '(Port 1)TX[10]: 05 64 05 C0 01 00 0A 00 (E0 8C)-CRC\n')
     output_data = input_data.replace(' ', '')
     expected_output = [
         (
             '056405C001000A00',
             'E08C',
             'True'
         ),
         (
             '056405C001000A00',
             'E08C',
             'True'
         ),
         (
             '056405C001000A00',
             'E08C',
             'True'
         ),
         (
             '056405C001000A00',
             'E08C',
             'True'
         ),
         (
             '056405C001000A00',
             'E08C',
             'True'
         ),
         (
             '056405C001000A00',
             'E08C',
             'True'
         )
     ]
     exit_value = parseInput.parseData('', input_data)
     self.assertEqual(exit_value, expected_output)
 def test_pasted_tx_message_with_only_message_bytes(self):
     'Verifies the result for a pasted message with no extra characters'
     input_data = '05 64 05 C0 01 00 0A 00 E0 8C'
     output_data = [(input_data.replace(' ', ''), "True")]
     exit_value = parseInput.parseData(input_data, '')
     self.assertEqual(exit_value, output_data)
 def test_bad_exit(self):
     'Verifies the function returns an empty string when no data is passed in'
     exit_value = parseInput.parseData('', '')
     self.assertEqual(exit_value, '')
 def test_ParseTwoInputs(self): #with both inputs present, it should use the first one (if not empty)
     parsedData = parseInput.parseData("1", "2")
     result = "1"
     assert result == parsedData[0][0]
 def test_ParseSimpleInput(self):
     inputData = "05 64 05 C0 01 00 0A 00 (E0 8C), 05 64 12 C4 02 00 64 00 (FF B7)"
     parsedData = parseInput.parseData("" , inputData)
     result = [("056405C001000A00","E08C","True"), ("056412C402006400","FFB7","True")]
     assert result == parsedData
 def test_pasted_tx_message_with_only_message_bytes(self):
     'Verifies the result for a pasted message with no extra characters'
     input_data = '05 64 05 C0 01 00 0A 00 E0 8C'
     output_data = [(input_data.replace(' ', ''), "True")]
     exit_value = parseInput.parseData(input_data, '')
     self.assertEqual(exit_value, output_data)
 def test_bad_exit(self):
     'Verifies the function returns an empty string when no data is passed in'
     exit_value = parseInput.parseData('', '')
     self.assertEqual(exit_value, '')