本文整理汇总了Python中test_awa_server_write.server_write函数的典型用法代码示例。如果您正苦于以下问题:Python server_write函数的具体用法?Python server_write怎么用?Python server_write使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了server_write函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_read_write_only_resource
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)
示例2: test_read_write_multiple_resources_same_instance
def test_read_write_multiple_resources_same_instance(self):
# test that multiple resources from the same instance can be set and retrieved with a single command
timezone = "ACME Corp."
currentTime = 123456789
result = server_write(self.config,
"/3/0/15=\"%s\"" % (timezone,),
"/3/0/13=%d" % (currentTime,))
self.assertEqual("", result.stderr)
self.assertEqual("", result.stdout)
self.assertEqual(0, result.code)
expectedStdout = "Device[/3/0]:\n Timezone[/3/0/15]: %s\n"% (timezone, )
expectedStderr = ""
expectedCode = 0
#result = server_read(self.config, "/3/0/15", "/3/0/13")
result = server_read(self.config, "/3/0/15")
self.assertEqual(expectedStderr, result.stderr)
self.assertEqual(expectedStdout, result.stdout)
self.assertEqual(expectedCode, result.code)
expectedStdout = "Device[/3/0]:\n CurrentTime[/3/0/13]: %s\n"% (currentTime, )
result = server_read(self.config, "/3/0/13")
self.assertEqual(expectedStderr, result.stderr)
self.assertEqual(expectedStdout, result.stdout)
self.assertEqual(expectedCode, result.code)
示例3: test_client_subscribe_resource_server_write
def test_client_subscribe_resource_server_write(self):
# test that the client can subscribe to a resource and receive a notification
# when that resource is changed by the server through the write function
# open client subscribe subprocess. Only wait for a single execute of the resource
port = self.config.clientIpcPort
subscribeProcess = tools_common.run_non_blocking(tools_common.CLIENT_SUBSCRIBE,
"--verbose --ipcPort %i --waitCount 1 /3/0/15" % (port,))
# wait for subscribe process to start up
self.assertEqual(tools_common.strip_prefix(subscribeProcess.stdout.readline()), "Session IPC configured for UDP: address 127.0.0.1, port %d" % (port,))
self.assertEqual(tools_common.strip_prefix(subscribeProcess.stdout.readline()), "Session connected")
self.assertEqual(tools_common.strip_prefix(subscribeProcess.stdout.readline()), "Subscribe /3/0/15 Change\n")
self.assertEqual(tools_common.strip_prefix(subscribeProcess.stdout.readline()), "Waiting for 1 notifications:\n")
# do write command
expectedStdout = ""
expectedStderr = ""
expectedCode = 0
result = server_write(self.config, "/3/0/15=abc")
self.assertEqual(expectedStdout, result.stdout)
self.assertEqual(expectedStderr, result.stderr)
self.assertEqual(expectedCode, result.code)
# read subscribe output
expectedStdout = "Notify 1:\nChanged: /3/0/15 Resource Modified:\nDevice[/3/0]:\n Timezone[/3/0/15]: abc\nSession disconnected\n"
expectedStderr = ""
expectedCode = 0
result = tools_common.non_blocking_get_run_result(subscribeProcess)
self.assertEqual(expectedStdout, result.stdout)
self.assertEqual(expectedStderr, result.stderr)
self.assertEqual(expectedCode, result.code)
示例4: test_read_write_multiple_resources_different_instances
def test_read_write_multiple_resources_different_instances(self):
# test that multiple resources from different instances can be set and retrieved with a single command
timezone = "ACME Corp."
modelNumber = "1234567890"
expectedStdout = \
""" Timezone[3/0/15]: %s
Resource100[1000/0/100]: %s
""" % (timezone, modelNumber)
expectedStderr = ""
expectedCode = 0
server_write(self.config, "/3/0/15=\"%s\"" % (timezone,), "/1000/0/100=\"%s\"" % (modelNumber,))
result = server_read(self.config, "/3/0/15", "/1000/0/100")
self.assertEqual(expectedStdout, result.stdout)
self.assertEqual(expectedStderr, result.stderr)
self.assertEqual(expectedCode, result.code)
示例5: temp_create_resource
def temp_create_resource(self, path, value):
# because defaults aren't currently supported, do a write to create the resource.
expectedStdout = ""
expectedStderr = ""
expectedCode = 0
result = server_write(self.config, "%s=%s" % (path, value))
self.assertEqual(expectedStdout, result.stdout)
self.assertEqual(expectedStderr, result.stderr)
self.assertEqual(expectedCode, result.code)
示例6: test_set_multiple_instances_on_single_instance_object
def test_set_multiple_instances_on_single_instance_object(self):
#test that we can't create multiple object instances on a single instance object
expectedStdout = ""
expectedStderr = ""
expectedCode = 0
result = server_write(self.config, "/1000/0/100=abc")
self.assertEqual(expectedStdout, result.stdout)
self.assertEqual(expectedStderr, result.stderr)
self.assertEqual(expectedCode, result.code)
expectedStdout = ""
expectedStderr = "AwaServerWriteOperation_Perform failed\nFailed to write to path /1000/1/100: AwaLWM2MError_MethodNotAllowed\n"
expectedCode = 1
result = server_write(self.config, "/1000/1/100=abc")
self.assertEqual(expectedStderr, result.stderr)
self.assertEqual(expectedStdout, result.stdout)
self.assertEqual(expectedCode, result.code)
示例7: test_set_multiple_instances_on_single_instance_resource
def test_set_multiple_instances_on_single_instance_resource(self):
#test that we can't set multiple resource instances on a single instance resource
expectedStdout = ""
expectedStderr = "Error: resource /1000/0/100 is not an array; do not specify a resource instance ID\n"
expectedCode = 1
result = server_write(self.config, "/1000/0/100/0=abc")
self.assertEqual(expectedStdout, result.stdout)
self.assertEqual(expectedStderr, result.stderr)
self.assertEqual(expectedCode, result.code)
示例8: observe_resource
def observe_resource(self, path, currentValuesOutput, value, expectedResponse):
# test that we can observe to a single change of value on a specified resource
# open client observe subprocess. Only wait for a single change to the resource
resourcePath = "/".join(path.split("/")[0:4])
port = self.config.serverIpcPort
observeProcess = tools_common.run_non_blocking(
SERVER_OBSERVE,
"--verbose --ipcPort %i --waitCount 1 --waitTime 555 %s --clientID %s"
% (port, resourcePath, self.config.clientEndpointName),
)
# wait for observe process to start up
self.assertEqual(
tools_common.strip_prefix(observeProcess.stdout.readline()),
"Session IPC configured for UDP: address 127.0.0.1, port %d" % (port,),
)
self.assertEqual(tools_common.strip_prefix(observeProcess.stdout.readline()), "Session connected")
self.assertEqual(tools_common.strip_prefix(observeProcess.stdout.readline()), "Observe %s\n" % (resourcePath,))
self.assertEqual(
tools_common.strip_prefix(observeProcess.stdout.readline()),
"Waiting for 1 notifications over 555 seconds:\n",
)
self.assertEqual(
tools_common.strip_prefix(observeProcess.stdout.readline()), "Notify 0 from clientID TestClient:\n"
)
self.assertEqual(
tools_common.strip_prefix(observeProcess.stdout.readline()),
"Changed: %s Resource Modified:\n" % (resourcePath,),
)
for line in currentValuesOutput:
self.assertEqual(tools_common.strip_prefix(observeProcess.stdout.readline()), line)
# do write command
expectedStdout = ""
expectedStderr = ""
expectedCode = 0
result = server_write(self.config, "%s=%s" % (path, value))
self.assertEqual(expectedStdout, result.stdout)
self.assertEqual(expectedStderr, result.stderr)
self.assertEqual(expectedCode, result.code)
# Notify 1:\n Manufacturer[3/0/0]: abc\nUnobserve /3/0/0\n
# read observe output
expectedStdout = expectedResponse
expectedStderr = ""
expectedCode = 0
result = tools_common.non_blocking_get_run_result(observeProcess)
self.assertEqual(expectedStdout, result.stdout)
self.assertEqual(expectedStderr, result.stderr)
self.assertEqual(expectedCode, result.code)
示例9: test_write_single_resource_none
def test_write_single_resource_none(self):
# test that a single none resource (executable) cannot be set
value = 12345
expectedStdout = ""
expectedStderr = "Resource /1000/0/107 is of type None and cannot be set\n"
expectedCode = 1
result = server_write(self.config, "/1000/0/107=%d" % (value,))
self.assertEqual(expectedStderr, result.stderr)
self.assertEqual(expectedStdout, result.stdout)
self.assertEqual(expectedCode, result.code)
示例10: test_server_write_client_get_multiple_resources_same_instance
def test_server_write_client_get_multiple_resources_same_instance(self):
# test that multiple resources from the same instance can be set on
# the server and retrieved on the client with single commands
timezone = "ACME Corp."
currentTime = 123456789
expectedStdout = \
"""Device[/3/0]:
Timezone[/3/0/15]: %s
CurrentTime[/3/0/13]: %d
""" % (timezone, currentTime)
expectedStderr = ""
expectedCode = 0
server_write(self.config,
"/3/0/15=\"%s\"" % (timezone,),
"/3/0/13=%d" % (currentTime,))
result = client_get(self.config, "/3/0/15", "/3/0/13")
self.assertEqual(expectedStdout, result.stdout)
self.assertEqual(expectedStderr, result.stderr)
self.assertEqual(expectedCode, result.code)
示例11: test_read_write_invalid_value
def test_read_write_invalid_value(self):
# first set an initial value for an integer resource.
# Then set the integer resource with a string value. Currently will set the value to 0
expectedStdout = ""
expectedStderr = ""
expectedCode = 0
result = server_write(self.config, "/1000/0/101=12345")
self.assertEqual(expectedStdout, result.stdout)
self.assertEqual(expectedStderr, result.stderr)
self.assertEqual(expectedCode, result.code)
expectedStdout = "Object1000[/1000/0]:\n Resource101[/1000/0/101]: 12345\n"
expectedStderr = ""
expectedCode = 0
result = server_read(self.config, "/1000/0/101")
self.assertEqual(expectedStdout, result.stdout)
self.assertEqual(expectedStderr, result.stderr)
self.assertEqual(expectedCode, result.code)
expectedStdout = ""
expectedStderr = ""
expectedCode = 0
result = server_write(self.config, "/1000/0/101=abc")
self.assertEqual(expectedStdout, result.stdout)
self.assertEqual(expectedStderr, result.stderr)
self.assertEqual(expectedCode, result.code)
expectedStdout = "Object1000[/1000/0]:\n Resource101[/1000/0/101]: 0\n"
expectedStderr = ""
expectedCode = 0
result = server_read(self.config, "/1000/0/101")
self.assertEqual(expectedStdout, result.stdout)
self.assertEqual(expectedStderr, result.stderr)
self.assertEqual(expectedCode, result.code)
示例12: test_read_write_single_resource_integer
def test_read_write_single_resource_integer(self):
# test that a single integer resource can be set and retrieved
value = 3
expectedStdout = "Object1000[/1000/0]:\n Resource101[/1000/0/101]: %d\n" % (value,)
expectedStderr = ""
expectedCode = 0
result = server_write(self.config, "--verbose /1000/0/101=%d" % (value,))
self.assertEqual(expectedCode, result.code)
result = server_read(self.config, "/1000/0/101")
self.assertEqual(expectedStdout, result.stdout)
self.assertEqual(expectedStderr, result.stderr)
self.assertEqual(expectedCode, result.code)
示例13: test_read_write_single_resource_float
def test_read_write_single_resource_float(self):
# test that a single float resource can be set and retrieved
value = 3.5
expectedStdout = "Object1000[/1000/0]:\n Resource102[/1000/0/102]: %.1f\n" % (value,)
expectedStderr = ""
expectedCode = 0
result = server_write(self.config, "/1000/0/102=%f" % (value,))
self.assertEqual(expectedCode, result.code)
result = server_read(self.config, "/1000/0/102")
self.assertEqual(expectedStdout, result.stdout)
self.assertEqual(expectedStderr, result.stderr)
self.assertEqual(expectedCode, result.code)
示例14: test_read_write_single_resource_time
def test_read_write_single_resource_time(self):
# test that a single time resource (64 bit integer) can be set and retrieved
value = 1442972971
expectedStdout = "Object1000[/1000/0]:\n Resource104[/1000/0/104]: %d\n" % (value,)
expectedStderr = ""
expectedCode = 0
result = server_write(self.config, "/1000/0/104=%d" % (value,))
self.assertEqual(expectedCode, result.code)
result = server_read(self.config, "/1000/0/104")
self.assertEqual(expectedStdout, result.stdout)
self.assertEqual(expectedStderr, result.stderr)
self.assertEqual(expectedCode, result.code)
示例15: test_read_write_single_resource_string
def test_read_write_single_resource_string(self):
# test that a single string resource can be set and retrieved
manufacturer = "ACME Corp."
expectedStdout = "Object1000[/1000/0]:\n Resource100[/1000/0/100]: %s\n" % (manufacturer,)
expectedStderr = ""
expectedCode = 0
result = server_write(self.config, "/1000/0/100=\"%s\"" % (manufacturer,))
self.assertEqual(expectedCode, result.code)
result = server_read(self.config, "/1000/0/100")
self.assertEqual(expectedStdout, result.stdout)
self.assertEqual(expectedStderr, result.stderr)
self.assertEqual(expectedCode, result.code)