Skip to content

Commit

Permalink
Added test_engines_plotly_reporter_draw_test_case_by_priority.py.py
Browse files Browse the repository at this point in the history
  • Loading branch information
wwakabobik committed Aug 30, 2024
1 parent 9e64152 commit ea283cb
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 1 deletion.
Binary file added tests/assets/expected_case_by_priority.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-
"""Tests for plotly_reporter module, the PlotlyReporter clas, draw_automation_state_report method"""
"""Tests for plotly_reporter module, the PlotlyReporter clas, draw_test_case_by_area method"""

from copy import deepcopy
from os import path, remove, getcwd
from random import choice
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# -*- coding: utf-8 -*-
"""Tests for plotly_reporter module, the PlotlyReporter clas, draw_test_case_by_priority method"""

from os import path, remove, getcwd
from random import choice, randint

import pytest
from faker import Faker


fake = Faker()


def test_draw_test_case_by_priority_no_cases(caplog, random_plotly_reporter):
"""
Init PlotlyReporter and call draw_test_case_by_priority without cases should raise ValueError
:param caplog: caplog fixture
:param random_plotly_reporter: fixture returns PlotlyReporter
"""
with pytest.raises(ValueError, match="No TestRail values are provided, report aborted!"):
random_plotly_reporter.draw_test_case_by_priority(
filename=fake.file_name(extension=choice(("png", "jpg", "jpeg", "webp")))
)


def test_draw_test_case_by_priority_no_filename(caplog, random_plotly_reporter):
"""
Init PlotlyReporter and call draw_test_case_by_priority 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_test_case_by_priority(values=[fake.pydict()])


def test_draw_test_case_by_priority_creates_file(caplog, random_plotly_reporter):
"""
Init PlotlyReporter and call draw_test_case_by_priority with valid parameters should create file
:param caplog: caplog fixture
:param random_plotly_reporter: fixture returns PlotlyReporter
"""
filename = fake.file_name(extension=choice(("png", "jpg", "jpeg", "webp")))
try:
random_plotly_reporter.draw_test_case_by_priority(filename=filename, values=[randint(0, 1024) for _ in range(randint(1, 4))])

assert path.exists(filename)
finally:
if path.exists(filename):
remove(filename)


def test_draw_test_case_by_priority_creates_correct_image(caplog, compare_image, random_plotly_reporter):
"""
Init PlotlyReporter and call draw_test_case_by_priority with valid parameters should create correct image
:param caplog: caplog fixture
:param compare_image: fixture, returns function to compare images
:param random_plotly_reporter: fixture returns PlotlyReporter
"""
filename = "actual_test_case_by_priority.png"
try:
random_plotly_reporter.draw_test_case_by_priority(filename=filename, values=[1, 101, 72, 16])
assert compare_image(actual=filename, expected=f"{getcwd()}/tests/assets/expected_case_by_priority.png")
finally:
if path.exists(filename):
remove(filename)

0 comments on commit ea283cb

Please sign in to comment.