You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
138 lines
7.3 KiB
138 lines
7.3 KiB
import pytest
|
|
import os
|
|
from calculate.templates.template_processor import TemplateParameters, DIR,\
|
|
FILE, IncorrectParameter,\
|
|
TemplateAction
|
|
from calculate.utils.files import join_paths
|
|
from pprint import pprint
|
|
|
|
|
|
CHROOT_PATH = os.path.join(os.getcwd(), 'tests/templates/testfiles')
|
|
|
|
|
|
@pytest.mark.template_parameters
|
|
class TestTemplateParameters:
|
|
def test_if_TemplateParameters_object_is_initialized_accoding_to_dictionary_of_correct_template_parameters__the_TemplateParameters_object_contains_processed_parameters_as_its_attributes_including_default_values(self):
|
|
parameters = {'append': 'join',
|
|
'chmod': '600',
|
|
'force': True}
|
|
template_parameters = TemplateParameters(parameters, DIR)
|
|
assert (template_parameters.append == 'join' and
|
|
template_parameters.chmod == 0o600 and
|
|
template_parameters.force and
|
|
not template_parameters.autoupdate)
|
|
|
|
def test_if_TemplateParameters_object_is_intialized_using_dictionary_with_append_parameter__a_value_of_the_parameter_will_be_checked(self):
|
|
parameters = {'append': 'join'}
|
|
# Для получения множества доступных значений параметра append.
|
|
TemplateAction()
|
|
try:
|
|
template_parameters = TemplateParameters(parameters, FILE)
|
|
assert template_parameters.append == 'join'
|
|
except Exception as error:
|
|
pytest.fail('Unexpected exception: {0}'.
|
|
format(str(error)))
|
|
|
|
def test_if_TemplateParameters_object_is_intialized_using_dictionary_with_correct_source_parameter__the_object_will_be_initialized_successfully(self):
|
|
parameters = {'source': '/test_dir_1/file.test'}
|
|
|
|
try:
|
|
template_parameters = TemplateParameters(parameters, FILE,
|
|
chroot_path=CHROOT_PATH)
|
|
assert template_parameters.source == join_paths(
|
|
CHROOT_PATH,
|
|
'/test_dir_1/file.test')
|
|
except Exception as error:
|
|
pytest.fail('Unexpected exception: {0}'.
|
|
format(str(error)))
|
|
|
|
def test_if_TemplateParameters_object_is_intialized_as_dir_parameters_object_using_correct_source_parameter_with_append_link__the_object_will_be_initialized_successfully(self):
|
|
parameters = {'append': 'link', 'source': '/test_dir_1'}
|
|
|
|
try:
|
|
template_parameters = TemplateParameters(parameters, DIR,
|
|
chroot_path=CHROOT_PATH)
|
|
assert template_parameters.source == join_paths(CHROOT_PATH,
|
|
'/test_dir_1')
|
|
except Exception as error:
|
|
pytest.fail('Unexpected exception: {0}'.
|
|
format(str(error)))
|
|
|
|
def test_if_TemplateParameters_object_is_intialized_using_source_parameter_with_unexisting_file_path__the_initialization_of_the_object_will_be_failed(self):
|
|
parameters = {'source': '/test_dir_1/unexisted_file.test'}
|
|
with pytest.raises(IncorrectParameter):
|
|
template_parameters = TemplateParameters(parameters, FILE)
|
|
|
|
def test_if_TemplateParameters_object_is_intialized_as_dir_parameters_object_using_source_parameter_but_without_append_link__the_initialization_of_the_object_will_be_failed(self):
|
|
parameters = {'source': '/test_dir_1/file.test'}
|
|
with pytest.raises(IncorrectParameter):
|
|
template_parameters = TemplateParameters(parameters, DIR,
|
|
chroot_path=CHROOT_PATH)
|
|
|
|
def test_if_TemplateParameters_object_is_intialized_using_dictionary_with_correct_force_parameter__the_object_will_be_initialized_successfully(self):
|
|
parameters = {'force': True}
|
|
try:
|
|
template_parameters = TemplateParameters(parameters, FILE)
|
|
assert template_parameters.force
|
|
except Exception as error:
|
|
pytest.fail('Unexpected exception: {0}'.
|
|
format(str(error)))
|
|
|
|
def test_if_TemplateParameters_object_is_intialized_using_dictionary_with_incorrect_force_parameter__the_initialization_of_the_object_will_be_failed(self):
|
|
parameters = {'force': 'value'}
|
|
with pytest.raises(IncorrectParameter):
|
|
template_parameters = TemplateParameters(parameters, FILE)
|
|
|
|
def test_if_TemplateParameters_object_is_intialized_using_dictionary_with_autoupdate_parameter__a_value_of_the_parameter_will_be_checked(self):
|
|
parameters = {'autoupdate': True}
|
|
try:
|
|
template_parameters = TemplateParameters(parameters, FILE)
|
|
assert template_parameters.autoupdate
|
|
except Exception as error:
|
|
pytest.fail('Unexpected exception: {0}'.
|
|
format(str(error)))
|
|
|
|
def test_if_TemplateParameters_object_is_intialized_using_dictionary_with_incorrect_autoupdate_parameter__the_initialization_of_the_object_will_be_failed(self):
|
|
parameters = {'autoupdate': 'value'}
|
|
with pytest.raises(IncorrectParameter):
|
|
template_parameters = TemplateParameters(parameters, FILE)
|
|
|
|
def test_if_TemplateParameters_object_is_intialized_using_dictionary_with_correct_chown_parameter__the_object_will_be_initialized_successfully(self):
|
|
parameters = {'chown': 'root:root'}
|
|
try:
|
|
template_parameters = TemplateParameters(parameters, FILE)
|
|
assert template_parameters.chown == {'uid': 0, 'gid': 0}
|
|
except Exception as error:
|
|
pytest.fail('Unexpected exception: {0}'.
|
|
format(str(error)))
|
|
|
|
def test_if_TemplateParameters_object_is_intialized_using_dictionary_with_correct_chown_parameter_in_its_digital_form__the_object_will_be_initialized_successfully(self):
|
|
uid = os.getuid()
|
|
gid = os.getgid()
|
|
parameters = {'chown': '{0}:{1}'.format(uid, gid)}
|
|
try:
|
|
template_parameters = TemplateParameters(parameters, FILE)
|
|
assert template_parameters.chown == {'uid': uid, 'gid': gid}
|
|
except Exception as error:
|
|
pytest.fail('Unexpected exception: {0}'.
|
|
format(str(error)))
|
|
|
|
def test_if_TemplateParameters_object_is_intialized_using_dictionary_with_incorrect_chown_parameter__the_initialization_of_the_object_will_be_failed(self):
|
|
parameters = {'chown': 'wrong_user_name:wrong_group_name'}
|
|
with pytest.raises(IncorrectParameter):
|
|
template_parameters = TemplateParameters(parameters, FILE)
|
|
|
|
def test_if_TemplateParameters_object_is_intialized_using_dictionary_with_correct_chmod_parameter__the_object_will_be_initialized_successfully(self):
|
|
try:
|
|
parameters = {'chmod': 'rw-r--r--'}
|
|
template_parameters = TemplateParameters(parameters, FILE)
|
|
assert template_parameters.chmod == 0o644
|
|
del(template_parameters)
|
|
|
|
parameters = {'chmod': '600'}
|
|
template_parameters = TemplateParameters(parameters, FILE)
|
|
assert template_parameters.chmod == 0o600
|
|
except Exception as error:
|
|
pytest.fail('Unexpected exception: {0}'.
|
|
format(str(error)))
|