Ejemplo n.º 1
0
    def test_cache(self):
        locmem_cache = cache.get_cache('django.core.cache.backends.locmem.LocMemCache')
        # dummy_cache = cache.get_cache('django.core.cache.backends.dummy.DummyCache')
        locmem_cache.clear()
        with mock.patch('ereports.engine.cache._cache', locmem_cache):
            G(SimpleDemoModel, n=2, char='abc', integer1=10, integer2=20, boolean=True)
            r1 = BaseReport.as_report(model=SimpleDemoModel, use_cache=True)
            r2 = BaseReport.as_report(model=SimpleDemoModel, use_cache=True)

            with _AssertNumQueriesContext(self, 1, connections['default']):
                i1 = list(r1)
                self.assertSequenceEqual(i1, list(r2))
Ejemplo n.º 2
0
    def test_headers(self):
        G(SimpleDemoModel, n=2, char='abc', integer1=10, integer2=20)

        ds = Datasource.as_datasource(model=SimpleDemoModel)
        r = BaseReport.as_report(datasource=ds,
                                 list_display=['integer2', 'char', 'integer1'])

        self.assertSequenceEqual(['Integer #2', 'Character', 'Integer #1'], r.headers)

        ds = Datasource.as_datasource(model=SimpleDemoModel,
                                      columns=['integer2', 'char', 'integer1'])
        r = BaseReport.as_report(datasource=ds)

        self.assertSequenceEqual(['Integer #2', 'Character', 'Integer #1'], r.headers)
Ejemplo n.º 3
0
def test_subtotal():
    G(SimpleDemoModel, n=2, char='abc', integer1=10, integer2=20)
    ds = Datasource.as_datasource(model=SimpleDemoModel)
    r = BaseReport.as_report(datasource=ds)

    assert subtotal(r, r, 'integer1') == 20
    assert subtotal(r, int, 'integer1') == 0
Ejemplo n.º 4
0
def test_total():
    G(SimpleDemoModel, n=2, char='abc', integer1=10, integer2=20)
    ds = Datasource.as_datasource(model=SimpleDemoModel)
    r = BaseReport.as_report(datasource=ds)

    assert total(r, 'integer2') == 40
    assert total(r, 'char') == 0
Ejemplo n.º 5
0
    def test_headers(self):
        G(SimpleDemoModel, n=2, char='abc', integer1=10, integer2=20)

        ds = Datasource.as_datasource(model=SimpleDemoModel)
        r = BaseReport.as_report(datasource=ds,
                                 list_display=['integer2', 'char', 'integer1'])

        self.assertSequenceEqual(['Integer #2', 'Character', 'Integer #1'],
                                 r.headers)

        ds = Datasource.as_datasource(model=SimpleDemoModel,
                                      columns=['integer2', 'char', 'integer1'])
        r = BaseReport.as_report(datasource=ds)

        self.assertSequenceEqual(['Integer #2', 'Character', 'Integer #1'],
                                 r.headers)
Ejemplo n.º 6
0
    def test_get_column_values(self):
        G(SimpleDemoModel, n=10, data_fixture=SequentialDataFixture(0))
        ds = Datasource.as_datasource(model=SimpleDemoModel)
        r = BaseReport.as_report(datasource=ds,
                                 list_display=['integer2', 'char', 'integer1'])

        self.assertSequenceEqual([1, 3, 5, 7, 9, 11, 13, 15, 17, 19], r.get_column_values('integer1'))
Ejemplo n.º 7
0
    def test_get_column_values(self):
        G(SimpleDemoModel, n=10, data_fixture=SequentialDataFixture(0))
        ds = Datasource.as_datasource(model=SimpleDemoModel)
        r = BaseReport.as_report(datasource=ds,
                                 list_display=['integer2', 'char', 'integer1'])

        self.assertSequenceEqual([1, 3, 5, 7, 9, 11, 13, 15, 17, 19],
                                 r.get_column_values('integer1'))
Ejemplo n.º 8
0
    def test_datasource_std_list_display(self):
        G(SimpleDemoModel, n=2, char='abc', integer1=10, integer2=20)

        ds = Datasource.as_datasource(model=SimpleDemoModel,
                                      columns=['integer2', 'char', 'integer1'])
        r = BaseReport.as_report(datasource=ds)

        self.assertSequenceEqual([c.name for c in ds.columns], r.display_order())
        self.assertSequenceEqual(r[1], (20, u'abc', 10))
Ejemplo n.º 9
0
    def test_datasource_custom_list_display(self):
        G(SimpleDemoModel, n=2, char='abc', integer1=10, integer2=20)

        ds = Datasource.as_datasource(model=SimpleDemoModel)
        r = BaseReport.as_report(datasource=ds,
                                 list_display=['integer2', 'char', 'integer1'])

        self.assertSequenceEqual(r[1], (20, u'abc', 10))
        self.assertSequenceEqual(r[:1], [(20, u'abc', 10)])
Ejemplo n.º 10
0
    def test_datasource_custom_list_display(self):
        G(SimpleDemoModel, n=2, char='abc', integer1=10, integer2=20)

        ds = Datasource.as_datasource(model=SimpleDemoModel)
        r = BaseReport.as_report(datasource=ds,
                                 list_display=['integer2', 'char', 'integer1'])

        self.assertSequenceEqual(r[1], (20, u'abc', 10))
        self.assertSequenceEqual(r[:1], [(20, u'abc', 10)])
Ejemplo n.º 11
0
    def test_cache(self):
        locmem_cache = cache.get_cache(
            'django.core.cache.backends.locmem.LocMemCache')
        # dummy_cache = cache.get_cache('django.core.cache.backends.dummy.DummyCache')
        locmem_cache.clear()
        with mock.patch('ereports.engine.cache._cache', locmem_cache):
            G(SimpleDemoModel,
              n=2,
              char='abc',
              integer1=10,
              integer2=20,
              boolean=True)
            r1 = BaseReport.as_report(model=SimpleDemoModel, use_cache=True)
            r2 = BaseReport.as_report(model=SimpleDemoModel, use_cache=True)

            with _AssertNumQueriesContext(self, 1, connections['default']):
                i1 = list(r1)
                self.assertSequenceEqual(i1, list(r2))
Ejemplo n.º 12
0
 def test_getitem(self):
     instances = G(SimpleDemoModel,
                   n=2,
                   char='abc',
                   integer1=10,
                   integer2=20,
                   boolean=True)
     r = BaseReport.as_report(model=SimpleDemoModel)
     self.assertSequenceEqual(r[1].values(),
                              (instances[1].pk, u'abc', 10, 20, True))
Ejemplo n.º 13
0
    def test_datasource_std_list_display(self):
        G(SimpleDemoModel, n=2, char='abc', integer1=10, integer2=20)

        ds = Datasource.as_datasource(model=SimpleDemoModel,
                                      columns=['integer2', 'char', 'integer1'])
        r = BaseReport.as_report(datasource=ds)

        self.assertSequenceEqual([c.name for c in ds.columns],
                                 r.display_order())
        self.assertSequenceEqual(r[1], (20, u'abc', 10))
Ejemplo n.º 14
0
 def test_slice(self):
     instances = G(SimpleDemoModel,
                   n=2,
                   char='abc',
                   integer1=10,
                   integer2=20,
                   boolean=True)
     r = BaseReport.as_report(model=SimpleDemoModel)
     self.assertSequenceEqual(list(r[:1]),
                              [(instances[0].pk, u'abc', 10, 20, True)])
Ejemplo n.º 15
0
 def test_datasource(self):
     instances = G(SimpleDemoModel,
                   n=2,
                   char='abc',
                   integer1=10,
                   integer2=20,
                   boolean=True)
     ds = Datasource.as_datasource(model=SimpleDemoModel)
     r = BaseReport.as_report(datasource=ds)
     self.assertSequenceEqual(r[1].values(),
                              (instances[1].pk, u'abc', 10, 20, True))
Ejemplo n.º 16
0
 def test_slice(self):
     instances = G(SimpleDemoModel, n=2, char='abc', integer1=10, integer2=20, boolean=True)
     r = BaseReport.as_report(model=SimpleDemoModel)
     self.assertSequenceEqual(list(r[:1]), [(instances[0].pk, u'abc', 10, 20, True)])
Ejemplo n.º 17
0
 def test_improperly_configured_exception(self):
     G(SimpleDemoModel, n=2, char='abc', integer1=10, integer2=20)
     with self.assertRaises(ImproperlyConfigured):
         BaseReport.as_report(models=SimpleDemoModel)
Ejemplo n.º 18
0
 def test_type_error_exception(self):
     with self.assertRaises(TypeError):
         BaseReport.as_report(models="")
Ejemplo n.º 19
0
 def test_improperly_configured_exception(self):
     G(SimpleDemoModel, n=2, char='abc', integer1=10, integer2=20)
     with self.assertRaises(ImproperlyConfigured):
         BaseReport.as_report(models=SimpleDemoModel)
Ejemplo n.º 20
0
 def test_type_error_exception(self):
     with self.assertRaises(TypeError):
         BaseReport.as_report(models="")
Ejemplo n.º 21
0
 def test_getitem(self):
     instances = G(SimpleDemoModel, n=2, char='abc', integer1=10, integer2=20, boolean=True)
     r = BaseReport.as_report(model=SimpleDemoModel)
     self.assertSequenceEqual(r[1].values(), (instances[1].pk, u'abc', 10, 20, True))
Ejemplo n.º 22
0
 def test_datasource(self):
     instances = G(SimpleDemoModel, n=2, char='abc', integer1=10, integer2=20, boolean=True)
     ds = Datasource.as_datasource(model=SimpleDemoModel)
     r = BaseReport.as_report(datasource=ds)
     self.assertSequenceEqual(r[1].values(), (instances[1].pk, u'abc', 10, 20, True))