Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the --browser option #504

Merged
merged 2 commits into from Aug 27, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 4 additions & 4 deletions scanapi/reporter.py
@@ -1,8 +1,8 @@
#!/usr/bin/env python3
import datetime
import logging
import pathlib
import webbrowser
from os.path import abspath

from pkg_resources import get_distribution

Expand All @@ -25,7 +25,7 @@ class Reporter:

def __init__(self, output_path=None, template=None):
"""Creates a Reporter instance object."""
self.output_path = output_path or "scanapi-report.html"
self.output_path = pathlib.Path(output_path or "scanapi-report.html")
self.template = template

def write(self, results):
Expand All @@ -51,11 +51,11 @@ def write(self, results):
doc.write(content)

logger.info("\nThe documentation was generated successfully.")
logger.info(f"It is available at {abspath(self.output_path)}")
logger.info(f"It is available at {self.output_path.resolve().as_uri()}")

def open_report_in_browser(self):
"""Open the results file on a browser"""
webbrowser.open(self.output_path)
webbrowser.open(self.output_path.resolve().as_uri())

@staticmethod
def write_without_generating_report(results):
Expand Down
14 changes: 8 additions & 6 deletions tests/unit/test_reporter.py
@@ -1,3 +1,5 @@
import pathlib

from freezegun.api import FakeDatetime
from pytest import fixture, mark

Expand All @@ -20,7 +22,7 @@ class TestInit:
def test_init_output_path_and_template(self):
reporter = Reporter()

assert reporter.output_path == "scanapi-report.html"
assert str(reporter.output_path) == "scanapi-report.html"
assert reporter.template is None

@mark.context("when there is a template argument")
Expand All @@ -31,7 +33,7 @@ def test_init_output_path_and_template(self):
def test_init_output_path_and_template_2(self):
reporter = Reporter(template="my_template.jinja")

assert reporter.output_path == "scanapi-report.html"
assert str(reporter.output_path) == "scanapi-report.html"
assert reporter.template == "my_template.jinja"

@mark.context("when there is an output path argument")
Expand All @@ -41,7 +43,7 @@ def test_init_output_path_and_template_2(self):
def test_init_output_path_and_template_3(self):
reporter = Reporter(output_path="my-report.html")

assert reporter.output_path == "my-report.html"
assert str(reporter.output_path) == "my-report.html"
assert reporter.template is None


Expand Down Expand Up @@ -103,7 +105,7 @@ def test_should_write_to_default_output(

mocked__render.assert_called_once_with("report.html", context, False)
mocked__open.assert_called_once_with(
"scanapi-report.html", "w", newline="\n"
pathlib.Path("scanapi-report.html"), "w", newline="\n"
)
mocked__open().write.assert_called_once_with("ScanAPI Report")

Expand All @@ -123,7 +125,7 @@ def test_should_write_to_custom_output(

mocked__render.assert_called_once_with("html", context, True)
mocked__open.assert_called_once_with(
"./custom/report-output.html", "w", newline="\n"
pathlib.Path("./custom/report-output.html"), "w", newline="\n"
)
mocked__open().write.assert_called_once_with("ScanAPI Report")

Expand All @@ -145,7 +147,7 @@ def test_should_handle_custom_templates(
"my-template.html", context, True
)
mocked__open.assert_called_once_with(
"scanapi-report.html", "w", newline="\n"
pathlib.Path("scanapi-report.html"), "w", newline="\n"
)
mocked__open().write.assert_called_once_with("ScanAPI Report")

Expand Down