-
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_reporter_utils_csv_parser_*.py
- Loading branch information
1 parent
c66bbe5
commit 3674308
Showing
6 changed files
with
235 additions
and
39 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
17 changes: 17 additions & 0 deletions
17
tests/utils/test_reporter_utils_csv_parser_custom_logger.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,17 @@ | ||
# -*- coding: utf-8 -*- | ||
"""Tests for the csv_parser module against custom logger""" | ||
|
||
from logging import Logger, DEBUG, ERROR, FATAL, INFO, WARNING | ||
from random import choice | ||
|
||
from faker import Faker | ||
|
||
from testrail_api_reporter.utils.csv_parser import CSVParser # pylint: disable=import-error,no-name-in-module | ||
|
||
|
||
fake = Faker() | ||
|
||
|
||
def test_custom_csv_logger(): | ||
"""Use custom logger""" | ||
CSVParser(logger=Logger(name=fake.name(), level=choice((DEBUG, INFO, WARNING, ERROR, FATAL)))) |
50 changes: 50 additions & 0 deletions
50
tests/utils/test_reporter_utils_csv_parser_load_history_data.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,50 @@ | ||
# -*- coding: utf-8 -*- | ||
"""Tests for the csv_parser module, 'load_history' function""" | ||
|
||
from datetime import datetime | ||
|
||
import pytest | ||
from faker import Faker | ||
|
||
from testrail_api_reporter.utils.csv_parser import CSVParser # pylint: disable=import-error,no-name-in-module | ||
|
||
|
||
fake = Faker() | ||
|
||
|
||
def test_load_history_data(csv_file, random_stat): | ||
"""Check load_history_data function""" | ||
parser = CSVParser(filename=csv_file) | ||
|
||
total, automated, not_automated, not_applicable = random_stat | ||
year = fake.year() | ||
month = fake.month() | ||
day_of_month = fake.day_of_month() | ||
with open(csv_file, "w") as f: | ||
f.write(f"{year},{month},{day_of_month},{total},{automated},{not_automated},{not_applicable}\n") | ||
|
||
data = parser.load_history_data() | ||
|
||
assert data == [ | ||
[datetime(int(year), int(month), int(day_of_month))], | ||
[str(total)], | ||
[str(automated)], | ||
[str(not_automated)], | ||
[str(not_applicable)], | ||
] | ||
|
||
|
||
def test_load_history_data_no_filename(csv_file): | ||
"""No filename is provided for load history""" | ||
parser = CSVParser() | ||
|
||
with pytest.raises(ValueError): | ||
parser.load_history_data() | ||
|
||
|
||
def test_load_history_data_file_not_found(): | ||
"""File not found error for load history""" | ||
parser = CSVParser(filename="non_existent_file.csv") | ||
|
||
with pytest.raises(ValueError): | ||
parser.load_history_data() |
60 changes: 60 additions & 0 deletions
60
tests/utils/test_reporter_utils_csv_parser_save_history_data.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,60 @@ | ||
# -*- coding: utf-8 -*- | ||
"""Tests for the csv_parser module'""" | ||
from datetime import datetime | ||
|
||
import pytest | ||
from faker import Faker | ||
|
||
from testrail_api_reporter.utils.csv_parser import CSVParser # pylint: disable=import-error,no-name-in-module | ||
|
||
fake = Faker() | ||
|
||
|
||
def test_save_history_data(csv_file, random_stat, case_stat): | ||
"""Check save_history_data function""" | ||
parser = CSVParser(filename=csv_file) | ||
|
||
total, automated, not_automated, not_applicable = random_stat | ||
case_stat.set_total(total) | ||
case_stat.set_automated(automated) | ||
case_stat.set_not_automated(not_automated) | ||
case_stat.set_not_applicable(not_applicable) | ||
|
||
parser.save_history_data(report=case_stat) | ||
|
||
with open(csv_file, "r") as f: | ||
data = f.read() | ||
assert data == ( | ||
f"{datetime.today().strftime('%Y')}," | ||
f"{datetime.today().strftime('%m')}," | ||
f"{datetime.today().strftime('%d')}," | ||
f"{total},{automated},{not_automated},{not_applicable}\n" | ||
) | ||
|
||
|
||
def test_save_history_data_no_filename(csv_file): | ||
"""No filename provided for save history data""" | ||
parser = CSVParser() | ||
|
||
with pytest.raises(ValueError): | ||
parser.save_history_data() | ||
|
||
|
||
def test_save_history_data_no_report(csv_file): | ||
"""No data for save history data""" | ||
parser = CSVParser(filename=csv_file) | ||
|
||
with pytest.raises(ValueError): | ||
parser.save_history_data() | ||
|
||
|
||
def test_save_history_data_already_stored(csv_file, random_stat, case_stat_random): | ||
"""History already stored for such day for save history data""" | ||
parser = CSVParser(filename=csv_file) | ||
|
||
parser.save_history_data(report=case_stat_random) | ||
parser.save_history_data(report=case_stat_random) | ||
|
||
with open(csv_file, "r") as f: | ||
data = f.read() | ||
assert data.count("\n") == 1 |