Changes between Initial Version and Version 1 of Ticket #2605


Ignore:
Timestamp:
06/27/12 10:30:46 (22 months ago)
Author:
ross
Comment:

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #2605

    • Property Status changed from new to accepted
  • Ticket #2605 – Description

    initial v1  
    1212detect the detached session and bypass the cache in this case? 
    1313 
    14 diff --git a/ckan/tests/models/test_user.py b/ckan/tests/models/test_user.py 
    15 index a49759a..ffd3449 100644 
    16 --- a/ckan/tests/models/test_user.py 
    17 +++ b/ckan/tests/models/test_user.py 
    18 @@ -52,3 +52,50 @@ class TestUser: 
    19          out = model.User.get(u'http:/sandra.owndomain.com/') 
    20          assert out 
    21          assert out.fullname == u'Sandra' 
    22 + 
    23 +def to_names(domain_obj_list): 
    24 +    '''Takes a list of domain objects and returns a corresponding list 
    25 +    of their names.''' 
    26 +    objs = [] 
    27 +    for obj in domain_obj_list: 
    28 +        objs.append(obj.name if obj else None) 
    29 +    return objs 
    30 + 
    31 +class TestUserGroups: 
    32 +    @classmethod 
    33 +    def setup_class(self): 
    34 +        CreateTestData.create_arbitrary([{'name': 'testpkg'}], 
    35 +                                        extra_user_names=['brian', 'sandra']) 
    36 +        CreateTestData.create_groups([ 
    37 +            {'name': 'grp1', 
    38 +             'phone': '1234', 
    39 +             } 
    40 +            ]) 
    41 +        model.repo.new_revision() 
    42 +        grp1 = model.Group.by_name(u'grp1') 
    43 +        brian = model.User.by_name(u'brian') 
    44 +        model.Session.add(model.Member(group=grp1, 
    45 +                                       table_id=brian.id, 
    46 +                                       table_name='user', 
    47 +                                       capacity='admin') 
    48 +                         ) 
    49 +        model.repo.commit_and_remove() 
    50 +         
    51 +    @classmethod 
    52 +    def teardown_class(self): 
    53 +        model.repo.rebuild_db() 
    54 +     
    55 +    def test_get_groups(self): 
    56 +        brian = model.User.by_name(u'brian') 
    57 +        groups = brian.get_groups() 
    58 +        assert_equal(to_names(groups), ['grp1']) 
    59 +        assert_equal(groups[0].extras, {'phone': '1234'}) 
    60 + 
    61 +        # check cache works between sessions 
    62 +        model.Session.expunge_all() 
    63 +        #don't refresh brian user since this is how c.user works 
    64 +        # i.e. don't do this: brian = model.User.by_name(u'brian') 
    65 +        groups = brian.get_groups() 
    66 +        assert_equal(to_names(groups), ['grp1']) 
    67 +        assert_equal(groups[0].extras, {'phone': '1234'}) 
    68 + 
     14diff at https://gist.github.com/3003117