def test_not_found_json(self, dummy_request, test_uuids): from channelstream.wsgi_views.server import user_state dummy_request.json_body = {"user": "******"} with pytest.raises(marshmallow.exceptions.ValidationError) as excinfo: user_state(dummy_request) assert excinfo.value.messages == {"user": ["Unknown user"]}
def test_bad_json(self, dummy_request, test_uuids): from channelstream.wsgi_views.server import user_state dummy_request.json_body = {} with pytest.raises(marshmallow.exceptions.ValidationError) as excinfo: user_state(dummy_request) assert excinfo.value.messages == {"user": ["Missing data for required field."]}
def test_bad_json(self, dummy_request, test_uuids): from channelstream.wsgi_views.server import user_state dummy_request.json_body = {} with pytest.raises(marshmallow.exceptions.ValidationError) as excinfo: user_state(dummy_request) assert excinfo.value.messages == { "user": ["Missing data for required field."] }
def test_good_json_no_public_keys(self, dummy_request, test_uuids): from channelstream.wsgi_views.server import user_state self._connect_user(dummy_request, test_uuids) dummy_request.json_body = { "user": "******", "user_state": {"bar": 2, "private": "im_private"}, } result = user_state(dummy_request) sorted_keys = sorted(["bar", "key", "private"]) assert sorted_keys == sorted(result["user_state"].keys()) assert result["user_state"]["private"] == "im_private" assert result["public_keys"] == ["bar"] sorted_changed = sorted([x["key"] for x in result["changed_state"]]) assert sorted_changed == sorted(["bar", "private"])
def test_good_json_no_public_keys(self, dummy_request, test_uuids): from channelstream.wsgi_views.server import user_state self._connect_user(dummy_request, test_uuids) dummy_request.json_body = { "user": "******", "user_state": { "bar": 2, "private": "im_private" }, } result = user_state(dummy_request) sorted_keys = sorted(["bar", "key", "private"]) assert sorted_keys == sorted(result["user_state"].keys()) assert result["user_state"]["private"] == "im_private" assert result["public_keys"] == ["bar"] sorted_changed = sorted([x["key"] for x in result["changed_state"]]) assert sorted_changed == sorted(["bar", "private"])