コード例 #1
0
ファイル: test_validate.py プロジェクト: MayerBjoern/sampledb
def test_validate_object_reference_invalid_type():
    from sampledb.models.users import User, UserType
    from sampledb.models.actions import Action
    schema = {'title': 'Example', 'type': 'object_reference'}
    user = User("User", "*****@*****.**", UserType.OTHER)
    action = Action(sampledb.models.ActionType.SAMPLE_CREATION,
                    "Example Action",
                    schema={
                        "title": "Sample Information",
                        "type": "object",
                        "properties": {
                            "name": {
                                "title": "Sample Name",
                                "type": "text"
                            }
                        },
                        'required': ['name']
                    })

    sampledb.db.session.add(user)
    sampledb.db.session.add(action)
    sampledb.db.session.commit()

    object_id = create_object(
        data={'name': {
            '_type': 'text',
            'text': 'example'
        }},
        user_id=user.id,
        action_id=action.id)
    instance = object_id
    with pytest.raises(ValidationError):
        validate(instance, schema)
コード例 #2
0
def test_validate_sample():
    from sampledb.models.users import User, UserType
    from sampledb.models.actions import Action
    schema = {
        'title': 'Example',
        'type': 'sample'
    }
    user = User("User", "*****@*****.**", UserType.OTHER)
    action = Action(sampledb.models.ActionType.SAMPLE_CREATION, "Example Action", schema={
      "title": "Sample Information",
      "type": "object",
      "properties": {
        "name": {
          "title": "Sample Name",
          "type": "text"
        }
      },
      'required': ['name']
    })

    sampledb.db.session.add(user)
    sampledb.db.session.add(action)
    sampledb.db.session.commit()

    object = create_object(data={'name': {'_type': 'text', 'text': 'example'}}, user_id=user.id, action_id=action.id)
    instance = {
        '_type': 'sample',
        'object_id': object.id
    }
    validate(instance, schema)
コード例 #3
0
ファイル: test_validate.py プロジェクト: MayerBjoern/sampledb
def test_validate_measurement_wrong_object_id_type():
    from sampledb.models.users import User, UserType
    from sampledb.models.actions import Action
    schema = {'title': 'Example', 'type': 'measurement'}
    user = User("User", "*****@*****.**", UserType.OTHER)
    action = Action(sampledb.models.ActionType.MEASUREMENT,
                    "Example Action",
                    schema={
                        "title": "Measurement Information",
                        "type": "object",
                        "properties": {
                            "name": {
                                "title": "Measurement Name",
                                "type": "text"
                            }
                        },
                        "required": ["name"]
                    })

    sampledb.db.session.add(user)
    sampledb.db.session.add(action)
    sampledb.db.session.commit()

    object = create_object(data={'name': {
        '_type': 'text',
        'text': 'example'
    }},
                           user_id=user.id,
                           action_id=action.id)
    instance = {'_type': 'measurement', 'object_id': object}
    with pytest.raises(ValidationError):
        validate(instance, schema)
コード例 #4
0
def test_validate_object_reference_wrong_action():
    from sampledb.models.users import User, UserType
    from sampledb.models.actions import Action
    user = User("User", "*****@*****.**", UserType.OTHER)
    action = Action(sampledb.models.ActionType.SAMPLE_CREATION, "Example Action", schema={
      "title": "Sample Information",
      "type": "object",
      "properties": {
        "name": {
          "title": "Sample Name",
          "type": "text"
        }
      },
      "required": ["name"]
    })

    sampledb.db.session.add(user)
    sampledb.db.session.add(action)
    sampledb.db.session.commit()

    object = create_object(data={'name': {'_type': 'text', 'text': 'example'}}, user_id=user.id, action_id=action.id)
    instance = {
        '_type': 'object_reference',
        'object_id': object.id
    }

    schema = {
        'title': 'Example',
        'type': 'object_reference',
        'action_id': action.id
    }
    validate(instance, schema)

    schema = {
        'title': 'Example',
        'type': 'object_reference',
        'action_id': action.id + 1
    }
    with pytest.raises(ValidationError):
        validate(instance, schema)