Skip to content
Open
Changes from 1 commit
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,31 @@ 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

@mock.patch(
"process_report.processors.coldfront_fetch_processor.ColdfrontFetchProcessor._fetch_coldfront_allocation_api",
)
def test_get_allocation_data_missing_key(self, mock_get_allocation_data):

@QuanMPhm QuanMPhm Jun 4, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at this test, it does not seem like you need any mocking at all. The test itself can be shortened.

    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 allocation entries with missing keys are skipped."""
mock_get_allocation_data.return_value = [
{
"resource": {"name": "stack"},
"project": {"pi": "PI1"},
"attributes": {},
}, # missing Allocated Project ID
]
test_invoice = self._get_test_invoice(["P1"], cluster_name=["stack"])
proc = test_utils.new_coldfront_fetch_processor(data=test_invoice)
result = proc._get_allocation_data(mock_get_allocation_data.return_value)
assert result == {} # malformed entry was skipped
Loading