mirror of
https://github.com/netbox-community/netbox.git
synced 2024-05-10 07:54:54 +00:00
Closes #3594: Add ChoiceVar for custom scripts
This commit is contained in:
@@ -99,6 +99,31 @@ class ScriptVariablesTest(TestCase):
|
||||
self.assertTrue(form.is_valid())
|
||||
self.assertEqual(form.cleaned_data['var1'], False)
|
||||
|
||||
def test_choicevar(self):
|
||||
|
||||
CHOICES = (
|
||||
('ff0000', 'Red'),
|
||||
('00ff00', 'Green'),
|
||||
('0000ff', 'Blue')
|
||||
)
|
||||
|
||||
class TestScript(Script):
|
||||
|
||||
var1 = ChoiceVar(
|
||||
choices=CHOICES
|
||||
)
|
||||
|
||||
# Validate valid choice
|
||||
data = {'var1': CHOICES[0][0]}
|
||||
form = TestScript().as_form(data)
|
||||
self.assertTrue(form.is_valid())
|
||||
self.assertEqual(form.cleaned_data['var1'], CHOICES[0][0])
|
||||
|
||||
# Validate invalid choices
|
||||
data = {'var1': 'taupe'}
|
||||
form = TestScript().as_form(data)
|
||||
self.assertFalse(form.is_valid())
|
||||
|
||||
def test_objectvar(self):
|
||||
|
||||
class TestScript(Script):
|
||||
|
||||
Reference in New Issue
Block a user