Skip to content

Commit

Permalink
fix and test image renderer
Browse files Browse the repository at this point in the history
  • Loading branch information
sheppard committed Dec 11, 2015
1 parent ef9b183 commit c0c8b5c
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
3 changes: 2 additions & 1 deletion rest_pandas/renderers.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from io import StringIO

import os
from io import BytesIO


class PandasBaseRenderer(BaseRenderer):
Expand Down Expand Up @@ -148,7 +149,7 @@ def get_pandas_kwargs(self, data, renderer_context):
return {'ax': self.ax}

def get_output(self):
data = StringIO()
data = BytesIO()
self.fig.savefig(data, format=self.format)
return data.getvalue()

Expand Down
33 changes: 33 additions & 0 deletions tests/test_images.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
from rest_framework.test import APITestCase
from tests.testapp.models import TimeSeries
import unittest

try:
import matplotlib
except ImportError:
matplotlib = None


class ImageTestCase(APITestCase):
def setUp(self):
data = (
('2014-01-01', 0.5),
('2014-01-02', 0.4),
('2014-01-03', 0.6),
('2014-01-04', 0.2),
('2014-01-05', 0.1),
)
for date, value in data:
TimeSeries.objects.create(date=date, value=value)

@unittest.skipUnless(matplotlib, "requires matplotlib")
def test_png(self):
response = self.client.get("/timeseries.png")
header = response.content[1:4]
self.assertEqual(header, b"PNG")

@unittest.skipUnless(matplotlib, "requires matplotlib")
def test_svg(self):
response = self.client.get("/timeseries.svg")
header = response.content[2:5]
self.assertEqual(header, b"xml")

0 comments on commit c0c8b5c

Please sign in to comment.