"""Test whether dot dict works right.""" import os import pytest from salessheets import config from salessheets.utils import misc TEST_VALUE = 'test_value' TEST_FILE_PATH = os.path.join(config.TEMPLATE_PATH, 'test.html') ONE_PARAGRAPH_STR = 'Lorem ipsum dolor sit amet, consectetur adipiscing ' \ 'elit, sed do eiusmod tempor incididunt ut labore et ' \ 'dolore magna aliqua.' MANY_PARAGRAPH_STR = 'Lorem ipsum dolor sit amet, consectetur adipiscing ' \ 'elit, sed do eiusmod tempor incididunt ut labore ' \ 'et dolore magna aliqua. \r\n Ut enim ad minim veniam, ' \ 'quis nostrud exercitation ullamco laborisnisi ut ' \ 'aliquip ex ea commodo consequat. \r\n Duis aute irure ' \ 'dolor in reprehenderit in voluptate velit esse cillum ' \ 'dolore eu fugiat nulla pariatur.' def test_dot_dict_get_set(): """Test DotDict get and set value.""" context = misc.DotDict() context.test_value = TEST_VALUE assert context.test_value == TEST_VALUE def test_dot_dict_no_value(): """Test DotDict get value that does not exist returns None.""" context = misc.DotDict() assert context.test_value is None def test_dot_set_dict_get(): """Test DotDict set/get value with dot notation.""" context = misc.DotDict() context.test_value = TEST_VALUE assert context['test_value'] == TEST_VALUE def test_dict_set_dot_get(): """Test DotDict get/set value with dict notation.""" context = misc.DotDict() context['test_value'] = TEST_VALUE assert context.test_value == TEST_VALUE def test_remove_file(): """Test remove_file removes existing file.""" with open(TEST_FILE_PATH, 'a') as file: file.write('test_value') misc.remove_file(TEST_FILE_PATH) result = os.path.isfile(TEST_FILE_PATH) assert not result def test_remove_no_existing_file(): """Test remove_file runs with non-existing file without exception.""" try: misc.remove_file('some/unreal/path/to/file.py') except FileNotFoundError: pytest.fail('FileNotFound Exception should not raise') def test_split_text_in_paragraphs_with_one_paragraph(): """Test split_text_in_paragraphs with one-paragraph string.""" paragraph_list = misc.split_text_in_paragraphs(ONE_PARAGRAPH_STR) assert len(paragraph_list) == 1 assert type(paragraph_list) is list def test_split_text_in_paragraphs_with_many_paragraph(): """Test split_text_in_paragraphs with many-paragraph string.""" paragraph_list = misc.split_text_in_paragraphs(MANY_PARAGRAPH_STR) assert len(paragraph_list) == 3 assert type(paragraph_list) is list def test_split_text_in_paragraphs_in_case_description_is_none(): """Test split_text_in_paragraphs with None instead of string.""" paragraph_list = misc.split_text_in_paragraphs(None) assert len(paragraph_list) == 0 assert type(paragraph_list) is list def test_cleanup_dict(): """Test cleanup_dict() function.""" expected_result = { 'key': '', 'second': 'Data', 'third': '', 'fourth': 0, 'fifth': 0 } result = misc.cleanup_dict({ 'key': None, 'second': 'Data', 'third': ' ', 'fourth': 0, 'fifth': False }) assert result == expected_result