Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from unittest import TestCase, mock
import pandas
import pytest

import json
from process_report.tests import util as test_utils


Expand Down Expand Up @@ -259,3 +259,27 @@ def test_missing_project_cluster_tuples(self, mock_get_allocation_data):
assert str(cm.value) == (
f"Projects {expected_missing} not found in Coldfront and are billable! Please check the project names"
)

def test_get_coldfront_api_data_with_filepath(self):
mock_api_data = [{"project": "test"}]
with mock.patch(
"builtins.open", mock.mock_open(read_data=json.dumps(mock_api_data))
):
proc = test_utils.new_coldfront_fetch_processor(
coldfront_data_filepath="fake/path.json"
)
result = proc._get_coldfront_api_data()
assert result == mock_api_data

def test_get_allocation_data_missing_key(self):
"""Malformed allocation entries with missing keys are skipped."""
test_allocation_data = [
{
"resource": {"name": "stack"},
"project": {"pi": "PI1"},
"attributes": {},
}, # missing Allocated Project ID
]
proc = test_utils.new_coldfront_fetch_processor()
result = proc._get_allocation_data(test_allocation_data)
assert result == {} # malformed entry was skipped
Loading