예제 #1
0
def OrganizationsResource(OrganizationResource):
    @CollectionResource.define(item_class=OrganizationResource,
                               primary_index=SimpleIndex(('id', int), ))
    class OrganizationsRes(CollectionResource):
        def __init__(self, parent, name):
            CollectionResource.__init__(self, parent, name, 'memory')

    return OrganizationsRes
예제 #2
0
파일: test_index.py 프로젝트: xica/hieratic
def test_simple_index_custom_delimiter(User):

    index = SimpleIndex(('organization_id', int), ('id', int), '/')
    user = User(organization_id=0, id=1, name='test')

    expected_key = '0/1'
    expected_dict = {'organization_id': 0, 'id': 1}

    assert index.make_key_from_dict(user._asdict()) == expected_key
    assert index.make_key_from_values(0, 1) == expected_key
    assert index.make_key_from_data(user) == expected_key
    assert index.make_key_dict(expected_key) == expected_dict
    assert index.make_key_dict_from_values(0, 1) == expected_dict
    assert index.make_key_dict_from_dict(user._asdict()) == expected_dict
    assert index.make_key_dict_from_data(user) == expected_dict
예제 #3
0
def UsersResource(UserResource):
    @CollectionResource.define(
        item_class=UserResource,
        primary_index=SimpleIndex(('organization_id', int), ('id', int)),
    )
    class UsersRes(CollectionResource):
        def __init__(self, parent, name):
            CollectionResource.__init__(self, parent, name, 'memory')

    return UsersRes
예제 #4
0
파일: test_index.py 프로젝트: xica/hieratic
def test_simple_index_custom_delimiter(User):

    index = SimpleIndex(('organization_id', int), ('id', int), '/')
    user = User(organization_id=0, id=1, name='test')

    expected_key = '0/1'
    expected_dict = {'organization_id': 0, 'id': 1}

    assert index.make_key_from_dict(user._asdict()) == expected_key
    assert index.make_key_from_values(0, 1) == expected_key
    assert index.make_key_from_data(user) == expected_key
    assert index.make_key_dict(expected_key) == expected_dict
    assert index.make_key_dict_from_values(0, 1) == expected_dict
    assert index.make_key_dict_from_dict(user._asdict()) == expected_dict
    assert index.make_key_dict_from_data(user) == expected_dict
예제 #5
0
파일: test_index.py 프로젝트: xica/hieratic
def test_simple_index(User):

    index = SimpleIndex(('organization_id', int), ('id', int))
    user = User(organization_id=0, id=1, name='test')

    expected_key = '0_1'
    expected_dict = {'organization_id': 0, 'id': 1}

    assert index.make_key_from_dict(user._asdict()) == expected_key
    assert index.make_key_from_values(0, 1) == expected_key
    assert index.make_key_from_data(user) == expected_key
    assert index.make_key_dict(expected_key) == expected_dict
    assert index.make_key_dict_from_values(0, 1) == expected_dict
    assert index.make_key_dict_from_dict(user._asdict()) == expected_dict
    assert index.make_key_dict_from_data(user) == expected_dict
    assert index.get_first_value_from_dict(user._asdict()) == 0
    assert index.get_first_value_from_data(user) == 0
    assert index.get_second_value_from_dict(user._asdict()) == 1
    assert index.get_second_value_from_data(user) == 1
예제 #6
0
파일: test_index.py 프로젝트: xica/hieratic
def test_simple_index(User):

    index = SimpleIndex(('organization_id', int), ('id', int))
    user = User(organization_id=0, id=1, name='test')

    expected_key = '0_1'
    expected_dict = {'organization_id': 0, 'id': 1}

    assert index.make_key_from_dict(user._asdict()) == expected_key
    assert index.make_key_from_values(0, 1) == expected_key
    assert index.make_key_from_data(user) == expected_key
    assert index.make_key_dict(expected_key) == expected_dict
    assert index.make_key_dict_from_values(0, 1) == expected_dict
    assert index.make_key_dict_from_dict(user._asdict()) == expected_dict
    assert index.make_key_dict_from_data(user) == expected_dict
    assert index.get_first_value_from_dict(user._asdict()) == 0
    assert index.get_first_value_from_data(user) == 0
    assert index.get_second_value_from_dict(user._asdict()) == 1
    assert index.get_second_value_from_data(user) == 1