1
0
mirror of https://github.com/netbox-community/netbox.git synced 2024-05-10 07:54:54 +00:00

Fixes #7628: Fix load_yaml method for custom scripts

This commit is contained in:
jeremystretch
2021-10-27 09:04:18 -04:00
parent d48a68317d
commit b56cae24c5
3 changed files with 53 additions and 2 deletions

View File

@ -1,3 +1,5 @@
import tempfile
from django.core.files.uploadedfile import SimpleUploadedFile
from django.test import TestCase
from netaddr import IPAddress, IPNetwork
@ -11,6 +13,50 @@ CHOICES = (
('0000ff', 'Blue')
)
YAML_DATA = """
Foo: 123
Bar: 456
Baz:
- A
- B
- C
"""
JSON_DATA = """
{
"Foo": 123,
"Bar": 456,
"Baz": ["A", "B", "C"]
}
"""
class ScriptTest(TestCase):
def test_load_yaml(self):
datafile = tempfile.NamedTemporaryFile()
datafile.write(bytes(YAML_DATA, 'UTF-8'))
datafile.seek(0)
data = Script().load_yaml(datafile.name)
self.assertEqual(data, {
'Foo': 123,
'Bar': 456,
'Baz': ['A', 'B', 'C'],
})
def test_load_json(self):
datafile = tempfile.NamedTemporaryFile()
datafile.write(bytes(JSON_DATA, 'UTF-8'))
datafile.seek(0)
data = Script().load_json(datafile.name)
self.assertEqual(data, {
'Foo': 123,
'Bar': 456,
'Baz': ['A', 'B', 'C'],
})
class ScriptVariablesTest(TestCase):