|
|
@@ -4,6 +4,7 @@ from netaddr import IPAddress, IPNetwork
|
|
|
|
|
|
from dcim.models import DeviceRole
|
|
|
from extras.scripts import *
|
|
|
+from utilities.forms import APISelect, APISelectMultiple
|
|
|
|
|
|
|
|
|
class ScriptVariablesTest(TestCase):
|
|
|
@@ -129,31 +130,8 @@ class ScriptVariablesTest(TestCase):
|
|
|
class TestScript(Script):
|
|
|
|
|
|
var1 = ObjectVar(
|
|
|
- queryset=DeviceRole.objects.all()
|
|
|
- )
|
|
|
-
|
|
|
- # Populate some objects
|
|
|
- for i in range(1, 6):
|
|
|
- DeviceRole(
|
|
|
- name='Device Role {}'.format(i),
|
|
|
- slug='device-role-{}'.format(i)
|
|
|
- ).save()
|
|
|
-
|
|
|
- # Validate valid data
|
|
|
- data = {'var1': DeviceRole.objects.first().pk}
|
|
|
- form = TestScript().as_form(data, None)
|
|
|
- self.assertTrue(form.is_valid())
|
|
|
- self.assertEqual(form.cleaned_data['var1'].pk, data['var1'])
|
|
|
-
|
|
|
- def test_dynamicobjectvar(self):
|
|
|
- """
|
|
|
- Test dynamic version of the objectvar
|
|
|
- """
|
|
|
-
|
|
|
- class TestScript(Script):
|
|
|
-
|
|
|
- var1 = DynamicObjectVar(
|
|
|
- queryset=DeviceRole.objects.all()
|
|
|
+ queryset=DeviceRole.objects.all(),
|
|
|
+ widget=APISelect(api_url='/api/dcim/device-roles/')
|
|
|
)
|
|
|
|
|
|
# Populate some objects
|
|
|
@@ -174,33 +152,8 @@ class ScriptVariablesTest(TestCase):
|
|
|
class TestScript(Script):
|
|
|
|
|
|
var1 = MultiObjectVar(
|
|
|
- queryset=DeviceRole.objects.all()
|
|
|
- )
|
|
|
-
|
|
|
- # Populate some objects
|
|
|
- for i in range(1, 6):
|
|
|
- DeviceRole(
|
|
|
- name='Device Role {}'.format(i),
|
|
|
- slug='device-role-{}'.format(i)
|
|
|
- ).save()
|
|
|
-
|
|
|
- # Validate valid data
|
|
|
- data = {'var1': [role.pk for role in DeviceRole.objects.all()[:3]]}
|
|
|
- form = TestScript().as_form(data, None)
|
|
|
- self.assertTrue(form.is_valid())
|
|
|
- self.assertEqual(form.cleaned_data['var1'][0].pk, data['var1'][0])
|
|
|
- self.assertEqual(form.cleaned_data['var1'][1].pk, data['var1'][1])
|
|
|
- self.assertEqual(form.cleaned_data['var1'][2].pk, data['var1'][2])
|
|
|
-
|
|
|
- def test_dynamicmultiobjectvar(self):
|
|
|
- """
|
|
|
- Test dynamic version of the multiobjectvar
|
|
|
- """
|
|
|
-
|
|
|
- class TestScript(Script):
|
|
|
-
|
|
|
- var1 = DynamicMultiObjectVar(
|
|
|
- queryset=DeviceRole.objects.all()
|
|
|
+ queryset=DeviceRole.objects.all(),
|
|
|
+ widget=APISelectMultiple(api_url='/api/dcim/device-roles/')
|
|
|
)
|
|
|
|
|
|
# Populate some objects
|