More tests improvements
This commit is contained in:
parent
ca90060ba1
commit
4ed80a0945
4 changed files with 38 additions and 16 deletions
|
@ -7,7 +7,7 @@ procedure.write_file:
|
||||||
event.hook.OnCustomEvent:
|
event.hook.OnCustomEvent:
|
||||||
if:
|
if:
|
||||||
type: platypush.message.event.custom.CustomEvent
|
type: platypush.message.event.custom.CustomEvent
|
||||||
subtype: platypush_test_procedure_from_event
|
subtype: test_procedure
|
||||||
then:
|
then:
|
||||||
- action: procedure.write_file
|
- action: procedure.write_file
|
||||||
args:
|
args:
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
import pytest
|
||||||
|
|
||||||
from platypush.event.hook import EventCondition
|
from platypush.event.hook import EventCondition
|
||||||
from platypush.message.event.ping import PingEvent
|
from platypush.message.event.ping import PingEvent
|
||||||
|
|
||||||
|
@ -25,4 +27,8 @@ def test_event_parse():
|
||||||
assert not result.is_match
|
assert not result.is_match
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
pytest.main()
|
||||||
|
|
||||||
|
|
||||||
# vim:sw=4:ts=4:et:
|
# vim:sw=4:ts=4:et:
|
||||||
|
|
|
@ -59,4 +59,8 @@ def test_request_with_wrong_credentials(base_url, expected_login_redirect):
|
||||||
assert expected_login_redirect == response.url, 'A request with wrong credentials should fail'
|
assert expected_login_redirect == response.url, 'A request with wrong credentials should fail'
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
pytest.main()
|
||||||
|
|
||||||
|
|
||||||
# vim:sw=4:ts=4:et:
|
# vim:sw=4:ts=4:et:
|
||||||
|
|
|
@ -7,29 +7,37 @@ from platypush.message.event.custom import CustomEvent
|
||||||
|
|
||||||
from .utils import register_user, send_request
|
from .utils import register_user, send_request
|
||||||
|
|
||||||
|
tmp_files = []
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(scope='module', autouse=True)
|
@pytest.fixture(scope='module', autouse=True)
|
||||||
def user(*_):
|
def user(*_):
|
||||||
register_user()
|
register_user()
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(scope='module')
|
@pytest.fixture(scope='module', autouse=True)
|
||||||
def tmp_file(*_):
|
def tmp_file(*_):
|
||||||
|
n_files = 2
|
||||||
|
for _ in range(n_files):
|
||||||
tmp_file = tempfile.NamedTemporaryFile(prefix='platypush-test-procedure-', suffix='.txt', delete=False)
|
tmp_file = tempfile.NamedTemporaryFile(prefix='platypush-test-procedure-', suffix='.txt', delete=False)
|
||||||
yield tmp_file
|
tmp_files.append(tmp_file.name)
|
||||||
if os.path.isfile(tmp_file.name):
|
|
||||||
os.unlink(tmp_file.name)
|
yield
|
||||||
|
|
||||||
|
for f in tmp_files:
|
||||||
|
if os.path.isfile(f):
|
||||||
|
os.unlink(f)
|
||||||
|
|
||||||
|
|
||||||
def check_file_content(expected_content: str, tmp_file):
|
def check_file_content(expected_content: str, tmp_file: str):
|
||||||
assert os.path.isfile(tmp_file.name), 'The expected output file was not created'
|
assert os.path.isfile(tmp_file), 'The expected output file was not created'
|
||||||
with open(tmp_file.name, 'r') as f:
|
with open(tmp_file, 'r') as f:
|
||||||
content = f.read()
|
content = f.read()
|
||||||
|
|
||||||
assert content == expected_content, 'The output file did not contain the expected text'
|
assert content == expected_content, 'The output file did not contain the expected text'
|
||||||
|
|
||||||
|
|
||||||
def test_procedure_call(tmp_file):
|
def test_procedure_call(base_url):
|
||||||
"""
|
"""
|
||||||
Test the result of a procedure invoked directly over HTTP.
|
Test the result of a procedure invoked directly over HTTP.
|
||||||
"""
|
"""
|
||||||
|
@ -37,23 +45,27 @@ def test_procedure_call(tmp_file):
|
||||||
send_request(
|
send_request(
|
||||||
action='procedure.write_file',
|
action='procedure.write_file',
|
||||||
args={
|
args={
|
||||||
'file': tmp_file.name,
|
'file': tmp_files[0],
|
||||||
'content': output_text,
|
'content': output_text,
|
||||||
})
|
})
|
||||||
|
|
||||||
check_file_content(expected_content=output_text, tmp_file=tmp_file)
|
check_file_content(expected_content=output_text, tmp_file=tmp_files[0])
|
||||||
|
|
||||||
|
|
||||||
def test_procedure_from_event(app, tmp_file):
|
def test_procedure_from_event(app, base_url):
|
||||||
"""
|
"""
|
||||||
Test the result of a procedure triggered by an event.
|
Test the result of a procedure triggered by an event.
|
||||||
"""
|
"""
|
||||||
output_text = 'Procedure from event test'
|
output_text = 'Procedure from event test'
|
||||||
event_type = 'platypush_test_procedure_from_event'
|
event_type = 'test_procedure'
|
||||||
# noinspection PyUnresolvedReferences
|
# noinspection PyUnresolvedReferences
|
||||||
app.bus.post(CustomEvent(subtype=event_type, file=tmp_file.name, content=output_text))
|
app.bus.post(CustomEvent(subtype=event_type, file=tmp_files[1], content=output_text))
|
||||||
time.sleep(3)
|
time.sleep(3)
|
||||||
check_file_content(expected_content=output_text, tmp_file=tmp_file)
|
check_file_content(expected_content=output_text, tmp_file=tmp_files[1])
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
pytest.main()
|
||||||
|
|
||||||
|
|
||||||
# vim:sw=4:ts=4:et:
|
# vim:sw=4:ts=4:et:
|
||||||
|
|
Loading…
Reference in a new issue