コード例 #1
0
def test_assign_location(user: User, object: Object):
    object_location_assignment = locations.get_current_object_location_assignment(
        object.id)
    assert object_location_assignment is None
    location = locations.create_location("Location",
                                         "This is an example location", None,
                                         user.id)
    locations.assign_location_to_object(
        object.id, location.id, None, user.id,
        "This object is stored at this location")
    object_location_assignment = locations.get_current_object_location_assignment(
        object.id)
    assert object_location_assignment.object_id == object.id
    assert object_location_assignment.location_id == location.id
    assert object_location_assignment.user_id == user.id
    assert object_location_assignment.description == "This object is stored at this location"
    user_log_entries = user_log.get_user_log_entries(user.id)
    assert [
        e for e in user_log_entries
        if e.data.get('object_location_assignment_id',
                      -1) == object_location_assignment.id
        and e.type == UserLogEntryType.ASSIGN_LOCATION
    ]
    object_log_entries = object_log.get_object_log_entries(object.id)
    assert [
        e for e in object_log_entries
        if e.data.get('object_location_assignment_id',
                      -1) == object_location_assignment.id
        and e.type == ObjectLogEntryType.ASSIGN_LOCATION
    ]
コード例 #2
0
def test_assign_location_which_does_not_exist(user: User, object: Object):
    with pytest.raises(errors.LocationDoesNotExistError):
        locations.assign_location_to_object(
            object.id, 42, None, user.id,
            "This object is stored at this location")
    object_location_assignment = locations.get_current_object_location_assignment(
        object.id)
    assert object_location_assignment is None
コード例 #3
0
def test_object_responsibility_confirmation(user: User, object: Object, app):
    other_user = User(name='Other User',
                      email="*****@*****.**",
                      type=UserType.PERSON)
    sampledb.db.session.add(other_user)
    sampledb.db.session.commit()
    server_name = app.config['SERVER_NAME']
    app.config['SERVER_NAME'] = 'localhost'
    with app.app_context():
        locations.assign_location_to_object(object.id, None, user.id,
                                            other_user.id, "")
    app.config['SERVER_NAME'] = server_name
    object_location_assignment = locations.get_current_object_location_assignment(
        object.id)
    assert not object_location_assignment.confirmed
    locations.confirm_object_responsibility(object_location_assignment.id)
    object_location_assignment = locations.get_current_object_location_assignment(
        object.id)
    assert object_location_assignment.confirmed