Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions syncano/models/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -727,7 +727,6 @@ def _clone(self):
def serialize(self, data, model=None):
"""Serializes passed data to related :class:`~syncano.models.base.Model` class."""
model = model or self.model

if data == '':
return

Expand Down Expand Up @@ -777,7 +776,7 @@ def request(self, method=None, path=None, **request):
raise self.model.DoesNotExist("{} not found.".format(obj_id))
raise

if 'next' not in response:
if 'next' not in response and not self._template:
return self.serialize(response)

return response
Expand All @@ -799,6 +798,9 @@ def iterator(self):
response = self._get_response()
results = 0
while True:
if self._template:
yield response
break
objects = response.get('objects')
next_url = response.get('next')

Expand Down
14 changes: 13 additions & 1 deletion tests/integration_test_reponse_templates.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-

from syncano.models import ResponseTemplate
from syncano.models import Class, ResponseTemplate
from tests.integration_test import InstanceMixin, IntegrationTest


Expand Down Expand Up @@ -59,3 +59,15 @@ def test_rename(self):
template = template.rename(new_name=new_name)

self.assertEqual(template.name, new_name)

def test_render_on_endpoint_list(self):
template_response = Class.please.template('objects_html_table').all()

self.assertIn('<table>', template_response[0]) # all() returns a list (precise: iterator)
self.assertIn('user_profile', template_response[0])

def test_render_on_endpoint_one_elem(self):
template_response = Class.please.template('objects_html_table').get(name='user_profile')

self.assertIn('<table>', template_response)
self.assertIn('user_profile', template_response)