Fix: Event types with periods cannot be fired using API

pull/2/head
Paulus Schoutsen 2013-11-09 14:23:26 -08:00
parent 94752f663e
commit 2f65751087
2 changed files with 11 additions and 10 deletions

View File

@ -152,8 +152,9 @@ class RequestHandler(BaseHTTPRequestHandler):
# /events
('GET', '/api/events', '_handle_get_api_events'),
('POST', re.compile(r'/api/events/(?P<event_type>\w+)'),
'_handle_fire_event'),
('POST',
re.compile(r'/api/events/(?P<event_type>[a-zA-Z\._0-9]+)'),
'_handle_fire_event'),
# Statis files
('GET', re.compile(r'/static/(?P<file>[a-zA-Z\._\-0-9\/]+)'),

View File

@ -87,14 +87,14 @@ class TestHTTPInterface(unittest.TestCase):
def test_debug_change_state(self):
""" Test if we can change a state from the debug interface. """
self.statemachine.set_state("test", "not_to_be_set_state")
self.statemachine.set_state("test.test", "not_to_be_set_state")
requests.post(_url(hah.URL_CHANGE_STATE),
data={"category": "test",
data={"category": "test.test",
"new_state":"debug_state_change2",
"api_password":API_PASSWORD})
self.assertEqual(self.statemachine.get_state("test")['state'],
self.assertEqual(self.statemachine.get_state("test.test")['state'],
"debug_state_change2")
def test_debug_fire_event(self):
@ -159,13 +159,13 @@ class TestHTTPInterface(unittest.TestCase):
def test_api_state_change(self):
""" Test if we can change the state of a category that exists. """
self.statemachine.set_state("test", "not_to_be_set_state")
self.statemachine.set_state("test.test", "not_to_be_set_state")
requests.post(_url(hah.URL_API_STATES_CATEGORY.format("test")),
requests.post(_url(hah.URL_API_STATES_CATEGORY.format("test.test")),
data={"new_state":"debug_state_change2",
"api_password":API_PASSWORD})
self.assertEqual(self.statemachine.get_state("test")['state'],
self.assertEqual(self.statemachine.get_state("test.test")['state'],
"debug_state_change2")
# pylint: disable=invalid-name
@ -196,10 +196,10 @@ class TestHTTPInterface(unittest.TestCase):
""" Helper method that will verify our event got called. """
test_value.append(1)
self.eventbus.listen_once("test_event_no_data", listener)
self.eventbus.listen_once("test.event_no_data", listener)
requests.post(
_url(hah.URL_API_EVENTS_EVENT.format("test_event_no_data")),
_url(hah.URL_API_EVENTS_EVENT.format("test.event_no_data")),
data={"api_password":API_PASSWORD})
# Allow the event to take place