Example #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)
Example #2
0
    def register(self, report_class):
        model = get_attr(report_class, 'datasource.model', None)
        if model is None:
            logger.error("Unable to monitor {0}".format(report_class))

        elif model not in self.monitors:
            self.monitors.append(model)
            monitor_model(model)

        self.reports.append(_Entry(fqn(report_class), report_class))
Example #3
0
    def register(self, report_class):
        model = get_attr(report_class, 'datasource.model', None)
        if model is None:
            logger.error("Unable to monitor {0}".format(report_class))

        elif model not in self.monitors:
            self.monitors.append(model)
            monitor_model(model)

        self.reports.append(_Entry(fqn(report_class), report_class))
Example #4
0
    def test_cache_invalidate_on_delete(self):
        with mock.patch('ereports.engine.cache._cache', locmem_cache):
            locmem_cache.clear()
            monitor_model(Permission)
            reset(Permission)

            TestDatasource = type('TestDatasource', (Datasource,), {'model': Permission,
                                                                    'use_cache': True,
                                                                    'columns': ['id', 'name']})
            ds1 = TestDatasource.as_datasource()
            list(ds1)
            Permission.objects.filter(pk=1).delete()
            ds2 = TestDatasource.as_datasource()
            with _AssertNumQueriesContext(self, 1, connections['default']):
                list(ds2)
Example #5
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)
Example #6
0
    def test_cache_invalidate_on_delete(self):
        with mock.patch('ereports.engine.cache._cache', locmem_cache):
            locmem_cache.clear()
            monitor_model(Permission)
            reset(Permission)

            TestDatasource = type('TestDatasource', (Datasource, ), {
                'model': Permission,
                'use_cache': True,
                'columns': ['id', 'name']
            })
            ds1 = TestDatasource.as_datasource()
            list(ds1)
            Permission.objects.filter(pk=1).delete()
            ds2 = TestDatasource.as_datasource()
            with _AssertNumQueriesContext(self, 1, connections['default']):
                list(ds2)
Example #7
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)
Example #8
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)