-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
449 additions
and
6 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
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,136 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
import datetime | ||
import pytest | ||
import uuid | ||
|
||
from AIPscan.Data import data | ||
from AIPscan.models import AIP, File, FileType, StorageService | ||
|
||
TEST_FILES = [ | ||
File( | ||
uuid=uuid.uuid4(), | ||
name="test.csv", | ||
size=1234567, | ||
aip_id=1, | ||
file_type=FileType.original, | ||
file_format="Comma Separated Values", | ||
filepath="/path/to/file.csv", | ||
date_created=datetime.datetime.now(), | ||
checksum_type="md5", | ||
checksum_value="fakemd5", | ||
), | ||
File( | ||
uuid=uuid.uuid4(), | ||
name="test.txt", | ||
size=12345, | ||
aip_id=2, | ||
file_type=FileType.original, | ||
file_format="Plain Text File", | ||
puid="x-fmt/111", | ||
filepath="/path/to/file.txt", | ||
date_created=datetime.datetime.now(), | ||
checksum_type="md5", | ||
checksum_value="anotherfakemd5", | ||
), | ||
File( | ||
uuid=uuid.uuid4(), | ||
name="test.pdf", | ||
size=12345678, | ||
aip_id=1, | ||
file_type=FileType.preservation, | ||
file_format="Acrobat PDF/A - Portable Document Format", | ||
format_version="1b", | ||
filepath="/path/to/test.pdf", | ||
date_created=datetime.datetime.now(), | ||
checksum_type="md5", | ||
checksum_value="yetanotherfakemd5", | ||
original_file_id=1, | ||
), | ||
] | ||
|
||
MOCK_STORAGE_SERVICE_ID = 1 | ||
MOCK_STORAGE_SERVICE_NAME = "some name" | ||
TEST_STORAGE_SERVICE = StorageService( | ||
name=MOCK_STORAGE_SERVICE_NAME, | ||
url="http://example.com", | ||
user_name="test", | ||
api_key="test", | ||
download_limit=20, | ||
download_offset=10, | ||
default=False, | ||
) | ||
|
||
MOCK_AIP_NAME = "Test transfer" | ||
MOCK_AIP_UUID = uuid.uuid4() | ||
TEST_AIP = AIP( | ||
uuid=MOCK_AIP_UUID, | ||
transfer_name=MOCK_AIP_NAME, | ||
create_date=datetime.datetime.now(), | ||
storage_service_id=MOCK_STORAGE_SERVICE_ID, | ||
fetch_job_id=1, | ||
) | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"file_data, file_count", [([], 0), (TEST_FILES, 3), (TEST_FILES[:2], 2)] | ||
) | ||
def test_largest_files(mocker, file_data, file_count): | ||
"""Test that return value conforms to expected structure. | ||
""" | ||
mock_query = mocker.patch("AIPscan.Data.data._largest_files_query") | ||
mock_query.return_value = file_data | ||
|
||
mock_get_ss = mocker.patch("AIPscan.Data.data._get_storage_service") | ||
mock_get_ss.return_value = TEST_STORAGE_SERVICE | ||
|
||
mock_get_aip = mocker.patch("sqlalchemy.orm.query.Query.get") | ||
mock_get_aip.return_value = TEST_AIP | ||
|
||
report = data.largest_files(MOCK_STORAGE_SERVICE_ID) | ||
report_files = report[data.FIELD_FILES] | ||
assert report[data.FIELD_STORAGE_NAME] == MOCK_STORAGE_SERVICE_NAME | ||
assert len(report_files) == file_count | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"test_file, has_format_version, has_puid", | ||
[ | ||
(TEST_FILES[0], False, False), | ||
(TEST_FILES[1], False, True), | ||
(TEST_FILES[2], True, False), | ||
], | ||
) | ||
def test_largest_files_elements(mocker, test_file, has_format_version, has_puid): | ||
"""Test that returned file data matches expected values. | ||
""" | ||
mock_query = mocker.patch("AIPscan.Data.data._largest_files_query") | ||
mock_query.return_value = [test_file] | ||
|
||
mock_get_ss = mocker.patch("AIPscan.Data.data._get_storage_service") | ||
mock_get_ss.return_value = TEST_STORAGE_SERVICE | ||
|
||
mock_get_aip = mocker.patch("sqlalchemy.orm.query.Query.get") | ||
mock_get_aip.return_value = TEST_AIP | ||
|
||
report = data.largest_files(MOCK_STORAGE_SERVICE_ID) | ||
report_file = report[data.FIELD_FILES][0] | ||
|
||
# Required elements | ||
assert test_file.name == report_file.get(data.FIELD_NAME) | ||
assert test_file.file_format == report_file.get(data.FIELD_FORMAT) | ||
|
||
# Optional elements | ||
if has_format_version: | ||
assert test_file.format_version == report_file.get(data.FIELD_VERSION) | ||
else: | ||
assert report_file.get(data.FIELD_VERSION) is None | ||
|
||
if has_puid: | ||
assert test_file.puid == report_file.get(data.FIELD_PUID) | ||
else: | ||
assert report_file.get(data.FIELD_PUID) is None | ||
|
||
# AIP information | ||
assert report_file.get(data.FIELD_AIP_NAME) == MOCK_AIP_NAME | ||
assert report_file.get(data.FIELD_AIP_UUID) == MOCK_AIP_UUID |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
from flask import render_template, request | ||
|
||
from AIPscan.Data import data | ||
from AIPscan.Reporter import reporter, translate_headers | ||
|
||
|
||
@reporter.route("/largest_files/", methods=["GET"]) | ||
def largest_files(): | ||
"""Return largest files.""" | ||
storage_service_id = request.args.get("amss_id") | ||
file_type = request.args.get("file_type") | ||
limit = 20 | ||
try: | ||
limit = int(request.args.get("limit", 20)) | ||
except ValueError: | ||
pass | ||
# TODO: Make limit configurable - currently set to default of 20 | ||
file_data = data.largest_files( | ||
storage_service_id=storage_service_id, file_type=file_type, limit=limit | ||
) | ||
storage_service_name = file_data[data.FIELD_STORAGE_NAME] | ||
headers = [ | ||
data.FIELD_FILENAME, | ||
data.FIELD_SIZE, | ||
data.FIELD_FORMAT, | ||
data.FIELD_PUID, | ||
data.FIELD_FILE_TYPE, | ||
data.FIELD_AIP, | ||
] | ||
return render_template( | ||
"report_largest_files.html", | ||
storage_service_id=storage_service_id, | ||
storage_service_name=storage_service_name, | ||
columns=translate_headers(headers), | ||
files=file_data[data.FIELD_FILES], | ||
file_type=file_type, | ||
limit=limit, | ||
) |
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
Oops, something went wrong.