예제 #1
0
파일: test_metrics.py 프로젝트: iotest3/new
 def test_find_metrics(self):
     from osi.utilities.metrics import find_metrics
     site = karltesting.DummyModel()
     metrics = karltesting.DummyModel()
     site['metrics'] = metrics
     result = find_metrics(site)
     self.failUnless(result is metrics)
예제 #2
0
    def test_it_inform_moderators(self):
        from pyramid.interfaces import ISettings
        karltesting.registerUtility(karltesting.DummySettings(), ISettings)

        site = karltesting.DummyModel()
        site['fred'] = profile = karltesting.DummyProfile()
        profile.title = 'Fred Flintstone'
        profile.email = '*****@*****.**'
        site['clint'] = moderator = karltesting.DummyProfile()
        moderator.title = 'Clint'
        moderator.email = '*****@*****.**'

        site.users = karltesting.DummyUsers()
        site.users.add('fred', 'fred', 'password', set(
            ('group.community:Test1:members',
             'group.community:Test2:members',
             'group.community:Test2:moderators',
             'group.SomeGroup')))
        site.users.add('clint', 'clint', 'password', set(
            ('group.community:Test1:moderators',
             'group.community:Test2:moderators')))

        site['communities'] = communities = karltesting.DummyModel()
        communities['Test1'] = karltesting.DummyModel(title='Test One')
        communities['Test2'] = karltesting.DummyModel(title='Test Two')

        mailer = karltesting.registerDummyMailer()
        renderer = karltesting.registerDummyRenderer(
            'templates/email_notify_former_staff.pt'
        )

        self._call_fut(profile)

        removed = site.users.removed_groups
        self.failIf(('fred', 'group.SomeGroup') in removed)
        self.failUnless(('fred', 'group.community:Test1:members') in removed)
        self.failUnless(('fred', 'group.community:Test2:moderators')
                        in removed)

        self.assertEqual(len(mailer), 1, mailer)
        sent = mailer[0]
        self.assertEqual(sent.mto, ['Clint <*****@*****.**>'])
        self.assertEqual(renderer.name, 'Fred Flintstone')
        self.assertEqual(renderer.communities, [
            {'unremove_url': 'http://offline.example.com/app/communities/Test1'
                             '/members/add_existing.html?user_id=fred',
             'title': 'Test One'},
            {'unremove_url': 'http://offline.example.com/app/communities/Test2'
                             '/members/add_existing.html?user_id=fred',
             'title': 'Test Two'}]
        )
예제 #3
0
파일: test_metrics.py 프로젝트: iotest3/new
    def test_profile(self):
        from osi.utilities.metrics import collect_profile_metrics
        from zope.interface import Interface
        from karl.models.interfaces import ICatalogSearch

        karltesting.registerAdapter(DummyProfileSearch, (Interface),
                                    ICatalogSearch)
        dummy_users = DummyUsers()
        site = karltesting.DummyModel()
        site.users = dummy_users

        result = collect_profile_metrics(site, 1985, 1)
        self.assertEqual(
            {
                'biff': {
                    'created': 1,
                    'is_staff': False,
                    'total': 2
                },
                'george': {
                    'created': 1,
                    'is_staff': True,
                    'total': 2
                }
            }, result)
예제 #4
0
파일: test_metrics.py 프로젝트: iotest3/new
    def test_user_metrics(self):
        from osi.utilities.metrics import collect_user_metrics
        from zope.interface import Interface
        from karl.models.interfaces import ICatalogSearch

        karltesting.registerAdapter(DummyUserSearch, (Interface),
                                    ICatalogSearch)
        dummy_users = DummyUsers()
        site = karltesting.DummyModel()
        site.users = dummy_users

        result = collect_user_metrics(site, 1985, 1, DummyWorkflow)
        self.assertEqual(
            {
                'created': {
                    'active': 2,
                    'affiliate': 2,
                    'core_office': 0,
                    'former': 0,
                    'national_foundation': 1,
                    'staff': 1,
                    'total': 3
                },
                'total': {
                    'active': 3,
                    'affiliate': 2,
                    'core_office': 1,
                    'former': 1,
                    'national_foundation': 1,
                    'staff': 1,
                    'total': 4
                }
            }, result)
예제 #5
0
파일: test_lock.py 프로젝트: iotest3/new
 def test_lock(self):
     from datetime import datetime
     from karl.utilities import lock
     date = datetime(1985, 1, 1)
     context = karltesting.DummyModel()
     lock.lock(context, 'foo', date)
     self.failUnless(lock.is_locked(context, date))
예제 #6
0
파일: test_lock.py 프로젝트: iotest3/new
 def test_lockinfo(self):
     from datetime import datetime
     from karl.utilities import lock
     past = datetime(1985, 1, 1, 0, 0, 1)
     context = karltesting.DummyModel()
     lock.lock(context, 'foo', past)
     lockinfo = lock.lock_info(context)
     self.assertEqual('foo', lockinfo['userid'])
     self.assertEqual(past, lockinfo['time'])
예제 #7
0
파일: test_lock.py 프로젝트: iotest3/new
 def test_lock_timeout(self):
     from datetime import datetime
     from karl.utilities import lock
     past = datetime(1955, 1, 1, 0, 0, 1)
     past_plus_1 = datetime(1955, 1, 1, 0, 0, 2)
     future = datetime(1985, 1, 1)
     context = karltesting.DummyModel()
     lock.lock(context, 'foo', past)
     self.failUnless(lock.is_locked(context, past_plus_1))
     self.failIf(lock.is_locked(context, future))
예제 #8
0
파일: test_lock.py 프로젝트: iotest3/new
 def test_lockdata(self):
     from datetime import datetime
     from karl.utilities import lock
     past = datetime(1985, 1, 1, 0, 0, 1)
     now = datetime(1985, 1, 1, 0, 0, 10)
     context = karltesting.DummyModel()
     request = testing.DummyRequest()
     site = karltesting.DummyRoot()
     site['bar'] = context
     lock.lock(context, 'foo', past)
     lockdata = lock.lock_info_for_view(context, request, now)
     self.failUnless(lockdata['is_locked'])
예제 #9
0
    def setUp(self):
        testing.cleanUp()

        from karl.models.contentfeeds import SiteEvents

        self.root = root = karltesting.DummyModel()
        root['profiles'] = karltesting.DummyModel()
        root.users = karltesting.DummyUsers()

        root['a'] = karltesting.DummyModel(creator='chris')
        root['b'] = karltesting.DummyModel(modified_by='chris')

        root.events = events = SiteEvents()
        events.push(userid='chris', profile_url='/profiles/chris',
                    name='Chris R', anumber=123)

        class DummySearchAdapter(object):
            def __init__(self, context):
                pass

            def __call__(self, **kw):
                resolver = lambda x: root.get(x)
                if kw.get('creator') == 'chris':
                    return 1, ['a'], resolver
                if kw.get('modified_by') == 'chris':
                    return 1, ['b'], resolver
                return 0, [], resolver

        from zope.interface import Interface
        from karl.models.interfaces import ICatalogSearch
        karltesting.registerAdapter(DummySearchAdapter, (Interface, Interface),
                                ICatalogSearch)
        karltesting.registerAdapter(DummySearchAdapter, (Interface,),
                                ICatalogSearch)

        root.catalog = catalog = karltesting.DummyModel()
        catalog['creator'] =  DummyCatalogIndex()
        catalog['modified_by'] =  DummyCatalogIndex()
예제 #10
0
    def test_it_dont_inform_moderators(self):
        site = karltesting.DummyModel()
        site['fred'] = profile = karltesting.DummyProfile()
        site.users = karltesting.DummyUsers()
        site.users.add('fred', 'fred', 'password', set(
            ('group.community:Test1:members',
             'group.community:Test2:moderators',
             'group.SomeGroup')))

        self._call_fut(profile, False)

        removed = site.users.removed_groups
        self.failIf(('fred', 'group.SomeGroup') in removed)
        self.failUnless(('fred', 'group.community:Test1:members') in removed)
        self.failUnless(('fred', 'group.community:Test2:moderators')
                        in removed)
예제 #11
0
파일: test_metrics.py 프로젝트: iotest3/new
    def test_community_metrics(self):
        from osi.utilities.metrics import collect_community_metrics
        from zope.interface import Interface
        from karl.models.interfaces import ICatalogSearch

        karltesting.registerAdapter(DummyCommunitySearch, (Interface),
                                    ICatalogSearch)

        site = karltesting.DummyModel()
        result = collect_community_metrics(site, 1985, 1)
        self.assertEqual(
            {
                'created': {
                    u'flux': {
                        'blogs': 2,
                        'comments': 7,
                        'created': 1985,
                        'last_activity': 1985,
                        'security_state': 'public',
                        'events': 3,
                        'files': 5,
                        'members': 3,
                        'moderators': 2,
                        'title': u'Flux Capacitor',
                        'total': 21,
                        'wikis': 4
                    }
                },
                'total': {
                    u'flux': {
                        'blogs': 4,
                        'comments': 14,
                        'created': 1985,
                        'last_activity': 1985,
                        'security_state': 'public',
                        'events': 6,
                        'files': 10,
                        'members': 3,
                        'moderators': 2,
                        'title': u'Flux Capacitor',
                        'total': 42,
                        'wikis': 8
                    }
                }
            }, result)
예제 #12
0
 def test_no_args_no_current(self):
     root = testing.DummyModel()
     previous, now = self._callFUT(root)
     self.assertEqual(previous, '')
     self.assertEqual(now, '')
     self.failIf('site_announcement' in root.__dict__)
예제 #13
0
파일: test_lock.py 프로젝트: iotest3/new
 def test_lock_owner(self):
     context = karltesting.DummyModel()
     from karl.utilities import lock
     lock.lock(context, 'foo')
     self.failUnless(lock.owns_lock(context, 'foo'))
     self.failIf(lock.owns_lock(context, 'bar'))
예제 #14
0
파일: test_metrics.py 프로젝트: iotest3/new
 def test_find_metrics_none(self):
     from osi.utilities.metrics import find_metrics
     site = karltesting.DummyModel()
     result = find_metrics(site)
     self.failUnless(result is None)
예제 #15
0
 def test_w_new_value_multiple(self):
     root = testing.DummyModel(site_announcement='TESTING')
     previous, now = self._callFUT(root, 'MULTIPLE', 'ARGUMENTS')
     self.assertEqual(previous, 'TESTING')
     self.assertEqual(now, 'MULTIPLE ARGUMENTS')
     self.assertEqual(root.site_announcement, 'MULTIPLE ARGUMENTS')
예제 #16
0
 def test_w_new_value(self):
     root = testing.DummyModel(site_announcement='TESTING')
     previous, now = self._callFUT(root, 'UPDATED')
     self.assertEqual(previous, 'TESTING')
     self.assertEqual(now, 'UPDATED')
     self.assertEqual(root.site_announcement, 'UPDATED')
예제 #17
0
파일: test_lock.py 프로젝트: iotest3/new
 def test_clear(self):
     from karl.utilities import lock
     context = karltesting.DummyModel()
     lock.lock(context, 'foo')
     lock.clear(context)
     self.failIf(lock.is_locked(context))
예제 #18
0
 def test_no_args_returns_current(self):
     root = testing.DummyModel(site_announcement='TESTING')
     previous, now = self._callFUT(root)
     self.assertEqual(previous, 'TESTING')
     self.assertEqual(now, 'TESTING')
     self.assertEqual(root.site_announcement, 'TESTING')
예제 #19
0
파일: test_lock.py 프로젝트: iotest3/new
 def test_unlocked_by_default(self):
     from karl.utilities import lock
     context = karltesting.DummyModel()
     self.failIf(lock.is_locked(context))