def test_define_object_verbose(self): # test that we can define a custom object customObjects = ( CustomObject( "Object1001", 1001, False, "single", (CustomResource("Resource100", 100, "string", "single", "optional", "rw"),), ), ) params = ["--verbose"] + tools_common.create_define_command(customObjects) expectedStdout = ( "Session IPC configured for UDP: address 127.0.0.1, port %d\nSession connected\nObjectID 1001 defined successfully\nSession disconnected\n" % (self.config.clientIpcPort,) ) expectedStderr = "" expectedCode = 0 # define our custom object result = client_define(self.config, *params) self.assertEqual(expectedStdout, result.stdout) self.assertEqual(expectedStderr, result.stderr) self.assertEqual(expectedCode, result.code)
def test_define_multiple_resources_same_ID(self): # test that we can't define multiple resources with the same ID in a single object customObjects = ( CustomObject( "Object1001", 1001, False, "single", ( CustomResource("Resource100", 100, "string", "single", "optional", "rw"), CustomResource("Resource100", 100, "string", "single", "optional", "rw"), ), ), ) params = tools_common.create_define_command(customObjects) result = client_define(self.config, *params) expectedStdout = "" expectedStderr = "AwaError_AlreadyDefined: \nCould not add resource definition (resource [100] Resource100) to object definition\nFailed to create object definition\n" expectedCode = 1 self.assertEqual(expectedStdout, result.stdout) self.assertEqual(expectedStderr, result.stderr) self.assertEqual(expectedCode, result.code)
def test_create_optional_resource(self): # test that the set tool can create an object instance without specifying an ID #expectedStdout = "Create /1000/0" expectedStdout = "" expectedStderr = "" expectedCode = 0 customObjects = ( tools_common.CustomObject("Object1001", 1001, False, "single", ( tools_common.CustomResource("Resource100", 100, "string", "single", "optional", "rw"), )), ) params = tools_common.create_define_command(customObjects) result = test_awa_client_define.client_define(self.config, *params) self.assertEqual(0, result.code) result = client_set(self.config, "--create /1001/0/") self.assertEqual(expectedStdout, result.stdout) self.assertEqual(expectedStderr, result.stderr) self.assertEqual(expectedCode, result.code) result = client_set(self.config, "--create /1001/0/100") self.assertEqual(expectedStdout, result.stdout) self.assertEqual(expectedStderr, result.stderr) self.assertEqual(expectedCode, result.code)
def test_set_read_only_resource(self): # test that we should still be able to set a read only resource (client should have permission to do anything) customObjects = ( CustomObject("Object1001", 1001, False, "single", ( CustomResource("Resource100", 100, "string", "single", "optional", "r"), )), ) params = tools_common.create_define_command(customObjects) result = client_define(self.config, *params) self.assertEqual(0, result.code) expectedStdout = "" expectedStderr = "" expectedCode = 0 # set a read only object result = client_set(self.config, "--create /1001/0 --create /1001/0/100 /1001/0/100=abc") self.assertEqual(expectedStdout, result.stdout) self.assertEqual(expectedStderr, result.stderr) self.assertEqual(expectedCode, result.code) expectedStdout = "Object1001[/1001/0]:\n Resource100[/1001/0/100]: abc\n" expectedStderr = "" expectedCode = 0 # check that the value was set correctly result = client_get(self.config, "/1001/0/100") self.assertEqual(expectedStdout, result.stdout) self.assertEqual(expectedStderr, result.stderr) self.assertEqual(expectedCode, result.code)
def test_redefine_existing_object(self): # test that we can't define an object if the ID is already used customObjects = ( CustomObject( "Object1001", 1001, False, "single", (CustomResource("Resource100", 100, "string", "single", "optional", "rw"),), ), ) params = tools_common.create_define_command(customObjects) # define our custom object result = client_define(self.config, *params) self.assertEqual(0, result.code) expectedStdout = "" expectedStderr = "AwaError_AlreadyDefined: Failed to add object definition\nDefine operation failed\n" expectedCode = 1 # attempt to redefine custom objects (should fail) result = client_define(self.config, *params) self.assertEqual(expectedStdout, result.stdout) self.assertEqual(expectedStderr, result.stderr) self.assertEqual(expectedCode, result.code)
def test_read_write_only_resource(self): # test that we can't read from a write only resource customObjects = ( CustomObject("Object1001", 1001, False, "single", ( CustomResource("Resource100", 100, "string", "single", "optional", "w"), )), ) #define and set the write only object params = tools_common.create_define_command(customObjects) result = client_define(self.config, *params) self.assertEqual(0, result.code) result = server_define(self.config, *params) self.assertEqual(0, result.code) result = server_write(self.config, "--create /1001/0") self.assertEqual("", result.stderr) self.assertEqual("", result.stdout) self.assertEqual(0, result.code) result = server_write(self.config, "/1001/0/100=abc") self.assertEqual("", result.stderr) self.assertEqual("", result.stdout) self.assertEqual(0, result.code) expectedStdout = "" expectedStderr = "AwaServerReadOperation_Perform failed\nFailed to read from path /1001/0/100: AwaLWM2MError_MethodNotAllowed\n" expectedCode = 1 # attempt to read a write only object, should fail result = server_read(self.config, "/1001/0/100") self.assertEqual(expectedStderr, result.stderr) self.assertEqual(expectedStdout, result.stdout) self.assertEqual(expectedCode, result.code)
def test_create_multiple_object_instances_for_single_instance_object(self): # test that the set tool cannot create an object instance with a non-zero ID on a single-instance customObjects = (tools_common.CustomObject( "Object1001", 1001, False, "single", (tools_common.CustomResource("Resource100", 100, "string", "single", "optional", "rw"), )), ) params = tools_common.create_define_command(customObjects) result = test_awa_client_define.client_define(self.config, *params) self.assertEqual(0, result.code) expectedStdout = "" expectedStderr = "" expectedCode = 0 result = client_set(self.config, "--create /1001/0") self.assertEqual(expectedStdout, result.stdout) self.assertEqual(expectedStderr, result.stderr) self.assertEqual(expectedCode, result.code) expectedStdout = "" expectedStderr = "AwaClientSetOperation_Perform failed\nFailed to set on path /1001/1: AwaError_CannotCreate\n" expectedCode = 1 result = client_set(self.config, "--create /1001/1") self.assertEqual(expectedStdout, result.stdout) self.assertEqual(expectedStderr, result.stderr) self.assertEqual(expectedCode, result.code)
def test_read_write_only_resource(self): # test that we can't read from a write only resource customObjects = ( CustomObject("Object1001", 1001, False, "single", ( CustomResource("Resource100", 100, "string", "single", "mandatory", "w"), )), ) #define and set the write only object params = tools_common.create_define_command(customObjects) result = client_define(self.config, *params) self.assertEqual(0, result.code) result = server_define(self.config, *params) self.assertEqual(0, result.code) result = server_write(self.config, "--create /1001/0") self.assertEqual("", result.stderr) self.assertEqual("", result.stdout) self.assertEqual(0, result.code) result = server_write(self.config, "/1001/0/100=abc") self.assertEqual("", result.stderr) self.assertEqual("", result.stdout) self.assertEqual(0, result.code) expectedStdout = "" expectedStderr = "AwaServerReadOperation_Perform failed\nFailed to read from path /1001/0/100: AwaLWM2MError_MethodNotAllowed\n" expectedCode = 1 # attempt to read a write only object, should fail result = server_read(self.config, "/1001/0/100") self.assertEqual(expectedStderr, result.stderr) self.assertEqual(expectedStdout, result.stdout) self.assertEqual(expectedCode, result.code)
def test_set_read_only_resource(self): # test that we should still be able to set a read only resource (client should have permission to do anything) customObjects = (CustomObject( "Object1001", 1001, False, "single", (CustomResource( "Resource100", 100, "string", "single", "optional", "r"), )), ) params = tools_common.create_define_command(customObjects) result = client_define(self.config, *params) self.assertEqual(0, result.code) expectedStdout = "" expectedStderr = "" expectedCode = 0 # set a read only object result = client_set( self.config, "--create /1001/0 --create /1001/0/100 /1001/0/100=abc") self.assertEqual(expectedStdout, result.stdout) self.assertEqual(expectedStderr, result.stderr) self.assertEqual(expectedCode, result.code) expectedStdout = "Object1001[/1001/0]:\n Resource100[/1001/0/100]: abc\n" expectedStderr = "" expectedCode = 0 # check that the value was set correctly result = client_get(self.config, "/1001/0/100") self.assertEqual(expectedStdout, result.stdout) self.assertEqual(expectedStderr, result.stderr) self.assertEqual(expectedCode, result.code)
def test_create_multiple_object_instances_for_single_instance_object(self): # test that the set tool cannot create an object instance with a non-zero ID on a single-instance customObjects = ( tools_common.CustomObject("Object1001", 1001, False, "single", ( tools_common.CustomResource("Resource100", 100, "string", "single", "optional", "rw"), )), ) params = tools_common.create_define_command(customObjects) result = test_awa_client_define.client_define(self.config, *params) self.assertEqual(0, result.code) expectedStdout = "" expectedStderr = "" expectedCode = 0 result = client_set(self.config, "--create /1001/0") self.assertEqual(expectedStdout, result.stdout) self.assertEqual(expectedStderr, result.stderr) self.assertEqual(expectedCode, result.code) expectedStdout = "" expectedStderr = "AwaClientSetOperation_Perform failed\nFailed to set on path /1001/1: AwaError_CannotCreate\n" expectedCode = 1 result = client_set(self.config, "--create /1001/1") self.assertEqual(expectedStdout, result.stdout) self.assertEqual(expectedStderr, result.stderr) self.assertEqual(expectedCode, result.code)
def test_define_unsupported_resource_type(self): # test that we can't use 'byte' as a resource type without crashing customObjects = (CustomObject( "Object1000", 1000, False, "single", (CustomResource( "Resource100", 100, "byte", "single", "optional", "rw"), )), ) params = tools_common.create_define_command(customObjects) expectedStdout = "" expectedStderr = tools_common.SERVER_DEFINE + ": invalid argument, \"byte\", for option `--resourceType\' (`-t\')\n" expectedCode = 1 # define our custom object result = server_define(self.config, *params) self.assertEqual(expectedStdout, result.stdout) self.assertEqual(expectedStderr, result.stderr) self.assertEqual(expectedCode, result.code)
def test_define_executable_non_none_resource(self): # test that only none resource types can be executable customObjects = (CustomObject( "Object1000", 1000, False, "single", (CustomResource( "Resource100", 100, "string", "single", "optional", "e"), )), ) params = tools_common.create_define_command(customObjects) expectedStdout = "" expectedStderr = "AwaError_DefinitionInvalid: \nCould not add resource definition (resource [100] Resource100) to object definition\nFailed to create object definition\n" expectedCode = 1 # define our custom object result = server_define(self.config, *params) self.assertEqual(expectedStdout, result.stdout) self.assertEqual(expectedStderr, result.stderr) self.assertEqual(expectedCode, result.code)
def test_define_no_resources(self): # test that we can define an object without resources customObjects = ( CustomObject("Object1234", 1234, False, "single", ()), ) params = ["--verbose"] + tools_common.create_define_command(customObjects) expectedStdout = "Session IPC configured for UDP: address 127.0.0.1, port %d\nSession connected\nObjectID 1234 defined successfully\nSession disconnected\n" % (self.config.serverIpcPort, ) expectedStderr = "" expectedCode = 0 # define our custom object result = server_define(self.config, *params) self.assertEqual(expectedStdout, result.stdout) self.assertEqual(expectedStderr, result.stderr) self.assertEqual(expectedCode, result.code)
def test_define_read_write_execute(self): # test that we can't create a resource that supports read, write and execute together (only r, w, rw or e) customObjects = (CustomObject( "Object1000", 1000, False, "single", (CustomResource("Resource100", 100, "string", "single", "optional", "rwe"), )), ) params = tools_common.create_define_command(customObjects) expectedStdout = "" expectedStderr = tools_common.SERVER_DEFINE + ": invalid argument, \"rwe\", for option `--resourceOperations\' (`-k\')\n" expectedCode = 1 # define our custom object result = server_define(self.config, *params) self.assertEqual(expectedStdout, result.stdout) self.assertEqual(expectedStderr, result.stderr) self.assertEqual(expectedCode, result.code)
def test_define_object(self): # test that we can define a custom object customObjects = (CustomObject( "Object1234", 1234, False, "single", (CustomResource("Resource100", 100, "string", "single", "optional", "rw"), )), ) params = tools_common.create_define_command(customObjects) expectedStdout = "" expectedStderr = "" expectedCode = 0 # define our custom object result = server_define(self.config, *params) self.assertEqual(expectedStdout, result.stdout) self.assertEqual(expectedStderr, result.stderr) self.assertEqual(expectedCode, result.code)
def test_new_object_no_instance(self): # test a get on a new object with no instances created customObjects = (CustomObject( "Object1001", 1001, False, "single", (CustomResource("Resource100", 100, "string", "single", "optional", "rw"), )), ) params = tools_common.create_define_command(customObjects) client_define(self.config, *params) expectedStdout = "Object1001[/1001]: No instances\n" expectedStderr = "" expectedCode = 0 result = client_get(self.config, "/1001") self.assertEqual(expectedStdout, result.stdout) self.assertEqual(expectedStderr, result.stderr) self.assertEqual(expectedCode, result.code)
def test_new_object_no_instance(self): # test a get on a new object with no instances created customObjects = ( CustomObject("Object1001", 1001, False, "single", ( CustomResource("Resource100", 100, "string", "single", "optional", "rw"), )), ) params = tools_common.create_define_command(customObjects) client_define(self.config, *params) expectedStdout = "Object1001[/1001]: No instances\n" expectedStderr = "" expectedCode = 0 result = client_get(self.config, "/1001") self.assertEqual(expectedStdout, result.stdout) self.assertEqual(expectedStderr, result.stderr) self.assertEqual(expectedCode, result.code)
def test_define_unsupported_resource_type(self): # test that we can't use 'byte' as a resource type without crashing customObjects = ( CustomObject("Object1000", 1000, False, "single", ( CustomResource("Resource100", 100, "byte", "single", "optional", "rw"), )), ) params = tools_common.create_define_command(customObjects) expectedStdout = "" expectedStderr = tools_common.SERVER_DEFINE + ": invalid argument, \"byte\", for option `--resourceType\' (`-t\')\n" expectedCode = 1 # define our custom object result = server_define(self.config, *params) self.assertEqual(expectedStdout, result.stdout) self.assertEqual(expectedStderr, result.stderr) self.assertEqual(expectedCode, result.code)
def test_define_multiple_instance_executable_resource(self): # test that executable resources can only be single instance customObjects = ( CustomObject("Object1000", 1000, False, "single", ( CustomResource("Resource100", 100, "string", "multiple", "optional", "e"), )), ) params = tools_common.create_define_command(customObjects) expectedStdout = "" expectedStderr = "AwaError_DefinitionInvalid: \nCould not add resource definition (resource [100] Resource100) to object definition\nFailed to create object definition\n" expectedCode = 1 # define our custom object result = server_define(self.config, *params) self.assertEqual(expectedStdout, result.stdout) self.assertEqual(expectedStderr, result.stderr) self.assertEqual(expectedCode, result.code)
def test_define_read_write_execute(self): # test that we can't create a resource that supports read, write and execute together (only r, w, rw or e) customObjects = ( CustomObject("Object1000", 1000, False, "single", ( CustomResource("Resource100", 100, "string", "single", "optional", "rwe"), )), ) params = tools_common.create_define_command(customObjects) expectedStdout = "" expectedStderr = tools_common.SERVER_DEFINE + ": invalid argument, \"rwe\", for option `--resourceOperations\' (`-k\')\n" expectedCode = 1 # define our custom object result = server_define(self.config, *params) self.assertEqual(expectedStdout, result.stdout) self.assertEqual(expectedStderr, result.stderr) self.assertEqual(expectedCode, result.code)
def test_define_object(self): # test that we can define a custom object customObjects = ( CustomObject("Object1234", 1234, False, "single", ( CustomResource("Resource100", 100, "string", "single", "optional", "rw"), )), ) params = tools_common.create_define_command(customObjects) expectedStdout = "" expectedStderr = "" expectedCode = 0 # define our custom object result = server_define(self.config, *params) self.assertEqual(expectedStdout, result.stdout) self.assertEqual(expectedStderr, result.stderr) self.assertEqual(expectedCode, result.code)
def test_define_object_verbose(self): # test that we can define a custom object customObjects = (CustomObject( "Object1001", 1001, False, "single", (CustomResource("Resource100", 100, "string", "single", "optional", "rw"), )), ) params = ["--verbose" ] + tools_common.create_define_command(customObjects) expectedStdout = "Session IPC configured for UDP: address 127.0.0.1, port %d\nSession connected\nObjectID 1001 defined successfully\nSession disconnected\n" % ( self.config.clientIpcPort, ) expectedStderr = "" expectedCode = 0 # define our custom object result = client_define(self.config, *params) self.assertEqual(expectedStdout, result.stdout) self.assertEqual(expectedStderr, result.stderr) self.assertEqual(expectedCode, result.code)
def test_define_multiple_resources_same_ID(self): # test that we can't define multiple resources with the same ID in a single object customObjects = ( CustomObject("Object1234", 1234, False, "single", ( CustomResource("Resource100", 100, "string", "single", "optional", "rw"), CustomResource("Resource100", 100, "string", "single", "optional", "rw"), )), ) params = tools_common.create_define_command(customObjects) result = server_define(self.config, *params) expectedStdout = "" expectedStderr = "AwaError_AlreadyDefined: \nCould not add resource definition (resource [100] Resource100) to object definition\nFailed to create object definition\n" expectedCode = 1 self.assertEqual(expectedStdout, result.stdout) self.assertEqual(expectedStderr, result.stderr) self.assertEqual(expectedCode, result.code)
def test_create_object_instance_with_non_zero_id(self): # test that the set tool can create an object instance with a specified ID expectedStdout = "" expectedStderr = "" expectedCode = 0 customObjects = (tools_common.CustomObject( "Object1001", 1001, False, "single", (tools_common.CustomResource("Resource100", 100, "string", "single", "optional", "rw"), )), ) params = tools_common.create_define_command(customObjects) result = test_awa_client_define.client_define(self.config, *params) self.assertEqual(0, result.code) result = test_awa_server_define.server_define(self.config, *params) self.assertEqual(0, result.code) result = server_write(self.config, "--create /1001/1") self.assertEqual(expectedStdout, result.stdout) self.assertEqual(expectedStderr, result.stderr) self.assertEqual(expectedCode, result.code)
def test_write_read_only_resource(self): # test that we can't write to a read only resource customObjects = (CustomObject( "Object1001", 1001, False, "single", (CustomResource( "Resource100", 100, "string", "single", "optional", "r"), )), ) params = tools_common.create_define_command(customObjects) result = client_define(self.config, *params) self.assertEqual(0, result.code) result = server_define(self.config, *params) self.assertEqual(0, result.code) # FlowDeviceMgmtServer_Write failed : (-11) The requested operation is not permitted\n expectedStdout = "" expectedStderr = "AwaServerWriteOperation_Perform failed\nFailed to write to path /1001/0/100: AwaLWM2MError_MethodNotAllowed\n" expectedCode = 1 # set a read only object result = server_write(self.config, "/1001/0/100=abc") self.assertEqual(expectedStderr, result.stderr) self.assertEqual(expectedStdout, result.stdout) self.assertEqual(expectedCode, result.code)
def test_redefine_existing_object(self): # test that we can't define an object if the ID is already used customObjects = (CustomObject( "Object1234", 1234, False, "single", (CustomResource("Resource100", 100, "string", "single", "optional", "rw"), )), ) params = tools_common.create_define_command(customObjects) # define our custom object result = server_define(self.config, *params) self.assertEqual(0, result.code) expectedStdout = "" expectedStderr = "AwaError_AlreadyDefined: Failed to add object definition\nDefine operation failed\n" expectedCode = 1 #attempt to redefine custom objects (should fail) result = server_define(self.config, *params) self.assertEqual(expectedStdout, result.stdout) self.assertEqual(expectedStderr, result.stderr) self.assertEqual(expectedCode, result.code)
def test_create_object_instance_with_non_zero_id(self): # test that the set tool can create an object instance with a specified ID expectedStdout = "" expectedStderr = "" expectedCode = 0 customObjects = ( tools_common.CustomObject("Object1001", 1001, False, "single", ( tools_common.CustomResource("Resource100", 100, "string", "single", "optional", "rw"), )), ) params = tools_common.create_define_command(customObjects) result = test_awa_client_define.client_define(self.config, *params) self.assertEqual(0, result.code) result = test_awa_server_define.server_define(self.config, *params) self.assertEqual(0, result.code) result = server_write(self.config, "--create /1001/1") self.assertEqual(expectedStdout, result.stdout) self.assertEqual(expectedStderr, result.stderr) self.assertEqual(expectedCode, result.code)
def test_write_read_only_resource(self): # test that we can't write to a read only resource customObjects = ( CustomObject("Object1001", 1001, False, "single", ( CustomResource("Resource100", 100, "string", "single", "optional", "r"), )), ) params = tools_common.create_define_command(customObjects) result = client_define(self.config, *params) self.assertEqual(0, result.code) result = server_define(self.config, *params) self.assertEqual(0, result.code) # FlowDeviceMgmtServer_Write failed : (-11) The requested operation is not permitted\n expectedStdout = "" expectedStderr = "AwaServerWriteOperation_Perform failed\nFailed to write to path /1001/0/100: AwaLWM2MError_MethodNotAllowed\n" expectedCode = 1 # set a read only object result = server_write(self.config, "/1001/0/100=abc") self.assertEqual(expectedStderr, result.stderr) self.assertEqual(expectedStdout, result.stdout) self.assertEqual(expectedCode, result.code)
def test_get_write_only_resource(self): # test that we can read from a write only resource - client should have power to do anything customObjects = (CustomObject( "Object1001", 1001, False, "single", (CustomResource( "Resource100", 100, "string", "single", "optional", "w"), )), ) #define and set the write only object params = tools_common.create_define_command(customObjects) result = client_define(self.config, *params) self.assertEqual(0, result.code) result = client_set( self.config, "--create /1001/0 --create /1001/0/100 /1001/0/100=abc") self.assertEqual(0, result.code) expectedStdout = "Object1001[/1001/0]:\n Resource100[/1001/0/100]: abc\n" expectedStderr = "" expectedCode = 0 # attempt to get a write only object, should not fail on the client only. result = client_get(self.config, "/1001/0/100") self.assertEqual(expectedStdout, result.stdout) self.assertEqual(expectedStderr, result.stderr) self.assertEqual(expectedCode, result.code)
def test_get_write_only_resource(self): # test that we can read from a write only resource - client should have power to do anything customObjects = ( CustomObject("Object1001", 1001, False, "single", ( CustomResource("Resource100", 100, "string", "single", "optional", "w"), )), ) #define and set the write only object params = tools_common.create_define_command(customObjects) result = client_define(self.config, *params) self.assertEqual(0, result.code) result = client_set(self.config, "--create /1001/0 --create /1001/0/100 /1001/0/100=abc") self.assertEqual(0, result.code) expectedStdout = "Object1001[/1001/0]:\n Resource100[/1001/0/100]: abc\n" expectedStderr = "" expectedCode = 0 # attempt to get a write only object, should not fail on the client only. result = client_get(self.config, "/1001/0/100") self.assertEqual(expectedStdout, result.stdout) self.assertEqual(expectedStderr, result.stderr) self.assertEqual(expectedCode, result.code)