Skip to content

Commit

Permalink
Merge pull request #22 from JKRhb/op-types
Browse files Browse the repository at this point in the history
Update form op types and tests
  • Loading branch information
agmangas committed Apr 29, 2021
2 parents cec61d4 + a46cfe2 commit a77d51f
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 19 deletions.
8 changes: 4 additions & 4 deletions tests/protocols/http/test_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,31 +33,31 @@ def _get_property_href(exp_thing, prop_name, server):

prop = exp_thing.thing.properties[prop_name]
prop_forms = server.build_forms("localhost", prop)
return next(item.href for item in prop_forms if item.op == InteractionVerbs.READ_PROPERTY)
return next(item.href for item in prop_forms if InteractionVerbs.READ_PROPERTY in item.op)


def _get_property_observe_href(exp_thing, prop_name, server):
"""Helper function to retrieve the Property subscription href."""

prop = exp_thing.thing.properties[prop_name]
prop_forms = server.build_forms("localhost", prop)
return next(item.href for item in prop_forms if item.op == InteractionVerbs.OBSERVE_PROPERTY)
return next(item.href for item in prop_forms if InteractionVerbs.OBSERVE_PROPERTY in item.op)


def _get_action_href(exp_thing, action_name, server):
"""Helper function to retrieve the Property subscription href."""

action = exp_thing.thing.actions[action_name]
action_forms = server.build_forms("localhost", action)
return next(item.href for item in action_forms if item.op == InteractionVerbs.INVOKE_ACTION)
return next(item.href for item in action_forms if InteractionVerbs.INVOKE_ACTION in item.op)


def _get_event_observe_href(exp_thing, event_name, server):
"""Helper function to retrieve the Event subscription href."""

event = exp_thing.thing.events[event_name]
event_forms = server.build_forms("localhost", event)
return next(item.href for item in event_forms if item.op == InteractionVerbs.SUBSCRIBE_EVENT)
return next(item.href for item in event_forms if InteractionVerbs.SUBSCRIBE_EVENT in item.op)


def test_property_get(http_server):
Expand Down
19 changes: 6 additions & 13 deletions wotpy/protocols/http/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,19 +109,12 @@ def _build_forms_property(self, proprty, hostname):
self.scheme, hostname.rstrip("/").lstrip("/"), self.port,
proprty.thing.url_name, proprty.url_name)

form_read = Form(
form_read_write = Form(
interaction=proprty,
protocol=self.protocol,
href=href_read_write,
content_type=MediaTypes.JSON,
op=InteractionVerbs.READ_PROPERTY)

form_write = Form(
interaction=proprty,
protocol=self.protocol,
href=href_read_write,
content_type=MediaTypes.JSON,
op=InteractionVerbs.WRITE_PROPERTY)
op=[InteractionVerbs.READ_PROPERTY, InteractionVerbs.WRITE_PROPERTY])

href_observe = "{}/subscription".format(href_read_write)

Expand All @@ -130,9 +123,9 @@ def _build_forms_property(self, proprty, hostname):
protocol=self.protocol,
href=href_observe,
content_type=MediaTypes.JSON,
op=InteractionVerbs.OBSERVE_PROPERTY)
op=[InteractionVerbs.OBSERVE_PROPERTY])

return [form_read, form_write, form_observe]
return [form_read_write, form_observe]

def _build_forms_action(self, action, hostname):
"""Builds and returns the HTTP Form instances for the given Action interaction."""
Expand All @@ -146,7 +139,7 @@ def _build_forms_action(self, action, hostname):
protocol=self.protocol,
href=href_invoke,
content_type=MediaTypes.JSON,
op=InteractionVerbs.INVOKE_ACTION)
op=[InteractionVerbs.INVOKE_ACTION])

return [form_invoke]

Expand All @@ -162,7 +155,7 @@ def _build_forms_event(self, event, hostname):
protocol=self.protocol,
href=href_observe,
content_type=MediaTypes.JSON,
op=InteractionVerbs.SUBSCRIBE_EVENT)
op=[InteractionVerbs.SUBSCRIBE_EVENT])

return [form_observe]

Expand Down
2 changes: 1 addition & 1 deletion wotpy/wot/form.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,5 @@ def id(self):
self.protocol,
self.href,
self.content_type,
self.op
tuple(self.op) if isinstance(self.op, list) else self.op
))
10 changes: 9 additions & 1 deletion wotpy/wot/validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,15 @@
"type": "string",
"default": "application/json"
},
"op": {"type": "string"},
"op": { "oneOf": [
{
"type": "string"
},
{
"type": "array",
"items": {"type": "string"}
}
]},
"subprotocol": {"type": "string"},
"security": {
"type": "array",
Expand Down

0 comments on commit a77d51f

Please sign in to comment.