diff --git a/syncano/models/incentives.py b/syncano/models/incentives.py index e36c9fc..6beeb4c 100644 --- a/syncano/models/incentives.py +++ b/syncano/models/incentives.py @@ -8,6 +8,7 @@ from .base import Model from .instances import Instance from .manager import ScriptEndpointManager, ScriptManager +from .mixins import RenameMixin class Script(Model): @@ -284,7 +285,7 @@ def reset_link(self): self.public_link = response['public_link'] -class ResponseTemplate(Model): +class ResponseTemplate(RenameMixin, Model): """ OO wrapper around templates. @@ -330,3 +331,11 @@ def render(self, context=None): connection = self._get_connection() return connection.request('POST', endpoint, data={'context': context}) + + def rename(self, new_name): + rename_path = self.links.rename + data = {'new_name': new_name} + connection = self._get_connection() + response = connection.request('POST', rename_path, data=data) + self.to_python(response) + return self diff --git a/syncano/models/instances.py b/syncano/models/instances.py index 23c434a..66f49f6 100644 --- a/syncano/models/instances.py +++ b/syncano/models/instances.py @@ -2,9 +2,10 @@ from . import fields from .base import Model +from .mixins import RenameMixin -class Instance(Model): +class Instance(RenameMixin, Model): """ OO wrapper around instances `link `_. @@ -75,20 +76,6 @@ class Meta: } } - def rename(self, new_name): - """ - A method for changing the instance name; - - :param new_name: the new name for the instance; - :return: a populated Instance object; - """ - rename_path = self.links.rename - data = {'new_name': new_name} - connection = self._get_connection() - response = connection.request('POST', rename_path, data=data) - self.to_python(response) - return self - class ApiKey(Model): """ diff --git a/syncano/models/mixins.py b/syncano/models/mixins.py new file mode 100644 index 0000000..8c2d016 --- /dev/null +++ b/syncano/models/mixins.py @@ -0,0 +1,18 @@ +# -*- coding: utf-8 -*- + + +class RenameMixin(object): + + def rename(self, new_name): + """ + A method for changing the name of the object; Corresponds to the Mixin in CORE; + + :param new_name: the new name for the object; + :return: a populated object; + """ + rename_path = self.links.rename + data = {'new_name': new_name} + connection = self._get_connection() + response = connection.request('POST', rename_path, data=data) + self.to_python(response) + return self diff --git a/tests/integration_test_reponse_templates.py b/tests/integration_test_reponse_templates.py index a145c95..6816cb8 100644 --- a/tests/integration_test_reponse_templates.py +++ b/tests/integration_test_reponse_templates.py @@ -49,3 +49,13 @@ def test_render_api(self): rendered = render_template.render(context={'objects': [3]}) self.assertEqual(rendered, '
  • 3
  • ') + + def test_rename(self): + name = 'some_old_new_name_for_template' + new_name = 'some_new_name_for_template' + + template = ResponseTemplate.please.create(name=name, content='
    ', content_type='text/html', + context={'two': 2}) + template = template.rename(new_name=new_name) + + self.assertEqual(template.name, new_name)