def test_bad_json(self, dummy_request, test_uuids): from channelstream.wsgi_views.server import unsubscribe dummy_request.json_body = {} try: unsubscribe(dummy_request) except marshmallow.exceptions.ValidationError as exc: assert list(sorted(exc.messages.keys())) == ["channels", "conn_id"]
def test_bad_json(self, dummy_request, test_uuids): from channelstream.wsgi_views.server import unsubscribe dummy_request.json_body = {} try: unsubscribe(dummy_request) except marshmallow.exceptions.ValidationError as exc: assert list(sorted(exc.messages.keys())) == ["channels", "conn_id"]
def test_no_channels(self, dummy_request, test_uuids): from channelstream.wsgi_views.server import connect, unsubscribe dummy_request.json_body = { "username": "******", "conn_id": str(test_uuids[1]), "fresh_user_state": { "key": "foo" }, "user_state": { "bar": "baz" }, "state_public_keys": ["bar"], "channels": ["a"], "channel_configs": { "a": { "store_history": True, "history_size": 2 } }, } connect(dummy_request) dummy_request.json_body = { "conn_id": str(test_uuids[1]), "channels": ["a"] } result = unsubscribe(dummy_request) assert len(result["channels"]) == 0 assert result["channels_info"]["users"] == [] assert result["channels_info"]["channels"] == {}
def test_good_json(self, dummy_request, test_uuids): from channelstream.wsgi_views.server import connect, unsubscribe dummy_request.json_body = { "username": "******", "conn_id": str(test_uuids[1]), "fresh_user_state": { "key": "foo" }, "user_state": { "bar": "baz" }, "state_public_keys": ["bar"], "channels": ["a", "aB", "aC"], "channel_configs": { "a": { "store_history": True, "history_size": 2 } }, } connect(dummy_request) dummy_request.json_body = { "conn_id": str(test_uuids[1]), "channels": ["aC", "a"], } result = unsubscribe(dummy_request) assert sorted(result["channels"]) == sorted(["aB"])
def test_non_existing_channel(self, dummy_request, test_uuids): from channelstream.wsgi_views.server import connect, unsubscribe dummy_request.json_body = { "username": "******", "conn_id": str(test_uuids[1]), "fresh_user_state": {"key": "foo"}, "user_state": {"bar": "baz"}, "state_public_keys": ["bar"], "channels": ["a", "aB", "aC"], "channel_configs": {"a": {"store_history": True, "history_size": 2}}, } connect(dummy_request) dummy_request.json_body = {"conn_id": str(test_uuids[1]), "channels": ["d"]} result = unsubscribe(dummy_request) assert sorted(result["channels"]) == sorted(["a", "aB", "aC"])