Пример #1
0
 def test_Webinterface_template_with_default(self):
     """test_Webinterface_template_with_default 
     TC6-A Kan importere default template med argument "default"
     """
     self.webschema2 = JsonControl()
     jsonSchema = self.webschema2.getTemplate("default")
     self.webschema2.validateTemplate(jsonSchema)
Пример #2
0
class Test_Setvalues(unittest.TestCase):
    def setUp(self):
        self.webschema = JsonControl()
        self.jsonSchema = self.webschema.getTemplate("default")

    def test_Can_SetValues_to_Default(self):
        """test_SetValues_to_default 
        TC9-A Kan sætte værdierne i et JSON schema til default værdier
        """
        self.assertEqual(self.jsonSchema["sentBy"], "<machineProcessId>")
        self.webschema.setDefaultValues(self.jsonSchema)
        self.assertEqual(self.jsonSchema["sentBy"], settings.df_sentBy)
        self.assertEqual(self.jsonSchema["statusCode"], None)

    def test_Can_SetValues_to_RealValues(self):
        """test_SetValues_to_RealValues 
        TC10-A Kan sætte værdierne i et JSON schema til "rigtige" værdier
        """
        settings.protocolVersion = 0.3
        settings.sentBy = "tester"
        settings.msgType = "command"
        settings.commandList = "starttest"
        settings.statusCode = "busy"
        settings.embeddedFileFormat = "tbd"
        settings.embeddedFile = "small"
        self.webschema.setValues(self.jsonSchema)
        self.assertEqual(self.jsonSchema["protocolVersion"], 0.3)
        self.assertEqual(self.jsonSchema["sentBy"], "tester")
        self.assertEqual(self.jsonSchema["msgType"], "command")
        self.assertEqual(self.jsonSchema["commandList"], "starttest")
        self.assertEqual(self.jsonSchema["statusCode"], "busy")
        self.assertEqual(self.jsonSchema["embeddedFileFormat"], "tbd")
        self.assertEqual(self.jsonSchema["embeddedFile"], "small")
Пример #3
0
 def test_Will_Fail_unKnown_Template(self):
     """test_Will_Fail_unKnown_Template 
     TC2-A Accepterer kun kendte templates
     """
     unknownTemplate = "unknown.json"
     self.unknown_Template = JsonControl()
     Template = self.unknown_Template.getTemplate(unknownTemplate)
     self.assertIs(Template, "failed")
Пример #4
0
 def test_Can_Import_Known_Template(self):
     """test_Can_Import_Known_Template 
     TC1-A Kan importere template
     """
     knownTemplate = settings.defaultJsonTemplate
     self.known_Template = JsonControl()
     self.known_Template.getTemplate(knownTemplate)
     self.assertTrue(self.known_Template, True)
Пример #5
0
    def startTest(self, testStandID="TS1"):
        self.entry_rxData.delete(first=0, last=END)
        if testStandID == "TS1":
            self.entry_rxData.delete(0, END)
            self.entry_rxData.update()
            print("Test Stand 1 Starts Testing!")
            settings.msgType = "command"
            settings.commandList = "starttest"
            JsonControl.setValues(self, self.jsonSchema)
            settings.txData = JsonControl.serialize(
                self, self.jsonSchema)
            sendNetData()
            self.entry_rxData.insert(0, settings.rxData_cl)

        else:
            print("Unkown Test Stand ID!")
            print("Provide TS1 for Test Stand 1, TS2, TS3 etc..")
Пример #6
0
class Test_Import_Template(unittest.TestCase):
    def test_Can_Import_Known_Template(self):
        """test_Can_Import_Known_Template 
        TC1-A Kan importere template
        """
        knownTemplate = settings.defaultJsonTemplate
        self.known_Template = JsonControl()
        self.known_Template.getTemplate(knownTemplate)
        self.assertTrue(self.known_Template, True)

    def test_Will_Fail_unKnown_Template(self):
        """test_Will_Fail_unKnown_Template 
        TC2-A Accepterer kun kendte templates
        """
        unknownTemplate = "unknown.json"
        self.unknown_Template = JsonControl()
        Template = self.unknown_Template.getTemplate(unknownTemplate)
        self.assertIs(Template, "failed")
Пример #7
0
class Test_Serialize_deSerialize(unittest.TestCase):
    def setUp(self):
        self.webschema = JsonControl()
        self.webschema.getTemplate(webSchema)

    def test_serialize_dict_to_string(self):
        """test_serialize_dict_to_string 
        TC7-A Kan serialize dict til string
        """
        jsonString = self.webschema.serialize(testSchema)
        self.assertTrue(isinstance(jsonString, str))

    def test_deSerializes_string_to_dict(self):
        """test_deSerializes_string_to_dict 
        TC8-A Kan De-serialize en string til dict
        """
        jsonString = self.webschema.serialize(testSchema)
        data = self.webschema.deSerialize(jsonString)
        self.assertTrue(isinstance(data, dict))
Пример #8
0
    def __init__(self, master):
        self.cjsonSchema = JsonControl()
        self.datactrl = DataControl()
        content = Frame(root)
        content.grid()
        # Program "Main" Header
        self.lb_prgHeader = Label(
            content, text=txt_programTitle, font=f_header1, )
        self.lb_prgHeader.grid(row=0, column=0, columnspan=4, sticky=(N, E, W))

        # Button: Start Test
        self.bt_startTest = Button(
            content, text="Start Test", font=f_normal, command=self.startTest)
        self.bt_startTest.grid(row=5, column=0)

        # Button: Initialize Template
        self.bt_usetemplate = Button(
            content, text="Use Template", font=f_normal, command=self.setTemplate)
        self.bt_usetemplate.grid(row=1, column=0)

        # Entry: Template
        self.entry_template = Entry(
            content, width=16)
        self.entry_template.grid(row=1, column=1, columnspan=3)
        self.entry_template.insert(0, settings.defaultJsonTemplate)
        # Button: Quit Program
        self.bt_quitProgram = Button(
            content, text="Quit", font=f_normal, command=content.quit)
        self.bt_quitProgram.grid(row=6, column=3, sticky=(S, E))

        # Label: Receive Data
        self.lb_rxData = Label(content, text="Received Data", font=f_normal)
        self.lb_rxData.grid(row=4, column=1)

        # Entry: Receive Data
        self.entry_rxData = Entry(
            content, width=12)
        self.entry_rxData.grid(row=5, column=1)
Пример #9
0
class DataControl():
    def __init__(self):
        self.cjsonSchema = JsonControl()
        return

    def getKeys(self, schema):
        return schema.keys()

    def getValues(self, schema):
        return schema.values()

    def startTest(self, schema, testStandID):
        """startTest Initiates a testrun by setting up the values in
        the JSON schema and pushing them to the teststand via netsockets
        (sendNetData)

        :param schema: Json schema
        :type schema: dict
        :param testStandID: "TS1" "TS2" etc.
        :type testStandID: str
        """
        if testStandID == "TS1":
            print("Test Stand 1 Starts Testing!")
            self.cjsonSchema.setValues(schema)
            settings.txData_cl = JsonControl.serialize(
                self, schema)
            sendNetData()
        else:
            print("Unkown Test Stand ID!")
            print("Provide TS1 for Test Stand 1, TS2, TS3 etc..")

    def trySetTemplate(self, schema):
        """trySetTemplate Will attempt to create a default template,
        that the teststand ID and commands can be stored in, 
        before initiating a test.

        :param schema: json schema
        :type schema: dict
        :return: schema
        :rtype: dict
        """
        try:
            self.jsonSchema = self.cjsonSchema.getTemplate(
                schema)
            self.cjsonSchema.setDefaultValues(self.jsonSchema)
        except:
            print("Failed loading JSON Schema!")
        self.cjsonSchema.validateTemplate(self.jsonSchema)
        return self.jsonSchema
Пример #10
0
    def startTest(self, schema, testStandID):
        """startTest Initiates a testrun by setting up the values in
        the JSON schema and pushing them to the teststand via netsockets
        (sendNetData)

        :param schema: Json schema
        :type schema: dict
        :param testStandID: "TS1" "TS2" etc.
        :type testStandID: str
        """
        if testStandID == "TS1":
            print("Test Stand 1 Starts Testing!")
            self.cjsonSchema.setValues(schema)
            settings.txData_cl = JsonControl.serialize(
                self, schema)
            sendNetData()
        else:
            print("Unkown Test Stand ID!")
            print("Provide TS1 for Test Stand 1, TS2, TS3 etc..")
Пример #11
0
class Test_Can_Validate_Webinterface_template(unittest.TestCase):
    def setUp(self):
        self.webschema = JsonControl()
        self.webschema.getTemplate(webSchema)

    def test_Webinterface_template_with_valid_input(self):
        """test_Webinterface_template_with_valid_input 
        TC5-A Kan validere WebinterfaceTeststandPayload_v1.json
        """
        jsonSchema = dict(statuscode="2", testcode="Write")
        self.webschema.validateTemplate(jsonSchema)

    def test_Webinterface_template_with_default(self):
        """test_Webinterface_template_with_default 
        TC6-A Kan importere default template med argument "default"
        """
        self.webschema2 = JsonControl()
        jsonSchema = self.webschema2.getTemplate("default")
        self.webschema2.validateTemplate(jsonSchema)
Пример #12
0
class Test_Can_Validate_Ref_Template(unittest.TestCase):
    def setUp(self):
        self.refschema = JsonControl()
        self.refschema.getTemplate(refSchema)

    def test_Reference_template_with_valid_input(self):
        """test_Reference_template_with_valid_input 
        TC3-A Den Importerede template valideres 
        mod indholdet i den lagrede
        """
        TestJsonString = {"name": "eggs", "price": 21.47, "sku": 7}
        self.refschema.validateTemplate(TestJsonString)

    def test_Reference_template_with_invalid_input(self):
        """test_Reference_template_with_valid_input 
        TC4-A Hvis en type int sættes til type string fejler validering
        """
        TestJsonString = {"name": "eggs", "price": 21.47, "sku": "o"}
        with self.assertRaises(Exception):
            self.refschema.validateTemplate(TestJsonString)
Пример #13
0
class Gui:
    # , padding=(3, 3, 12, 12)
    def __init__(self, master):
        self.cjsonSchema = JsonControl()
        self.datactrl = DataControl()
        content = Frame(root)
        content.grid()
        # Program "Main" Header
        self.lb_prgHeader = Label(
            content, text=txt_programTitle, font=f_header1, )
        self.lb_prgHeader.grid(row=0, column=0, columnspan=4, sticky=(N, E, W))

        # Button: Start Test
        self.bt_startTest = Button(
            content, text="Start Test", font=f_normal, command=self.startTest)
        self.bt_startTest.grid(row=5, column=0)

        # Button: Initialize Template
        self.bt_usetemplate = Button(
            content, text="Use Template", font=f_normal, command=self.setTemplate)
        self.bt_usetemplate.grid(row=1, column=0)

        # Entry: Template
        self.entry_template = Entry(
            content, width=16)
        self.entry_template.grid(row=1, column=1, columnspan=3)
        self.entry_template.insert(0, settings.defaultJsonTemplate)
        # Button: Quit Program
        self.bt_quitProgram = Button(
            content, text="Quit", font=f_normal, command=content.quit)
        self.bt_quitProgram.grid(row=6, column=3, sticky=(S, E))

        # Label: Receive Data
        self.lb_rxData = Label(content, text="Received Data", font=f_normal)
        self.lb_rxData.grid(row=4, column=1)

        # Entry: Receive Data
        self.entry_rxData = Entry(
            content, width=12)
        self.entry_rxData.grid(row=5, column=1)

    def setTemplate(self):
        actualTemplate = self.entry_template.get()
        self.entry_template.delete(0, END)
        try:
            jsonSchema = self.cjsonSchema.getTemplate(
                actualTemplate)
            self.jsonSchema = jsonSchema

            self.entry_template.insert(0, "JSON Schema OK")
        except:
            print(actualTemplate)
            self.entry_template.insert(0, "FAILED! Try again")
        self.entry_template.update()
        self.cjsonSchema.validateTemplate(jsonSchema)

    def startTest(self, testStandID="TS1"):
        self.entry_rxData.delete(first=0, last=END)
        if testStandID == "TS1":
            self.entry_rxData.delete(0, END)
            self.entry_rxData.update()
            print("Test Stand 1 Starts Testing!")
            settings.msgType = "command"
            settings.commandList = "starttest"
            JsonControl.setValues(self, self.jsonSchema)
            settings.txData = JsonControl.serialize(
                self, self.jsonSchema)
            sendNetData()
            self.entry_rxData.insert(0, settings.rxData_cl)

        else:
            print("Unkown Test Stand ID!")
            print("Provide TS1 for Test Stand 1, TS2, TS3 etc..")
Пример #14
0
 def setUp(self):
     self.webschema = JsonControl()
     self.webschema.getTemplate(webSchema)
Пример #15
0
 def setUp(self):
     self.webschema = JsonControl()
     self.jsonSchema = self.webschema.getTemplate("default")
Пример #16
0
 def __init__(self):
     self.cjsonSchema = JsonControl()
     return
Пример #17
0
def readGPIOpin(pin):  # pin format = P8_XX
    """readGPIOpin retrieves current state of a GPIO pin per request
    """
    spin = str(pin)
    GPIO.setup(spin, GPIO.IN)
    if GPIO.input(spin):
        settings.msgType = "status"
        settings.commandList = "GPIO Pin " + spin + " is HIGH"
    else:
        settings.msgType = "status"
        settings.commandList = "GPIO Pin " + spin + " is LOW"


# We must instantiate a JSON template object to be able to start test etc.
JsonWorker = JsonControl()
JsonWorker.getTemplate("default")


def getTestResult():
    """getTestResult will handle request for test actions. 
    Meaning it will initiate a given test action eg. setGPIOpin "P8_11" "HIGH"
    """
    if settings.statusCode == "Busy":
        print("Schema for deserialize = %s" % settings.str_rxData_ser)
        JsonSchema = JsonWorker.deSerialize(settings.str_rxData_ser)
        JsonWorker.getValues(JsonSchema)
        if settings.msgType == "command":
            if settings.commandList == "readGPIO_P8_11":
                readGPIOpin("P8_11")
            if settings.commandList == "setGPIO_P8_11H":
Пример #18
0
 def setUp(self):
     self.refschema = JsonControl()
     self.refschema.getTemplate(refSchema)