Beispiel #1
0
def test_update_object(session: sessionmaker(),
                       objects: VersionedJSONSerializableObjectTables) -> None:
    user1 = User(name="User 1")
    session.add(user1)
    action = Action(id=0, schema={})
    session.add(action)
    session.commit()
    object1 = objects.create_object(action_id=action.id,
                                    data={},
                                    schema={},
                                    user_id=user1.id)
    assert [object1] == objects.get_current_objects()
    assert object1 == objects.get_current_object(object1.object_id)
    user2 = User(name="User 2")
    session.add(user2)
    session.commit()
    object2 = objects.update_object(object1.object_id,
                                    data={'test': 1},
                                    schema={},
                                    user_id=user2.id)
    assert object2.object_id == object1.object_id
    assert object2.version_id == 1
    assert object2.user_id is not None and object2.user_id == user2.id
    assert object2.data == {'test': 1}
    assert object2.schema == {}
    assert object2.utc_datetime < datetime.datetime.utcnow()
    assert object2.utc_datetime > datetime.datetime.utcnow(
    ) - datetime.timedelta(seconds=5)
    assert [object2] == objects.get_current_objects()
    assert object2 == objects.get_current_object(object2.object_id)
Beispiel #2
0
def test_get_current_objects_action_filter(
        session: sessionmaker(), objects: VersionedJSONSerializableObjectTables
) -> None:
    user = User(id=0, name="User")
    session.add(user)
    action1 = Action(id=1, schema={'x': 1})
    action2 = Action(id=2, schema={})
    session.add(action1)
    session.add(action2)
    session.commit()
    object1 = objects.create_object(action_id=action1.id,
                                    data={},
                                    schema={},
                                    user_id=user.id)
    object2 = objects.create_object(action_id=action2.id,
                                    data={},
                                    schema={},
                                    user_id=user.id)

    current_objects = objects.get_current_objects(
        action_table=Action.__table__,
        action_filter=(Action.schema == {
            'x': 1
        }))
    assert current_objects == [object1]
Beispiel #3
0
def test_get_current_objects(
        session: sessionmaker(), objects: VersionedJSONSerializableObjectTables
) -> None:
    user = User(id=0, name="User")
    session.add(user)
    action = Action(id=0, schema={})
    session.add(action)
    session.commit()
    object1 = objects.create_object(action_id=action.id,
                                    data={},
                                    schema={},
                                    user_id=user.id)
    object2 = objects.create_object(action_id=action.id,
                                    data={},
                                    schema={},
                                    user_id=user.id)
    current_objects = objects.get_current_objects()
    assert current_objects == [object1, object2
                               ] or current_objects == [object2, object1]
Beispiel #4
0
def test_update_object_invalid_data(
        session: sessionmaker(), objects: VersionedJSONSerializableObjectTables
) -> None:
    user = User(name="User 1")
    session.add(user)
    action = Action(id=0, schema={})
    session.add(action)
    session.commit()
    object1 = objects.create_object(action_id=action.id,
                                    data={},
                                    schema={},
                                    user_id=user.id)
    assert [object1] == objects.get_current_objects()
    assert object1 == objects.get_current_object(object1.object_id)
    schema = {'type': 'object', 'properties': {'test': {'type': 'integer'}}}
    with pytest.raises(jsonschema.exceptions.ValidationError):
        objects.update_object(object1.object_id,
                              data={'test': '1'},
                              schema=schema,
                              user_id=user.id)
Beispiel #5
0
def test_create_object(session: sessionmaker(),
                       objects: VersionedJSONSerializableObjectTables) -> None:
    user = User(id=0, name="User")
    session.add(user)
    action = Action(id=0, schema={})
    session.add(action)
    session.commit()
    object1 = objects.create_object(action_id=action.id,
                                    data={},
                                    schema={},
                                    user_id=user.id)
    assert object1.version_id == 0
    assert object1.action_id == action.id
    assert object1.user_id is not None and object1.user_id == user.id
    assert object1.data == {}
    assert object1.schema == {}
    assert object1.utc_datetime < datetime.datetime.utcnow()
    assert object1.utc_datetime > datetime.datetime.utcnow(
    ) - datetime.timedelta(seconds=5)
    assert [object1] == objects.get_current_objects()
    assert object1 == objects.get_current_object(object1.object_id)