def test_offset_objects(user: User, action: Action) -> None:
    for i in range(10):
        sampledb.logic.objects.create_object(
            action_id=action.id,
            data={'name': {
                '_type': 'text',
                'text': str(i)
            }},
            user_id=user.id)

    objects = sampledb.logic.objects.get_objects(
        filter_func=lambda data: True,
        sorting_func=object_sorting.ascending(object_sorting.object_id()))
    assert len(objects) == 10
    for i, object in enumerate(objects, start=0):
        assert object.data['name']['text'] == str(i)

    objects = sampledb.logic.objects.get_objects(
        filter_func=lambda data: True,
        sorting_func=object_sorting.ascending(object_sorting.object_id()),
        offset=6)
    assert len(objects) == 4
    for i, object in enumerate(objects, start=6):
        assert object.data['name']['text'] == str(i)

    objects = sampledb.logic.objects.get_objects(
        filter_func=lambda data: True,
        sorting_func=object_sorting.ascending(object_sorting.object_id()),
        limit=3,
        offset=6)
    assert len(objects) == 3
    for i, object in enumerate(objects, start=6):
        assert object.data['name']['text'] == str(i)
Beispiel #2
0
def test_order_by_object_id(user: User, action: Action) -> None:
    sampledb.logic.objects.create_object(
        action_id=action.id,
        data={'name': {
            '_type': 'text',
            'text': 'Name'
        }},
        user_id=user.id)
    sampledb.logic.objects.create_object(
        action_id=action.id,
        data={'name': {
            '_type': 'text',
            'text': 'Name'
        }},
        user_id=user.id)

    objects = sampledb.logic.objects.get_objects(
        filter_func=lambda data: True,
        sorting_func=object_sorting.ascending(object_sorting.object_id()))
    assert objects[0].id <= objects[1].id

    objects = sampledb.logic.objects.get_objects(
        filter_func=lambda data: True,
        sorting_func=object_sorting.descending(object_sorting.object_id()))
    assert objects[0].id >= objects[1].id
Beispiel #3
0
def test_order_by_text_property(user: User, action: Action) -> None:
    sampledb.logic.objects.create_object(
        action_id=action.id,
        data={'name': {
            '_type': 'text',
            'text': 'Name'
        }},
        user_id=user.id)
    sampledb.logic.objects.create_object(
        action_id=action.id,
        data={'name': {
            '_type': 'text',
            'text': 'ABC'
        }},
        user_id=user.id)

    objects = sampledb.logic.objects.get_objects(
        filter_func=lambda data: True,
        sorting_func=object_sorting.ascending(
            object_sorting.property_value("name")))
    assert objects[0].data['name']['text'] <= objects[1].data['name']['text']

    objects = sampledb.logic.objects.get_objects(
        filter_func=lambda data: True,
        sorting_func=object_sorting.descending(
            object_sorting.property_value("name")))
    assert objects[0].data['name']['text'] >= objects[1].data['name']['text']
Beispiel #4
0
def test_order_by_last_modification_date(user: User, action: Action) -> None:
    sampledb.logic.objects.create_object(
        action_id=action.id,
        data={'name': {
            '_type': 'text',
            'text': 'Name'
        }},
        user_id=user.id)
    sampledb.logic.objects.create_object(
        action_id=action.id,
        data={'name': {
            '_type': 'text',
            'text': 'Name'
        }},
        user_id=user.id)

    objects = sampledb.logic.objects.get_objects(
        filter_func=lambda data: True,
        sorting_func=object_sorting.ascending(
            object_sorting.last_modification_date()))
    assert objects[0].utc_datetime <= objects[1].utc_datetime

    objects = sampledb.logic.objects.get_objects(
        filter_func=lambda data: True,
        sorting_func=object_sorting.descending(
            object_sorting.last_modification_date()))
    assert objects[0].utc_datetime >= objects[1].utc_datetime

    sampledb.logic.objects.update_object(
        objects[1].object_id,
        data={'name': {
            '_type': 'text',
            'text': 'Name'
        }},
        user_id=user.id)

    objects = sampledb.logic.objects.get_objects(
        filter_func=lambda data: True,
        sorting_func=object_sorting.ascending(
            object_sorting.last_modification_date()))
    assert objects[0].utc_datetime <= objects[1].utc_datetime

    objects = sampledb.logic.objects.get_objects(
        filter_func=lambda data: True,
        sorting_func=object_sorting.descending(
            object_sorting.last_modification_date()))
    assert objects[0].utc_datetime >= objects[1].utc_datetime
def test_limit_objects(user: User, action: Action) -> None:
    for i in range(10):
        sampledb.logic.objects.create_object(
            action_id=action.id,
            data={'name': {
                '_type': 'text',
                'text': str(i)
            }},
            user_id=user.id)

    num_objects_found = []

    objects = sampledb.logic.objects.get_objects(
        filter_func=lambda data: True,
        sorting_func=object_sorting.ascending(object_sorting.object_id()),
        num_objects_found=num_objects_found)
    assert len(objects) == 10
    assert num_objects_found[0] == 10
    for i, object in enumerate(objects):
        assert object.data['name']['text'] == str(i)

    objects = sampledb.logic.objects.get_objects(
        filter_func=lambda data: True,
        sorting_func=object_sorting.ascending(object_sorting.object_id()),
        limit=4,
        num_objects_found=num_objects_found)
    assert len(objects) == 4
    assert num_objects_found[0] == 10
    for i, object in enumerate(objects):
        assert object.data['name']['text'] == str(i)

    objects = sampledb.logic.objects.get_objects(
        filter_func=lambda data: True,
        sorting_func=object_sorting.ascending(object_sorting.object_id()),
        limit=20,
        num_objects_found=num_objects_found)
    assert len(objects) == 10
    assert num_objects_found[0] == 10
    for i, object in enumerate(objects):
        assert object.data['name']['text'] == str(i)
Beispiel #6
0
def test_order_by_sample_property(user: User, action: Action) -> None:
    object1 = sampledb.logic.objects.create_object(
        action_id=action.id,
        data={'name': {
            '_type': 'text',
            'text': 'Name'
        }},
        user_id=user.id)
    object2 = sampledb.logic.objects.create_object(action_id=action.id,
                                                   data={
                                                       'name': {
                                                           '_type': 'text',
                                                           'text': 'Name'
                                                       },
                                                       'sample_attr': {
                                                           '_type': 'sample',
                                                           'object_id':
                                                           object1.id
                                                       }
                                                   },
                                                   user_id=user.id)
    sampledb.logic.objects.update_object(object_id=object1.object_id,
                                         data={
                                             'name': {
                                                 '_type': 'text',
                                                 'text': 'Name'
                                             },
                                             'sample_attr': {
                                                 '_type': 'sample',
                                                 'object_id': object2.id
                                             }
                                         },
                                         user_id=user.id)

    objects = sampledb.logic.objects.get_objects(
        filter_func=lambda data: True,
        sorting_func=object_sorting.ascending(
            object_sorting.property_value("sample_attr")))
    assert objects[0].data['sample_attr']['object_id'] <= objects[1].data[
        'sample_attr']['object_id']

    objects = sampledb.logic.objects.get_objects(
        filter_func=lambda data: True,
        sorting_func=object_sorting.descending(
            object_sorting.property_value("sample_attr")))
    assert objects[0].data['sample_attr']['object_id'] >= objects[1].data[
        'sample_attr']['object_id']
Beispiel #7
0
def test_order_by_datetime_property(user: User, action: Action) -> None:
    sampledb.logic.objects.create_object(action_id=action.id,
                                         data={
                                             'name': {
                                                 '_type': 'text',
                                                 'text': 'Name'
                                             },
                                             'datetime_attr': {
                                                 '_type':
                                                 'datetime',
                                                 'utc_datetime':
                                                 '2019-01-28 16:00:00'
                                             }
                                         },
                                         user_id=user.id)
    sampledb.logic.objects.create_object(action_id=action.id,
                                         data={
                                             'name': {
                                                 '_type': 'text',
                                                 'text': 'Name'
                                             },
                                             'datetime_attr': {
                                                 '_type':
                                                 'datetime',
                                                 'utc_datetime':
                                                 '2019-01-29 16:00:00'
                                             }
                                         },
                                         user_id=user.id)

    objects = sampledb.logic.objects.get_objects(
        filter_func=lambda data: True,
        sorting_func=object_sorting.ascending(
            object_sorting.property_value("datetime_attr")))
    assert objects[0].data['datetime_attr']['utc_datetime'] <= objects[1].data[
        'datetime_attr']['utc_datetime']

    objects = sampledb.logic.objects.get_objects(
        filter_func=lambda data: True,
        sorting_func=object_sorting.descending(
            object_sorting.property_value("datetime_attr")))
    assert objects[0].data['datetime_attr']['utc_datetime'] >= objects[1].data[
        'datetime_attr']['utc_datetime']
Beispiel #8
0
def test_order_by_quantity_property(user: User, action: Action) -> None:
    sampledb.logic.objects.create_object(action_id=action.id,
                                         data={
                                             'name': {
                                                 '_type': 'text',
                                                 'text': 'Name'
                                             },
                                             'quantity_attr': {
                                                 '_type': 'quantity',
                                                 'dimensionality': '[length]',
                                                 'magnitude_in_base_units': 42,
                                                 'units': 'm'
                                             }
                                         },
                                         user_id=user.id)
    object = sampledb.logic.objects.create_object(
        action_id=action.id,
        data={
            'name': {
                '_type': 'text',
                'text': 'Name'
            },
            'quantity_attr': {
                '_type': 'quantity',
                'dimensionality': '[length]',
                'magnitude_in_base_units': 17,
                'units': 'm'
            }
        },
        user_id=user.id)

    objects = sampledb.logic.objects.get_objects(
        filter_func=lambda data: True,
        sorting_func=object_sorting.ascending(
            object_sorting.property_value("quantity_attr")))
    assert objects[0].data['quantity_attr'][
        'magnitude_in_base_units'] <= objects[1].data['quantity_attr'][
            'magnitude_in_base_units']

    objects = sampledb.logic.objects.get_objects(
        filter_func=lambda data: True,
        sorting_func=object_sorting.descending(
            object_sorting.property_value("quantity_attr")))
    assert objects[0].data['quantity_attr'][
        'magnitude_in_base_units'] >= objects[1].data['quantity_attr'][
            'magnitude_in_base_units']

    sampledb.logic.objects.update_object(
        object_id=object.id,
        data={'name': {
            '_type': 'text',
            'text': 'Name'
        }},
        user_id=user.id)

    objects = sampledb.logic.objects.get_objects(
        filter_func=lambda data: True,
        sorting_func=object_sorting.ascending(
            object_sorting.property_value("quantity_attr")))
    assert 'quantity_attr' in objects[
        0].data and 'quantity_attr' not in objects[1].data

    objects = sampledb.logic.objects.get_objects(
        filter_func=lambda data: True,
        sorting_func=object_sorting.descending(
            object_sorting.property_value("quantity_attr")))
    assert 'quantity_attr' in objects[
        1].data and 'quantity_attr' not in objects[0].data