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_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_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_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_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_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_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_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_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)