unit tests, fix returned data

This commit is contained in:
Pieprzycki Piotr
2016-11-11 23:35:51 +01:00
parent 681797fc6d
commit 0518980ab8
42 changed files with 713 additions and 142 deletions

56
test/unit/conftest.py Normal file
View File

@@ -0,0 +1,56 @@
"""Test fixtures."""
from builtins import super
import pytest
from napalm_base.test import conftest as parent_conftest
from napalm_base.test.double import BaseTestDouble
from napalm_vyos import vyos
@pytest.fixture(scope='class')
def set_device_parameters(request):
"""Set up the class."""
def fin():
request.cls.device.close()
request.addfinalizer(fin)
request.cls.driver = vyos.VyOSDriver
request.cls.patched_driver = PatchedVyOSDriver
request.cls.vendor = 'vyos'
parent_conftest.set_device_parameters(request)
def pytest_generate_tests(metafunc):
"""Generate test cases dynamically."""
parent_conftest.pytest_generate_tests(metafunc, __file__)
class PatchedVyOSDriver(vyos.VyOSDriver):
"""Patched VyOS Driver."""
def __init__(self, hostname, username, password, timeout=60, optional_args=None):
super().__init__(hostname, username, password, timeout, optional_args)
self.patched_attrs = ['device']
self.device = FakeVyOSDevice()
class FakeVyOSDevice(BaseTestDouble):
"""VyOS device test double."""
def run_commands(self, command_list, encoding='json'):
"""Fake run_commands."""
result = list()
for command in command_list:
filename = '{}.{}'.format(self.sanitize_text(command), encoding)
full_path = self.find_file(filename)
if encoding == 'json':
result.append(self.read_json_file(full_path))
else:
result.append({'output': self.read_txt_file(full_path)})
return result