Skip to content

Commit

Permalink
Merge pull request #180 from Syncano/LIB-637
Browse files Browse the repository at this point in the history
[LIB-637] add rename mixin for the rename functionality, add this t…
  • Loading branch information
opalczynski committed Apr 7, 2016
2 parents cf27bc9 + f7b98ac commit 04d1cd4
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 16 deletions.
11 changes: 10 additions & 1 deletion syncano/models/incentives.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from .base import Model
from .instances import Instance
from .manager import ScriptEndpointManager, ScriptManager
from .mixins import RenameMixin


class Script(Model):
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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
17 changes: 2 additions & 15 deletions syncano/models/instances.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 <http://docs.syncano.com/docs/getting-started-with-syncano#adding-an-instance>`_.
Expand Down Expand Up @@ -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):
"""
Expand Down
18 changes: 18 additions & 0 deletions syncano/models/mixins.py
Original file line number Diff line number Diff line change
@@ -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
10 changes: 10 additions & 0 deletions tests/integration_test_reponse_templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,13 @@ def test_render_api(self):

rendered = render_template.render(context={'objects': [3]})
self.assertEqual(rendered, '<li>3</li>')

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='<div></div>', content_type='text/html',
context={'two': 2})
template = template.rename(new_name=new_name)

self.assertEqual(template.name, new_name)

0 comments on commit 04d1cd4

Please sign in to comment.