Skip to content

Commit 38d7036

Browse files
committed
Make chromium test expect configured chrome binary path
The chrome binary used for pdf generation is controlled by the CHROME_BIN_PATH environment variable, but the test in in process_report/tests/integration/test_chromium.py expected the literal path `/usr/bin/chromium`. This would cause the tests to fail if run in an environment in which chromium was not installed, even if the code successfully used an alternate path.
1 parent 2a9f5a5 commit 38d7036

File tree

2 files changed

+6
-7
lines changed

2 files changed

+6
-7
lines changed

process_report/invoices/pi_specific_invoice.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414

1515
TEMPLATE_DIR_PATH = "process_report/templates"
16+
CHROME_BIN_PATH = os.environ.get("CHROME_BIN_PATH", "/usr/bin/chromium")
1617

1718

1819
logger = logging.getLogger(__name__)
@@ -120,20 +121,17 @@ def _create_html_invoice(temp_fd):
120121
temp_fd.flush()
121122

122123
def _create_pdf_invoice(temp_fd_name):
123-
chrome_binary_location = os.environ.get(
124-
"CHROME_BIN_PATH", "/usr/bin/chromium"
125-
)
126-
if not os.path.exists(chrome_binary_location):
124+
if not os.path.exists(CHROME_BIN_PATH):
127125
sys.exit(
128-
f"Chrome binary does not exist at {chrome_binary_location}. Make sure the env var CHROME_BIN_PATH is set correctly and that Google Chrome is installed"
126+
f"Chrome binary does not exist at {CHROME_BIN_PATH}. Make sure the env var CHROME_BIN_PATH is set correctly and that Google Chrome is installed"
129127
)
130128

131129
invoice_pdf_path = (
132130
f"{self.name}/{pi_instituition}_{pi}_{self.invoice_month}.pdf"
133131
)
134132
subprocess.run(
135133
[
136-
chrome_binary_location,
134+
CHROME_BIN_PATH,
137135
"--headless",
138136
"--no-sandbox",
139137
f"--print-to-pdf={invoice_pdf_path}",

process_report/tests/unit/invoices/test_pi_specific_invoice.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import pandas
44

55
from process_report.tests import util as test_utils
6+
from process_report.invoices.pi_specific_invoice import CHROME_BIN_PATH
67

78

89
class TestPISpecificInvoice(TestCase):
@@ -137,7 +138,7 @@ def test_export_pi(self, mock_subprocess_run, mock_path_exists, mock_filter_cols
137138
for i, pi_pdf_path in enumerate([pi_pdf_1, pi_pdf_2]):
138139
chrome_arglist, _ = mock_subprocess_run.call_args_list[i]
139140
answer_arglist = [
140-
"/usr/bin/chromium",
141+
CHROME_BIN_PATH,
141142
"--headless",
142143
"--no-sandbox",
143144
f"--print-to-pdf={pi_pdf_path}",

0 commit comments

Comments
 (0)