From ab5d9184be3b18413be9f804277ae690c1e0e9a7 Mon Sep 17 00:00:00 2001 From: Martin Weick Date: Mon, 18 Jan 2021 15:21:41 +0100 Subject: [PATCH 1/2] #10 add part of test script --- iotclient/iot_client.py | 36 ++++++++++++++++++++++++++++++++---- 1 file changed, 32 insertions(+), 4 deletions(-) diff --git a/iotclient/iot_client.py b/iotclient/iot_client.py index cb3788b..a94faad 100644 --- a/iotclient/iot_client.py +++ b/iotclient/iot_client.py @@ -4,7 +4,7 @@ import requests import json import time from datetime import datetime - +import sys, getopt def build_post_payload(identifier, metadata_payload, file_payload): return { @@ -216,14 +216,42 @@ def print_cursor(): print('Cursor on ' + str(index) + " out of " + str(len(metadata)) + " - " + metadata[index]['filename']) +testCommands=[] +testscriptData=[] + +def test_script(argv): + try: + opts, args=getopt.getopt(argv,"t") + except getopt.GetoptError: + print("Error by starting test script") + sys.exit(2) + for opt, arg in opts: + if opt == '-t': + testscriptData.append(True) + testCommands.append("deleteall") + #testCommands.append("fetchall") + testCommands.append("trigger") + testCommands.append("trigger") + testCommands.append("fetchall") + testCommands.append("exit") + testscriptData.append(len(testCommands)) + else: + testscriptData.append(False) + + + # main input loop command = "dummy" - - +test_script(sys.argv[1:]) +i=0 while (command.lower() not in ["exit", "quit", "end"]): try: - command = input("Please enter command: ") + if testscriptData[0] and i < testscriptData[1]: + command=testCommands[i] + i+=1 + else: + command = input("Please enter command: ") except: print() print("Error while reading keyboard input") From 6878c96f76b877501a886fa3e8ce00ebd081a68f Mon Sep 17 00:00:00 2001 From: Martin Weick Date: Mon, 18 Jan 2021 20:34:13 +0100 Subject: [PATCH 2/2] #3 bug fix list error --- iotclient/iot_client.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/iotclient/iot_client.py b/iotclient/iot_client.py index a6a9035..2c00154 100644 --- a/iotclient/iot_client.py +++ b/iotclient/iot_client.py @@ -238,12 +238,15 @@ testscriptData=[] def test_script(argv): try: + testscriptData.append(False) + testscriptData.append(0) opts, args=getopt.getopt(argv,"t") except getopt.GetoptError: print("Error by starting test script") sys.exit(2) for opt, arg in opts: if opt == '-t': + testscriptData.clear() testscriptData.append(True) testCommands.append("deleteall") #testCommands.append("fetchall") @@ -254,7 +257,7 @@ def test_script(argv): testscriptData.append(len(testCommands)) else: testscriptData.append(False) - + testscriptData.append(0) # main input loop @@ -269,8 +272,8 @@ while (command.lower() not in ["exit", "quit", "end"]): i+=1 else: command = input("Please enter command: ") - except: - print() + except Exception as ex: + print(ex) print("Error while reading keyboard input") break command_split = command.split(" ")