def validate_schema(event_dict) -> (bool, dict): """ Validates the schema using JSON Schema :return: returns a tuple of (bool, dict). The bool is if the execution was ok, dict returns the error event in case the execution failed """ ok, err = event_schema_validator.validate(event_dict) if not ok: err_event = get_error_ack("unknown", "unknown", content=AckErrorContent( error_code=EventError.MALFORMED_EVENT, details=err)) return False, err_event return True, None
def test_validate_comment_event(): event = copy.deepcopy(comment_event_dict) ok, err = event_schema_validator.validate(event) assert ok
def test_validate_comment_event_fail_missing_comment(): event = copy.deepcopy(comment_event_dict) event["content"].pop("comment") ok, err = event_schema_validator.validate(event) assert not ok
def test_validate_general_event_fail_missing_type(): event = copy.deepcopy(general_event_dict) event.pop("type") ok, err = event_schema_validator.validate(event) assert not ok
def test_validate_general_event_fail_invalid_type(): event = copy.deepcopy(general_event_dict) event['type'] = "l33t" ok, err = event_schema_validator.validate(event) assert not ok
def test_validate_general_event(): event = copy.deepcopy(general_event_dict) ok, err = event_schema_validator.validate(event) assert ok
def test_validate_general_event_fail_timestamp(): event = copy.deepcopy(general_event_dict) event['timestamp'] = "4640564060" ok, err = event_schema_validator.validate(event) assert not ok
def test_validate_start_event_fail_invalid_otp_type(): event = copy.deepcopy(start_event_dict) event["content"]["otp"] = 4320 ok, err = event_schema_validator.validate(event) assert not ok
def test_validate_vote_event_fail_missing_otp(): event = copy.deepcopy(vote_event_dict) event["content"].pop("vote") ok, err = event_schema_validator.validate(event) assert not ok
def test_validate_poll_event_three_option(): event = copy.deepcopy(poll_event_dict) event["content"]["options"] = ["yes", "no", "maybe"] ok, err = event_schema_validator.validate(event) assert ok
def test_validate_start_event_fail_missing_meeting(): event = copy.deepcopy(start_event_dict) event["content"].pop("meeting") ok, err = event_schema_validator.validate(event) assert not ok
def test_validate_poll_event_fail_one_option(): event = copy.deepcopy(poll_event_dict) event["content"]["options"] = ["yes"] ok, err = event_schema_validator.validate(event) assert not ok
def test_validate_poll_event_fail_missing_options(): event = copy.deepcopy(poll_event_dict) event["content"].pop("options") ok, err = event_schema_validator.validate(event) assert not ok
def test_validate_reply_event_fail_missing_reply(): event = copy.deepcopy(reply_event_dict) event["content"].pop("reply") ok, err = event_schema_validator.validate(event) assert not ok
def test_validate_discussion_event_fail_missing_patient(): event = copy.deepcopy(discussion_event_dict) event["content"].pop("patient") ok, err = event_schema_validator.validate(event) assert not ok
def test_validate_discussion_event(): event = copy.deepcopy(discussion_event_dict) ok, err = event_schema_validator.validate(event) assert ok