Ejemplo n.º 1
0
    def test_to_dict_multi(self):
        """
        Multiple complex elements.
        The id of report sub elements is prepended with the id of the parent
        element when to_dict is called.
        """
        tags = ["alpha", "beta", "gamma"]
        r = Report('redfang', tags=tags)
        a = Attribute('a', 'b')
        a2 = Attribute('a2', 'b2')
        r.add_attribute(a)
        r.add_attribute(a2)

        pg = PlotGroup('pgid')
        pg.add_plot(Plot('pid', 'anImg'))
        pg.add_plot(Plot('pid2', 'anImg2'))
        r.add_plotgroup(pg)

        pg = PlotGroup('pgid2')
        pg.add_plot(Plot('pid2', 'anImg2'))
        pg.add_plot(Plot('pid22', 'anImg22'))
        r.add_plotgroup(pg)

        t = Table('tabid')
        t.add_column(Column('c1'))
        r.add_table(t)

        t = Table('tabid2')
        t.add_column(Column('c2'))
        r.add_table(t)

        d = r.to_dict()

        log.debug(str(d))

        assert 'redfang' == d['id']
        assert 'redfang.a' == d['attributes'][0]['id']
        assert 'redfang.a2' == d['attributes'][1]['id']

        assert 'redfang.pgid' == d['plotGroups'][0]['id']
        assert 'redfang.pgid.pid' == d['plotGroups'][0]['plots'][0]['id']
        assert 'redfang.pgid.pid2' == d['plotGroups'][0]['plots'][1]['id']

        assert 'redfang.pgid2' == d['plotGroups'][1]['id']
        assert 'redfang.pgid2.pid2' == d['plotGroups'][1]['plots'][0]['id']
        assert 'redfang.pgid2.pid22' == d['plotGroups'][1]['plots'][1]['id']

        assert 'redfang.tabid' == d['tables'][0]['id']
        assert 'redfang.tabid.c1' == d['tables'][0]['columns'][0]['id']

        assert 'redfang.tabid2' == d['tables'][1]['id']
        assert 'redfang.tabid2.c2' == d['tables'][1]['columns'][0]['id']

        assert list(sorted(d['tags'])) == list(sorted(tags))

        loaded_report = load_report_from(d)
        assert list(sorted(loaded_report.tags)) == list(sorted(tags))

        log.info(repr(r))
        assert repr(r) is not None
Ejemplo n.º 2
0
    def test_to_dict(self):
        """
        The id of report sub elements is prepended with the id of the parent
        element when to_dict is called.
        """
        r = Report('redfang')
        a = Attribute('a', 'b')
        a2 = Attribute('a2', 'b2')
        r.add_attribute(a)
        r.add_attribute(a2)

        pg = PlotGroup('pgid')
        pg.add_plot(Plot('pid', 'anImg'))
        pg.add_plot(Plot('pid2', 'anImg2'))
        r.add_plotgroup(pg)

        t = Table('tabid')
        t.add_column(Column('c1'))
        r.add_table(t)

        d = r.to_dict()

        log.debug("\n" + pformat(d))

        self.assertEqual('redfang', d['id'])
        self.assertEqual('redfang.a', d['attributes'][0]['id'])
        self.assertEqual('redfang.a2', d['attributes'][1]['id'])
        self.assertEqual('redfang.pgid', d['plotGroups'][0]['id'])
        self.assertEqual('redfang.pgid.pid', d['plotGroups'][0]['plots'][0]['id'])
        self.assertEqual('redfang.pgid.pid2', d['plotGroups'][0]['plots'][1]['id'])

        self.assertEqual('redfang.tabid', d['tables'][0]['id'])
        self.assertEqual('redfang.tabid.c1', d['tables'][0]['columns'][0]['id'])
Ejemplo n.º 3
0
    def test_to_dict_multi(self):
        """
        Multiple complex elements.
        The id of report sub elements is prepended with the id of the parent
        element when to_dict is called.
        """
        r = Report('redfang')
        a = Attribute('a', 'b')
        a2 = Attribute('a2', 'b2')
        r.add_attribute(a)
        r.add_attribute(a2)

        pg = PlotGroup('pgid')
        pg.add_plot(Plot('pid', 'anImg'))
        pg.add_plot(Plot('pid2', 'anImg2'))
        r.add_plotgroup(pg)

        pg = PlotGroup('pgid2')
        pg.add_plot(Plot('pid2', 'anImg2'))
        pg.add_plot(Plot('pid22', 'anImg22'))
        r.add_plotgroup(pg)

        t = Table('tabid')
        t.add_column(Column('c1'))
        r.add_table(t)

        t = Table('tabid2')
        t.add_column(Column('c2'))
        r.add_table(t)

        d = r.to_dict()

        log.debug(str(d))

        self.assertEqual('redfang', d['id'])
        self.assertEqual('redfang.a', d['attributes'][0]['id'])
        self.assertEqual('redfang.a2', d['attributes'][1]['id'])

        self.assertEqual('redfang.pgid', d['plotGroups'][0]['id'])
        self.assertEqual('redfang.pgid.pid', d[
                         'plotGroups'][0]['plots'][0]['id'])
        self.assertEqual('redfang.pgid.pid2', d[
                         'plotGroups'][0]['plots'][1]['id'])

        self.assertEqual('redfang.pgid2', d['plotGroups'][1]['id'])
        self.assertEqual('redfang.pgid2.pid2', d[
                         'plotGroups'][1]['plots'][0]['id'])
        self.assertEqual('redfang.pgid2.pid22', d[
                         'plotGroups'][1]['plots'][1]['id'])

        self.assertEqual('redfang.tabid', d['tables'][0]['id'])
        self.assertEqual('redfang.tabid.c1', d['tables'][
                         0]['columns'][0]['id'])

        self.assertEqual('redfang.tabid2', d['tables'][1]['id'])
        self.assertEqual('redfang.tabid2.c2', d[
                         'tables'][1]['columns'][0]['id'])

        log.info(repr(r))
        self.assertIsNotNone(repr(r))
Ejemplo n.º 4
0
    def test_to_dict_multi(self):
        """
        Multiple complex elements.
        The id of report sub elements is prepended with the id of the parent
        element when to_dict is called.
        """
        r = Report('redfang')
        a = Attribute('a', 'b')
        a2 = Attribute('a2', 'b2')
        r.add_attribute(a)
        r.add_attribute(a2)

        pg = PlotGroup('pgid')
        pg.add_plot(Plot('pid', 'anImg'))
        pg.add_plot(Plot('pid2', 'anImg2'))
        r.add_plotgroup(pg)

        pg = PlotGroup('pgid2')
        pg.add_plot(Plot('pid2', 'anImg2'))
        pg.add_plot(Plot('pid22', 'anImg22'))
        r.add_plotgroup(pg)

        t = Table('tabid')
        t.add_column(Column('c1'))
        r.add_table(t)

        t = Table('tabid2')
        t.add_column(Column('c2'))
        r.add_table(t)

        d = r.to_dict()

        log.debug(str(d))

        self.assertEqual('redfang', d['id'])
        self.assertEqual('redfang.a', d['attributes'][0]['id'])
        self.assertEqual('redfang.a2', d['attributes'][1]['id'])

        self.assertEqual('redfang.pgid', d['plotGroups'][0]['id'])
        self.assertEqual('redfang.pgid.pid',
                         d['plotGroups'][0]['plots'][0]['id'])
        self.assertEqual('redfang.pgid.pid2',
                         d['plotGroups'][0]['plots'][1]['id'])

        self.assertEqual('redfang.pgid2', d['plotGroups'][1]['id'])
        self.assertEqual('redfang.pgid2.pid2',
                         d['plotGroups'][1]['plots'][0]['id'])
        self.assertEqual('redfang.pgid2.pid22',
                         d['plotGroups'][1]['plots'][1]['id'])

        self.assertEqual('redfang.tabid', d['tables'][0]['id'])
        self.assertEqual('redfang.tabid.c1',
                         d['tables'][0]['columns'][0]['id'])

        self.assertEqual('redfang.tabid2', d['tables'][1]['id'])
        self.assertEqual('redfang.tabid2.c2',
                         d['tables'][1]['columns'][0]['id'])

        log.info(repr(r))
        self.assertIsNotNone(repr(r))
Ejemplo n.º 5
0
    def test_to_dict(self):
        """
        The id of report sub elements is prepended with the id of the parent
        element when to_dict is called.
        """
        r = Report("redfang")
        a = Attribute("a", "b")
        a2 = Attribute("a2", "b2")
        r.add_attribute(a)
        r.add_attribute(a2)

        pg = PlotGroup("pgid")
        pg.add_plot(Plot("pid", "anImg"))
        pg.add_plot(Plot("pid2", "anImg2"))
        r.add_plotgroup(pg)

        t = Table("tabid")
        t.add_column(Column("c1"))
        r.add_table(t)

        d = r.to_dict()

        log.debug("\n" + pformat(d))

        self.assertEqual("redfang", d["id"])
        self.assertEqual("redfang.a", d["attributes"][0]["id"])
        self.assertEqual("redfang.a2", d["attributes"][1]["id"])
        self.assertEqual("redfang.pgid", d["plotGroups"][0]["id"])
        self.assertEqual("redfang.pgid.pid", d["plotGroups"][0]["plots"][0]["id"])
        self.assertEqual("redfang.pgid.pid2", d["plotGroups"][0]["plots"][1]["id"])

        self.assertEqual("redfang.tabid", d["tables"][0]["id"])
        self.assertEqual("redfang.tabid.c1", d["tables"][0]["columns"][0]["id"])
Ejemplo n.º 6
0
    def test_get_table_by_id_with_bad_id(self):
        r = Report('redfang')
        t1 = Table('tabid1')
        t1.add_column(Column('c1'))
        r.add_table(t1)

        bad_t = r.get_table_by_id('id_that_does_not_exist')
        self.assertIsNone(bad_t)
Ejemplo n.º 7
0
    def test_get_table_by_id(self):
        r = Report('redfang')
        t1 = Table('tabid1')
        t1.add_column(Column('c1'))
        r.add_table(t1)

        t = r.get_table_by_id('tabid1')
        self.assertEqual(t, t1)
Ejemplo n.º 8
0
    def test_get_table_by_id_with_bad_id(self):
        r = Report('redfang')
        t1 = Table('tabid1')
        t1.add_column(Column('c1'))
        r.add_table(t1)

        bad_t = r.get_table_by_id('id_that_does_not_exist')
        self.assertIsNone(bad_t)
Ejemplo n.º 9
0
    def test_get_table_by_id(self):
        r = Report('redfang')
        t1 = Table('tabid1')
        t1.add_column(Column('c1'))
        r.add_table(t1)

        t = r.get_table_by_id('tabid1')
        self.assertEqual(t, t1)
Ejemplo n.º 10
0
    def test_get_column_by_id(self):
        r = Report('redfang')
        t1 = Table('tabid1')
        c1 = Column('c1')
        t1.add_column(c1)
        r.add_table(t1)

        c = r.get_table_by_id('tabid1').get_column_by_id('c1')
        self.assertEqual(c, c1)
Ejemplo n.º 11
0
    def test_get_column_by_id(self):
        r = Report('redfang')
        t1 = Table('tabid1')
        c1 = Column('c1')
        t1.add_column(c1)
        r.add_table(t1)

        c = r.get_table_by_id('tabid1').get_column_by_id('c1')
        self.assertEqual(c, c1)
Ejemplo n.º 12
0
    def test_get_column_by_id_with_bad_id(self):
        r = Report('redfang')
        t1 = Table('tabid1')
        c1 = Column('c1')
        t1.add_column(c1)
        r.add_table(t1)

        bad_c = r.get_table_by_id('tabid1').get_column_by_id(
            'id_that_does_not_exist')
        assert bad_c is None
Ejemplo n.º 13
0
    def test_get_table_by_id(self):
        r = Report('redfang')
        t1 = Table('tabid1')
        t1.add_column(Column('c1'))
        r.add_table(t1)

        t = r.get_table_by_id('tabid1')
        assert t == t1
        columns_d = t.to_columns_d()
        assert len(columns_d) == 0
Ejemplo n.º 14
0
    def test_to_dict_multi(self):
        """
        Multiple complex elements.
        The id of report sub elements is prepended with the id of the parent
        element when to_dict is called.
        """
        r = Report("redfang")
        a = Attribute("a", "b")
        a2 = Attribute("a2", "b2")
        r.add_attribute(a)
        r.add_attribute(a2)

        pg = PlotGroup("pgid")
        pg.add_plot(Plot("pid", "anImg"))
        pg.add_plot(Plot("pid2", "anImg2"))
        r.add_plotgroup(pg)

        pg = PlotGroup("pgid2")
        pg.add_plot(Plot("pid2", "anImg2"))
        pg.add_plot(Plot("pid22", "anImg22"))
        r.add_plotgroup(pg)

        t = Table("tabid")
        t.add_column(Column("c1"))
        r.add_table(t)

        t = Table("tabid2")
        t.add_column(Column("c2"))
        r.add_table(t)

        d = r.to_dict()

        log.debug(str(d))

        self.assertEqual("redfang", d["id"])
        self.assertEqual("redfang.a", d["attributes"][0]["id"])
        self.assertEqual("redfang.a2", d["attributes"][1]["id"])

        self.assertEqual("redfang.pgid", d["plotGroups"][0]["id"])
        self.assertEqual("redfang.pgid.pid", d["plotGroups"][0]["plots"][0]["id"])
        self.assertEqual("redfang.pgid.pid2", d["plotGroups"][0]["plots"][1]["id"])

        self.assertEqual("redfang.pgid2", d["plotGroups"][1]["id"])
        self.assertEqual("redfang.pgid2.pid2", d["plotGroups"][1]["plots"][0]["id"])
        self.assertEqual("redfang.pgid2.pid22", d["plotGroups"][1]["plots"][1]["id"])

        self.assertEqual("redfang.tabid", d["tables"][0]["id"])
        self.assertEqual("redfang.tabid.c1", d["tables"][0]["columns"][0]["id"])

        self.assertEqual("redfang.tabid2", d["tables"][1]["id"])
        self.assertEqual("redfang.tabid2.c2", d["tables"][1]["columns"][0]["id"])

        log.info(repr(r))
        self.assertIsNotNone(repr(r))
Ejemplo n.º 15
0
    def test_to_dict(self):
        """
        The id of report sub elements is prepended with the id of the parent
        element when to_dict is called.
        """
        r = Report('redfang')
        a = Attribute('a', 'b')
        a2 = Attribute('a2', 'b2')
        r.add_attribute(a)
        r.add_attribute(a2)

        pg = PlotGroup('pgid')
        pg.add_plot(Plot('pid', 'anImg'))
        pg.add_plot(Plot('pid2', 'anImg2'))
        r.add_plotgroup(pg)

        t = Table('tabid')
        t.add_column(Column('c1'))
        r.add_table(t)

        d = r.to_dict()

        log.debug("\n" + pformat(d))

        r2 = load_report_from(d)
        self.assertEqual(r.uuid, r2.uuid)

        self.assertEqual('redfang', d['id'])
        self.assertEqual('redfang.a', d['attributes'][0]['id'])
        self.assertEqual('redfang.a2', d['attributes'][1]['id'])
        self.assertEqual('redfang.pgid', d['plotGroups'][0]['id'])
        self.assertEqual('redfang.pgid.pid',
                         d['plotGroups'][0]['plots'][0]['id'])
        self.assertEqual('redfang.pgid.pid2',
                         d['plotGroups'][0]['plots'][1]['id'])

        self.assertEqual('redfang.tabid', d['tables'][0]['id'])
        self.assertEqual('redfang.tabid.c1',
                         d['tables'][0]['columns'][0]['id'])