OpenSlides/server/tests/unit/core/test_websocket.py

45 lines
1.2 KiB
Python
Raw Normal View History

2018-10-26 15:37:29 +02:00
import jsonschema
import pytest
from openslides.utils.websocket import schema
def test_notify_schema_validation():
# This raises a validaten error if it fails
2018-10-17 18:04:06 +02:00
message = {
"id": "test-message",
"type": "notify",
"content": {"name": "testname", "content": ["some content"]},
}
2018-10-26 15:37:29 +02:00
jsonschema.validate(message, schema)
def test_notify_schema_invalid_str_in_list():
message = {
2019-01-06 16:22:33 +01:00
"type": "notify",
"content": [{}, "testmessage"],
"id": "test_send_invalid_notify_str_in_list",
2018-10-26 15:37:29 +02:00
}
with pytest.raises(jsonschema.ValidationError):
jsonschema.validate(message, schema)
def test_notify_schema_invalid_no_elements():
message = {
2019-01-06 16:22:33 +01:00
"type": "notify",
"content": [],
"id": "test_send_invalid_notify_str_in_list",
2018-10-26 15:37:29 +02:00
}
with pytest.raises(jsonschema.ValidationError):
jsonschema.validate(message, schema)
def test_notify_schema_invalid_not_a_list():
message = {
2019-01-06 16:22:33 +01:00
"type": "notify",
"content": {"testmessage": "foobar, what else."},
"id": "test_send_invalid_notify_str_in_list",
2018-10-26 15:37:29 +02:00
}
with pytest.raises(jsonschema.ValidationError):
jsonschema.validate(message, schema)