Beispiel #1
0
    def test_load_from_file(self):
        rpt_id = 'test_report'
        name = "test_report.json"
        path = get_data_file_from_subdir(_SERIALIZED_JSON_DIR, name)

        r = load_report_from(path)
        self.assertEqual(r.id, rpt_id)

        r2 = load_report_from(r.to_dict())
        self.assertEqual(r2.id, rpt_id)
Beispiel #2
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
Beispiel #3
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'])