| 1 | import json |
| 2 | import logging |
| 3 | import os |
| 4 | from pprint import pformat |
| 5 | |
| 6 | from base_utils import get_data_file_from_subdir |
| 7 | from pbcommand.pb_io import load_report_from_json |
| 8 | from pbcommand.models.report import Plot, PlotlyPlot |
| 9 | |
| 10 | _SERIALIZED_JSON_DIR = 'example-reports' |
| 11 | |
| 12 | |
| 13 | log = logging.getLogger(__name__) |
| 14 | |
| 15 | |
| 16 | def _to_report(name): |
| 17 | file_name = get_data_file_from_subdir(_SERIALIZED_JSON_DIR, name) |
| 18 | log.info("loading json report from {f}".format(f=file_name)) |
| 19 | r = load_report_from_json(file_name) |
| 20 | return r |
| 21 | |
| 22 | |
| 23 | class TestSerializationOverviewReport: |
| 24 | |
| 25 | @classmethod |
| 26 | def setup_class(cls): |
| 27 | name = 'overview.json' |
| 28 | cls.report = _to_report(name) |
| 29 | |
| 30 | def test_id(self): |
| 31 | assert self.report.id == "overview" |
| 32 | |
| 33 | def test_uuid(self): |
| 34 | assert self.report.uuid == "196136c8-f6fd-11e5-b481-3c15c2cc8f88" |
| 35 | |
| 36 | def test_title(self): |
| 37 | assert self.report.title == "Overview Report" |
| 38 | |
| 39 | def test_attributes(self): |
| 40 | assert len(self.report.attributes) == 2 |
| 41 | |
| 42 | |
| 43 | class TestSerializationAdapterReport: |
| 44 | |
| 45 | @classmethod |
| 46 | def setup_class(cls): |
| 47 | file_name = 'filter_reports_adapters.json' |
| 48 | cls.report = _to_report(file_name) |
| 49 | |
| 50 | def test_id(self): |
| 51 | assert self.report.id == 'adapter' |
| 52 | |
| 53 | def test_attributes(self): |
| 54 | assert len(self.report.attributes) == 6 |
| 55 | |
| 56 | def test_plotgroups(self): |
| 57 | assert len(self.report.plotGroups) == 2 |
| 58 | |
| 59 | def test_plots(self): |
| 60 | assert len(self.report.plotGroups[0].plots) == 1 |
| 61 | assert len(self.report.plotGroups[1].plots) == 1 |
| 62 | assert self.report.plotGroups[0].plots[0].plotType == Plot.PLOT_TYPE |
| 63 | assert self.report.plotGroups[1].plots[0].plotType == PlotlyPlot.PLOT_TYPE |