Commit 980c92b1 by Bach Dániel

dashboard: add test for Template.raw_data (issue #94)

fixes #94
parent 05e64bb7
......@@ -487,15 +487,14 @@ class TemplateForm(forms.ModelForm):
return User.objects.get(pk=self.instance.owner.pk)
return self.user
def clean(self):
cleaned_data = self.cleaned_data
def clean_raw_data(self):
# if raw_data has changed and the user is not superuser
if "raw_data" in self.changed_data and not self.user.is_superuser:
old_raw_data = InstanceTemplate.objects.get(
pk=self.instance.pk).raw_data
cleaned_data['raw_data'] = old_raw_data
return cleaned_data
return old_raw_data
else:
return self.cleaned_data['raw_data']
def save(self, commit=True):
data = self.cleaned_data
......
......@@ -190,6 +190,28 @@ class VmDetailTest(LoginMixin, TestCase):
response = c.post('/dashboard/template/1/', {})
self.assertEqual(response.status_code, 403)
def test_edit_unpermitted_template_raw_data(self):
c = Client()
self.login(c, 'user1')
tmpl = InstanceTemplate.objects.get(id=1)
tmpl.set_level(self.u1, 'owner')
tmpl.disks.get().set_level(self.u1, 'owner')
kwargs = tmpl.__dict__.copy()
kwargs.update(name='t1', lease=1, disks=1, raw_data='tst1')
response = c.post('/dashboard/template/1/', kwargs)
self.assertEqual(response.status_code, 302)
self.assertEqual(InstanceTemplate.objects.get(id=1).raw_data,
tmpl.raw_data)
def test_edit_permitted_template_raw_data(self):
c = Client()
self.login(c, 'superuser')
kwargs = InstanceTemplate.objects.get(id=1).__dict__.copy()
kwargs.update(name='t2', lease=1, disks=1, raw_data='tst2')
response = c.post('/dashboard/template/1/', kwargs)
self.assertEqual(response.status_code, 302)
self.assertEqual(InstanceTemplate.objects.get(id=1).raw_data, 'tst2')
def test_permitted_lease_delete(self):
c = Client()
self.login(c, 'superuser')
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment