Example #1
0
 def test_updates_commissioning_script(self):
     script = factory.make_Script(script_type=SCRIPT_TYPE.COMMISSIONING)
     content = factory.make_script_content()
     uploaded_file = SimpleUploadedFile(
         content=content.encode('ascii'), name=script.name)
     form = CommissioningScriptForm(files={'content': uploaded_file})
     self.assertTrue(form.is_valid(), form._errors)
     form.save()
     new_script = Script.objects.get(name=script.name)
     self.assertEquals(SCRIPT_TYPE.COMMISSIONING, new_script.script_type)
     self.assertEquals(content, new_script.script.data)
Example #2
0
 def test_creates_commissioning_script_from_embedded_yaml_name(self):
     name = factory.make_name('name')
     content = factory.make_script_content({'name': name})
     uploaded_file = SimpleUploadedFile(content=content.encode('ascii'),
                                        name=factory.make_name('filename'))
     form = CommissioningScriptForm(files={'content': uploaded_file})
     self.assertTrue(form.is_valid(), form._errors)
     form.save()
     new_script = Script.objects.get(name=name)
     self.assertEquals(SCRIPT_TYPE.COMMISSIONING, new_script.script_type)
     self.assertEquals(content, new_script.script.data)
Example #3
0
 def test_creates_audit_event(self):
     request = HttpRequest()
     request.user = factory.make_User()
     content = factory.make_script_content()
     name = factory.make_name("filename")
     uploaded_file = SimpleUploadedFile(content=content.encode("ascii"),
                                        name=name)
     form = CommissioningScriptForm(files={"content": uploaded_file})
     self.assertTrue(form.is_valid(), form._errors)
     form.save(request)
     event = Event.objects.get(type__level=AUDIT)
     self.assertIsNotNone(event)
     self.assertEqual(event.description, "Saved script '%s'." % name)
Example #4
0
 def test_creates_commissioning_script_from_filename(self):
     request = HttpRequest()
     request.user = factory.make_User()
     content = factory.make_script_content()
     name = factory.make_name("filename")
     uploaded_file = SimpleUploadedFile(content=content.encode("ascii"),
                                        name=name)
     form = CommissioningScriptForm(files={"content": uploaded_file})
     self.assertTrue(form.is_valid(), form._errors)
     form.save(request)
     new_script = Script.objects.get(name=name)
     self.assertEquals(SCRIPT_TYPE.COMMISSIONING, new_script.script_type)
     self.assertEquals(content, new_script.script.data)