-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Tests orafin home and download views
- Loading branch information
1 parent
f7dc4d7
commit 2ea332a
Showing
5 changed files
with
64 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
Empty file.
Empty file.
Empty file.
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,64 @@ | ||
import pathlib | ||
|
||
from airflow.www import app as application | ||
from bs4 import BeautifulSoup | ||
from flask.wrappers import Response | ||
import pytest | ||
|
||
from conftest import root_directory | ||
|
||
from libsys_airflow.plugins.orafin.apps.orafin_files_view import OrafinFilesView | ||
|
||
|
||
@pytest.fixture | ||
def test_airflow_client(): | ||
templates_folder = f"{root_directory}/libsys_airflow/plugins/orafin/templates" | ||
files_base = pathlib.Path( | ||
f"{root_directory}/tests/apps/orafin/orafin_file_fixtures" | ||
) | ||
|
||
app = application.create_app(testing=True) | ||
app.config['WTF_CSRF_ENABLED'] = False | ||
setattr(OrafinFilesView, "files_base", files_base) | ||
app.appbuilder.add_view(OrafinFilesView, "Orafin", category="Folio") | ||
app.blueprints['OrafinFilesView'].template_folder = templates_folder | ||
app.response_class = HTMLResponse | ||
|
||
with app.test_client() as client: | ||
yield client | ||
|
||
|
||
class HTMLResponse(Response): | ||
@property | ||
def html(self): | ||
return BeautifulSoup(self.get_data(), "html.parser") | ||
|
||
@property | ||
def files(self): | ||
return [self.get_data()] | ||
|
||
|
||
def test_orafin_files_home(test_airflow_client): | ||
response = test_airflow_client.get("/orafin/") | ||
assert response.status_code == 200 | ||
|
||
feeder_file_links = response.html.select("#feederFileDownloads tbody tr td a") | ||
|
||
assert feeder_file_links[0].attrs['href'] == "/orafin/data/feeder20241130_20241218" | ||
|
||
ap_report_links = response.html.select("#apReportsDownloads tbody tr td a") | ||
|
||
assert len(ap_report_links) == 3 | ||
|
||
|
||
def test_downloads(test_airflow_client): | ||
response = test_airflow_client.get("/orafin/data/feeder20241130_20241218") | ||
assert response.status_code == 200 | ||
|
||
assert response.mimetype.startswith("application/text") | ||
|
||
csv_response = test_airflow_client.get( | ||
"/orafin/reports/xxdl_ap_payments_1218202453000.csv" | ||
) | ||
|
||
assert csv_response.mimetype.startswith("application/csv") |