Add Reports domain method to get portfolio spend
This commit is contained in:
parent
baa3f390d2
commit
63cb05249f
@ -1,5 +1,11 @@
|
||||
from flask import current_app
|
||||
from itertools import groupby
|
||||
from atst.domain.csp.cloud.models import (
|
||||
ReportingCSPPayload,
|
||||
CostManagementQueryCSPResult,
|
||||
)
|
||||
from atst.domain.csp.reports import prepare_azure_reporting_data
|
||||
import pendulum
|
||||
|
||||
|
||||
class Reports:
|
||||
@ -42,3 +48,21 @@ class Reports:
|
||||
}
|
||||
)
|
||||
return output
|
||||
|
||||
@classmethod
|
||||
def get_portfolio_spending(cls, portfolio):
|
||||
# TODO: Extend this function to make from_date and to_date configurable
|
||||
from_date = pendulum.now().subtract(years=1).add(days=1).format("YYYY-MM-DD")
|
||||
to_date = pendulum.now().format("YYYY-MM-DD")
|
||||
rows = []
|
||||
|
||||
if portfolio.csp_data:
|
||||
payload = ReportingCSPPayload(
|
||||
from_date=from_date, to_date=to_date, **portfolio.csp_data
|
||||
)
|
||||
response: CostManagementQueryCSPResult = current_app.csp.cloud.get_reporting_data(
|
||||
payload
|
||||
)
|
||||
rows = response.properties.rows
|
||||
|
||||
return prepare_azure_reporting_data(rows)
|
||||
|
@ -1,8 +1,31 @@
|
||||
# TODO: Implement when we get real reporting data
|
||||
def test_expired_task_orders():
|
||||
pass
|
||||
import pytest
|
||||
|
||||
from atst.domain.reports import Reports
|
||||
from tests.factories import PortfolioFactory
|
||||
from decimal import Decimal
|
||||
|
||||
|
||||
# TODO: Implement when we get real reporting data
|
||||
def test_obligated_funds_by_JEDI_clin():
|
||||
pass
|
||||
@pytest.fixture(scope="function")
|
||||
def portfolio():
|
||||
portfolio = PortfolioFactory.create()
|
||||
return portfolio
|
||||
|
||||
|
||||
class TestGetPortfolioSpending:
|
||||
csp_data = {
|
||||
"tenant_id": "",
|
||||
"billing_profile_properties": {
|
||||
"invoice_sections": [{"invoice_section_id": "",}]
|
||||
},
|
||||
}
|
||||
|
||||
def test_with_csp_data(self, portfolio):
|
||||
portfolio.csp_data = self.csp_data
|
||||
data = Reports.get_portfolio_spending(portfolio)
|
||||
assert data["invoiced"] == Decimal(1551.0)
|
||||
assert data["estimated"] == Decimal(500.0)
|
||||
|
||||
def test_without_csp_data(self, portfolio):
|
||||
data = Reports.get_portfolio_spending(portfolio)
|
||||
assert data["invoiced"] == Decimal(0)
|
||||
assert data["estimated"] == Decimal(0)
|
||||
|
Loading…
x
Reference in New Issue
Block a user