| 1 | import logging |
| 2 | from pprint import pformat |
| 3 | |
| 4 | import pytest |
| 5 | |
| 6 | from pbcommand.models.report import Plot, PbReportError, PlotlyPlot |
| 7 | |
| 8 | log = logging.getLogger(__name__) |
| 9 | |
| 10 | |
| 11 | class TestPlot: |
| 12 | |
| 13 | def test_plot_null_id(self): |
| 14 | """Can't create an plot without an id.""" |
| 15 | with pytest.raises(PbReportError): |
| 16 | p = Plot(None, 'foo') |
| 17 | |
| 18 | def test_plot_null_image(self): |
| 19 | """Can't create an plot without an image.""" |
| 20 | def _test(): |
| 21 | p = Plot('123', None) |
| 22 | with pytest.raises(PbReportError): |
| 23 | _test() |
| 24 | |
| 25 | def test_to_dict(self): |
| 26 | """Test plot to dictionary method""" |
| 27 | a = Plot('123', 'foo', caption='foo is the caption') |
| 28 | d = a.to_dict() |
| 29 | assert '123' == d['id'] |
| 30 | assert 'foo' == d['image'] |
| 31 | assert 'foo is the caption' == d['caption'] |
| 32 | assert Plot.PLOT_TYPE == d['plotType'] |
| 33 | log.info(pformat(d, indent=4)) |
| 34 | log.info(repr(a)) |
| 35 | assert repr(a) is not None |
| 36 | |
| 37 | def test_init_with_thumbnail(self): |
| 38 | """Initial with thumbnail""" |
| 39 | image = "my_image.png" |
| 40 | thumbnail = "my_image_thumb.png" |
| 41 | p = Plot('plot_1', image, thumbnail=thumbnail, caption="Awesome image") |
| 42 | |
| 43 | assert p.thumbnail == thumbnail |
| 44 | log.info(pformat(p.to_dict())) |
| 45 | assert isinstance(p.to_dict(), dict) |
| 46 | |
| 47 | def test_plotly_plot(self): |
| 48 | a = PlotlyPlot('123', 'foo', caption='foo is the caption', |
| 49 | plotly_version="1.2.3") |
| 50 | d = a.to_dict() |
| 51 | assert '123' == d['id'] |
| 52 | assert 'foo' == d['image'] |
| 53 | assert 'foo is the caption' == d['caption'] |
| 54 | assert d['plotType'] == PlotlyPlot.PLOT_TYPE |
| 55 | assert d['plotlyVersion'] == "1.2.3" |