Exemplo n.º 1
0
    def test_generation(self):
        locmem_cache = cache.get_cache(
            'django.core.cache.backends.locmem.LocMemCache')
        manager = DatasourceCacheManager()
        with mock.patch('ereports.engine.cache._cache', locmem_cache):
            monitor_model(Permission)
            reset(Permission)

            TestDatasource = type(
                'TestDatasource', (Datasource, ), {
                    'model': Permission,
                    'dependent_models': [ContentType],
                    'use_cache': True,
                    'columns': ['id', 'name']
                })

            ds1 = TestDatasource.as_datasource()
            k1 = manager.get_key(ds1)
            self.assertTrue(
                k1.startswith(
                    'ereports/1/django.contrib.auth.models.Permission/0'
                    '/django.contrib.contenttypes.models.ContentType/0/'), k1)
            Permission.objects.filter(pk=1).delete()
            k2 = manager.get_key(ds1)
            self.assertTrue(
                k2.startswith(
                    'ereports/1/django.contrib.auth.models.Permission/1'
                    '/django.contrib.contenttypes.models.ContentType/0/'), k2)
Exemplo n.º 2
0
    def test_get_key(self):
        manager = DatasourceCacheManager()
        dummy_cache = cache.get_cache('django.core.cache.backends.dummy.DummyCache')
        dummy_cache.clear()
        with mock.patch('ereports.engine.cache._cache', dummy_cache):
            monitor_model(Permission)
            reset(Permission)

            TestDatasource = type('TestDatasource', (Datasource,), {'model': Permission,
                                                                    'dependent_models': [ContentType],
                                                                    'use_cache': True,
                                                                    'columns': ['id', 'name']})
            ds1 = TestDatasource.as_datasource()
            k = manager.get_key(ds1)
            self.assertTrue(k.startswith('ereports/1/django.contrib.auth.models.Permission/0'
                                         '/django.contrib.contenttypes.models.ContentType/0/'), k)
Exemplo n.º 3
0
    def test_generation(self):
        locmem_cache = cache.get_cache('django.core.cache.backends.locmem.LocMemCache')
        manager = DatasourceCacheManager()
        with mock.patch('ereports.engine.cache._cache', locmem_cache):
            monitor_model(Permission)
            reset(Permission)

            TestDatasource = type('TestDatasource', (Datasource,),
                                  {'model': Permission,
                                   'dependent_models': [ContentType],
                                   'use_cache': True,
                                   'columns': ['id', 'name']})

            ds1 = TestDatasource.as_datasource()
            k1 = manager.get_key(ds1)
            self.assertTrue(k1.startswith('ereports/1/django.contrib.auth.models.Permission/0'
                                          '/django.contrib.contenttypes.models.ContentType/0/'), k1)
            Permission.objects.filter(pk=1).delete()
            k2 = manager.get_key(ds1)
            self.assertTrue(k2.startswith('ereports/1/django.contrib.auth.models.Permission/1'
                                          '/django.contrib.contenttypes.models.ContentType/0/'), k2)
Exemplo n.º 4
0
    def test_get_key(self):
        manager = DatasourceCacheManager()
        dummy_cache = cache.get_cache(
            'django.core.cache.backends.dummy.DummyCache')
        dummy_cache.clear()
        with mock.patch('ereports.engine.cache._cache', dummy_cache):
            monitor_model(Permission)
            reset(Permission)

            TestDatasource = type(
                'TestDatasource', (Datasource, ), {
                    'model': Permission,
                    'dependent_models': [ContentType],
                    'use_cache': True,
                    'columns': ['id', 'name']
                })
            ds1 = TestDatasource.as_datasource()
            k = manager.get_key(ds1)
            self.assertTrue(
                k.startswith(
                    'ereports/1/django.contrib.auth.models.Permission/0'
                    '/django.contrib.contenttypes.models.ContentType/0/'), k)
Exemplo n.º 5
0
    def __init__(self, **kwargs):
        self.kwfilters = {}
        self.filters = []
        self._result_cache = None
        self._queryset = None
        self._custom_filters = kwargs.pop('custom_filters', [])
        self.extras = kwargs.pop('extras', {})

        for key, value in kwargs.iteritems():
            setattr(self, key, value)

        if self.use_cache and self.cache_manager is None:
            self.cache_manager = DatasourceCacheManager()
        elif not self.use_cache:
            self.cache_manager = DummyCacheManager()