mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-05-02 23:31:25 -07:00
Add junos_config unit test (#24005)
This commit is contained in:
parent
1f7c2c63c2
commit
9c4daded94
9 changed files with 227 additions and 13 deletions
|
@ -38,15 +38,23 @@ fixture_path = os.path.join(os.path.dirname(__file__), 'fixtures')
|
|||
fixture_data = {}
|
||||
|
||||
|
||||
def load_fixture(name):
|
||||
def load_fixture(name, content='xml'):
|
||||
path = os.path.join(fixture_path, name)
|
||||
if path in fixture_data:
|
||||
return fixture_data[path]
|
||||
|
||||
try:
|
||||
data = ET.parse(path).getroot()
|
||||
except:
|
||||
pass
|
||||
if content == 'str':
|
||||
with open(path) as f:
|
||||
data = f.read()
|
||||
try:
|
||||
data = json.load(path)
|
||||
except:
|
||||
pass
|
||||
else:
|
||||
try:
|
||||
data = ET.parse(path).getroot()
|
||||
except:
|
||||
pass
|
||||
|
||||
fixture_data[path] = data
|
||||
return data
|
||||
|
@ -64,7 +72,7 @@ class TestJunosModule(unittest.TestCase):
|
|||
|
||||
def execute_module(self, failed=False, changed=False, commands=None, sort=True, defaults=False, format='text'):
|
||||
|
||||
self.load_fixtures(commands, format)
|
||||
self.load_fixtures(commands, format, changed=changed)
|
||||
|
||||
if failed:
|
||||
result = self.failed()
|
||||
|
@ -73,12 +81,6 @@ class TestJunosModule(unittest.TestCase):
|
|||
result = self.changed(changed)
|
||||
self.assertEqual(result['changed'], changed, result)
|
||||
|
||||
if commands:
|
||||
if sort:
|
||||
self.assertEqual(sorted(commands), sorted(result['commands']), result['commands'])
|
||||
else:
|
||||
self.assertEqual(commands, result['commands'], result['commands'])
|
||||
|
||||
return result
|
||||
|
||||
def failed(self):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue