Beispiel #1
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 #2
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 #3
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 #4
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