-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6e87fe5
commit fd0a0f2
Showing
5 changed files
with
130 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,27 @@ | ||
"""Conftest for testsuite""" | ||
|
||
from os import path, remove | ||
|
||
import pytest | ||
from faker import Faker | ||
|
||
|
||
@pytest.fixture | ||
def create_test_file(): | ||
""" | ||
Fixture to create random test file | ||
:return: filename | ||
:rtype: str | ||
""" | ||
test_file = f"not_existing_{Faker().file_name()}" | ||
with open(test_file, "w", encoding="utf-8") as file: | ||
file.write("Test") | ||
assert path.exists(test_file) is True | ||
yield test_file | ||
# Cleanup if not removed by tests | ||
try: | ||
remove(test_file) | ||
except FileNotFoundError: | ||
pass | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
"""Tests for the reporter_utils module, function 'check_captions_and_files'""" | ||
|
||
from logging import getLogger | ||
from random import randint | ||
from unittest.mock import MagicMock | ||
|
||
from faker import Faker | ||
|
||
from testrail_api_reporter.utils.reporter_utils import check_captions_and_files # pylint: disable=import-error,no-name-in-module | ||
|
||
faker = Faker() | ||
|
||
def test_check_captions_and_files_not_list(): | ||
"""Test check_captions_and_files when captions is not a list""" | ||
captions = faker.sentence() | ||
files = [faker.file_name() for _ in range(randint(1, 10))] | ||
|
||
logger = getLogger(__name__) | ||
logger.debug = MagicMock() | ||
|
||
result = check_captions_and_files(captions, files, debug=True, logger=logger) | ||
assert result is None | ||
logger.debug.assert_called_once_with("Captions are not a list, thus no legend will be displayed") | ||
|
||
def test_check_captions_and_files_different_length(): | ||
"""Test check_captions_and_files when captions and files have different lengths""" | ||
captions = [faker.sentence() for _ in range(randint(1, 10))] | ||
files = [faker.file_name() for _ in range(randint(1, 10))] | ||
|
||
logger = getLogger(__name__) | ||
logger.debug = MagicMock() | ||
|
||
result = check_captions_and_files(captions, files, debug=True, logger=logger) | ||
assert result is None | ||
logger.debug.assert_called_once_with( | ||
"Caption and file lists are not the same length %s != %s thus no legend will be displayed", | ||
len(captions), | ||
len(files), | ||
) | ||
|
||
def test_check_captions_and_files_same_length(): | ||
"""Test check_captions_and_files when captions and files have the same length""" | ||
length = randint(1, 10) | ||
captions = [faker.sentence() for _ in range(length)] | ||
files = [faker.file_name() for _ in range(length)] | ||
|
||
result = check_captions_and_files(captions, files, debug=False) | ||
assert result == captions |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
"""Tests for the reporter_utils module, function 'init_get_cases_process'""" | ||
|
||
from testrail_api_reporter.utils.reporter_utils import init_get_cases_process # pylint: disable=import-error,no-name-in-module | ||
|
||
|
||
def test_init_get_cases_process(): | ||
"""Test init_get_cases_process""" | ||
cases_list, first_run, criteria, response, retry = init_get_cases_process() | ||
|
||
assert isinstance(cases_list, list) | ||
assert cases_list == [] | ||
assert first_run is True | ||
assert criteria is None | ||
assert response is None | ||
assert retry == 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
"""Tests for the reporter_utils module, function 'zip_file'""" | ||
|
||
import os | ||
import logging | ||
from unittest.mock import MagicMock | ||
from testrail_api_reporter.utils.reporter_utils import zip_file # pylint: disable=import-error,no-name-in-module | ||
|
||
def test_zip_file_default(create_test_file): | ||
"""Test zip file with default parameters""" | ||
zipped_file = zip_file(create_test_file, debug=False) | ||
assert os.path.exists(zipped_file) is True | ||
os.remove(zipped_file) | ||
os.remove(create_test_file) | ||
|
||
def test_zip_file_suffix(create_test_file): | ||
"""Test zip file with custom suffix""" | ||
zipped_file = zip_file(create_test_file, suffix="_suffix", debug=False) | ||
assert os.path.exists(zipped_file) is True | ||
os.remove(zipped_file) | ||
os.remove(create_test_file) | ||
|
||
def test_zip_file_logger(create_test_file): | ||
"""Test zip file with logger""" | ||
logger = logging.getLogger(__name__) | ||
logger.debug = MagicMock() | ||
zipped_file = zip_file(create_test_file, debug=True, logger=logger) | ||
assert os.path.exists(zipped_file) is True | ||
logger.debug.assert_called_once_with(f"ZIPped {create_test_file} to {zipped_file}") | ||
os.remove(zipped_file) | ||
os.remove(create_test_file) |