コード例 #1
0
 def test_propagates_script_form_errors(self):
     # Regression test for LP:1712422
     uploaded_file = SimpleUploadedFile(
         content=factory.make_script_content().encode("ascii"), name="none")
     form = CommissioningScriptForm(files={"content": uploaded_file})
     self.assertFalse(form.is_valid())
     self.assertDictEqual({"content": ['name: "none" is a reserved name.']},
                          form.errors)
コード例 #2
0
ファイル: test_script.py プロジェクト: Kryndex/maas
 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)
コード例 #3
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)
コード例 #4
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)
コード例 #5
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)
コード例 #6
0
 def test_not_valid_when_empty(self):
     # Regression test for LP:1712423
     form = CommissioningScriptForm()
     self.assertFalse(form.is_valid())