-
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.
Added test_engines_plotly_reporter_draw_automation_state_report.py
- Loading branch information
1 parent
86becd9
commit f5e64ae
Showing
9 changed files
with
292 additions
and
21 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
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
97 changes: 97 additions & 0 deletions
97
tests/engines/test_engines_plotly_reporter_draw_automation_state_report.py
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,97 @@ | ||
# -*- coding: utf-8 -*- | ||
"""Tests for plotly_reporter module, the PlotlyReporter clas, draw_automation_state_report method""" | ||
|
||
from os import path, remove, getcwd | ||
from random import choice | ||
|
||
import pytest | ||
from faker import Faker | ||
|
||
from testrail_api_reporter.engines.plotly_reporter import ( # pylint: disable=import-error,no-name-in-module | ||
PlotlyReporter, | ||
) | ||
|
||
|
||
fake = Faker() | ||
|
||
|
||
@pytest.fixture | ||
def random_expected_image(case_stat): | ||
""" | ||
Fixture that chooses random expected image for draw automation state | ||
:param case_stat: fixture returns empty CaseStat object | ||
""" | ||
if choice((False, True)): | ||
case_stat.set_name("Automation State") | ||
case_stat.total = 5905 | ||
case_stat.automated = 19100 | ||
case_stat.not_automated = 27205 | ||
case_stat.not_applicable = 10092 | ||
return {"filename": f"{getcwd()}/tests/assets/expected_automation_state.png", "data": [case_stat]} | ||
else: | ||
case_stat.set_name("Automation State") | ||
return {"filename": f"{getcwd()}/tests/assets/expected_automation_state_empty.png", "data": [case_stat]} | ||
|
||
|
||
def test_draw_automation_state_report_no_reports(caplog, random_plotly_reporter): | ||
""" | ||
Init PlotlyReporter and call draw_automation_state_report without reports should raise ValueError | ||
:param caplog: caplog fixture | ||
:param random_plotly_reporter: fixture returns PlotlyReporter | ||
""" | ||
with pytest.raises(ValueError, match="No TestRail reports are provided, report aborted!"): | ||
random_plotly_reporter.draw_automation_state_report( | ||
filename=fake.file_name(extension=choice(("png", "jpg", "jpeg", "webp"))) | ||
) | ||
|
||
|
||
def test_draw_automation_state_report_no_filename(caplog, random_plotly_reporter): | ||
""" | ||
Init PlotlyReporter and call draw_automation_state_report without filename should raise ValueError | ||
:param caplog: caplog fixture | ||
:param random_plotly_reporter: fixture returns PlotlyReporter | ||
""" | ||
with pytest.raises(ValueError, match="No output filename is provided, report aborted!"): | ||
random_plotly_reporter.draw_automation_state_report(reports=[fake.pydict()]) | ||
|
||
|
||
def test_draw_automation_state_report_creates_file(caplog, case_stat, case_stat_random, random_plotly_reporter): | ||
""" | ||
Init PlotlyReporter and call draw_automation_state_report with valid parameters should create file | ||
:param caplog: caplog fixture | ||
:param case_stat: fixture returns empty CaseStat object | ||
:param case_stat_random: fixture returns filled with random data CaseStat object | ||
:param random_plotly_reporter: fixture returns PlotlyReporter | ||
""" | ||
filename = fake.file_name(extension=choice(("png", "jpg", "jpeg", "webp"))) | ||
try: | ||
reports = [case_stat, case_stat_random] | ||
random_plotly_reporter.draw_automation_state_report(filename=filename, reports=reports) | ||
|
||
assert path.exists(filename) | ||
finally: | ||
if path.exists(filename): | ||
remove(filename) | ||
|
||
|
||
def test_draw_automation_state_report_creates_correct_image(caplog, random_expected_image, compare_image): | ||
""" | ||
Init PlotlyReporter and call draw_automation_state_report with valid parameters should create correct image | ||
:param caplog: caplog fixture | ||
:param random_expected_image: fixture, returns any of possible expected cases | ||
:param compare_image: fixture, returns function to compare images | ||
""" | ||
type_platforms = [{"name": "Automation State", "sections": [42, 1024, 0]}] | ||
filename = "actual_automation_state.png" | ||
try: | ||
plotly_reporter = PlotlyReporter(type_platforms=type_platforms) | ||
plotly_reporter.draw_automation_state_report(filename=filename, reports=random_expected_image["data"]) | ||
assert compare_image(actual=filename, expected=random_expected_image["filename"]) | ||
finally: | ||
if path.exists(filename): | ||
remove(filename) |
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,88 @@ | ||
# -*- coding: utf-8 -*- | ||
"""Tests for plotly_reporter module, the PlotlyReporter class, init method""" | ||
|
||
from logging import getLogger, INFO, WARNING, ERROR, FATAL | ||
from os import path, remove | ||
from random import randint, choice | ||
|
||
import pytest | ||
from faker import Faker | ||
|
||
from testrail_api_reporter.engines.plotly_reporter import ( # pylint: disable=import-error,no-name-in-module | ||
PlotlyReporter, | ||
) | ||
from testrail_api_reporter.utils.logger_config import ( # pylint: disable=import-error,no-name-in-module | ||
setup_logger, | ||
DEFAULT_LOGGING_LEVEL, | ||
) | ||
|
||
fake = Faker() | ||
|
||
|
||
def test_plotly_reporter_init_default_params(caplog): | ||
"""Init PlotlyReporter with default parameters""" | ||
type_platforms = [{"name": fake.word(), "sections": [randint(1, 10000)]} for _ in range(randint(1, 5))] | ||
|
||
plotly_reporter = PlotlyReporter(type_platforms=type_platforms) | ||
|
||
logger = getLogger("PlotlyReporter") | ||
assert logger.level == DEFAULT_LOGGING_LEVEL | ||
assert path.exists("PlotlyReporter.log") | ||
|
||
attributes = vars(plotly_reporter) | ||
assert attributes['_PlotlyReporter__pr_labels'] == ["Low", "Medium", "High", "Critical"] | ||
assert attributes['_PlotlyReporter__pr_colors'] == ["rgb(173,216,230)", "rgb(34,139,34)", "rgb(255,255,51)", "rgb(255, 153, 153)"] | ||
assert attributes['_PlotlyReporter__ar_colors'] == [ | ||
"rgb(255, 153, 153)", | ||
"rgb(255,255,51)", | ||
"rgb(34,139,34)", | ||
"rgb(173,216,230)", | ||
"rgb(65,105,225)", | ||
"rgb(192, 192, 192)", | ||
] | ||
assert attributes['_PlotlyReporter__lines'] == {"color": "rgb(0,0,51)", "width": 1.5} | ||
assert attributes['_PlotlyReporter__type_platforms'] == type_platforms | ||
|
||
|
||
def test_plotly_reporter_init_custom_params(caplog): | ||
"""Init PlotlyReporter with custom parameters""" | ||
logger_file = fake.file_name(extension="log") | ||
logger_name = fake.name() | ||
logger_level = choice((INFO, WARNING, ERROR, FATAL)) | ||
try: | ||
logger = setup_logger(logger_name, logger_file, level=logger_level) | ||
type_platforms = [{"name": fake.word(), "sections": [randint(1, 10000)]} for _ in range(randint(1, 5))] | ||
pr_labels = [fake.word() for _ in range(4)] | ||
pr_colors = [f"rgb({randint(0, 255)},{randint(0, 255)},{randint(0, 255)})" for _ in range(4)] | ||
ar_colors = [f"rgb({randint(0, 255)},{randint(0, 255)},{randint(0, 255)})" for _ in range(6)] | ||
lines = {"color": f"rgb({randint(0, 255)},{randint(0, 255)},{randint(0, 255)})", "width": randint(1, 3)} | ||
|
||
plotly_reporter = PlotlyReporter( | ||
pr_colors=pr_colors, | ||
pr_labels=pr_labels, | ||
ar_colors=ar_colors, | ||
lines=lines, | ||
type_platforms=type_platforms, | ||
logger=logger, | ||
log_level=INFO, | ||
) | ||
|
||
logger = getLogger(logger_name) | ||
assert logger.level == logger_level | ||
assert path.exists(logger_file) | ||
|
||
attributes = vars(plotly_reporter) | ||
assert attributes['_PlotlyReporter__pr_labels'] == pr_labels | ||
assert attributes['_PlotlyReporter__pr_colors'] == pr_colors | ||
assert attributes['_PlotlyReporter__ar_colors'] == ar_colors | ||
assert attributes['_PlotlyReporter__lines'] == lines | ||
assert attributes['_PlotlyReporter__type_platforms'] == type_platforms | ||
finally: | ||
if path.exists(logger_file): | ||
remove(logger_file) | ||
|
||
|
||
def test_plotly_reporter_init_no_type_platforms(caplog): | ||
"""Init PlotlyReporter without type_platforms should raise ValueError""" | ||
with pytest.raises(ValueError, match="Platform types is not provided, Plotly Reporter cannot be initialized!"): | ||
PlotlyReporter() |
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