Skip to content
Merged
Show file tree
Hide file tree
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
35 changes: 35 additions & 0 deletions coldfront/core/portal/tests/test_views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# SPDX-FileCopyrightText: (C) ColdFront Authors
#
# SPDX-License-Identifier: AGPL-3.0-or-later

import logging

from django.test import TestCase

logging.disable(logging.CRITICAL)


class PortalViewBaseTest(TestCase):
"""Base class for portal view tests."""

@classmethod
def setUpTestData(cls):
"""Test Data setup for all portal view tests."""
pass


class CenterSummaryViewTest(PortalViewBaseTest):
"""Tests for center summary view"""

@classmethod
def setUpTestData(cls):
"""Set up users and project for testing"""
cls.url = "/center-summary"
super(PortalViewBaseTest, cls).setUpTestData()

def test_centersummary_renders(self):
response = self.client.get(self.url)
self.assertEqual(response.status_code, 200)
self.assertContains(response, "Active Allocations and Users")
self.assertContains(response, "Resources and Allocations Summary")
self.assertNotContains(response, "We're having a bit of system trouble at the moment. Please check back soon!")
7 changes: 5 additions & 2 deletions coldfront/core/portal/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@

from django.conf import settings
from django.contrib.humanize.templatetags.humanize import intcomma
from django.db.models import Count, Q, Sum
from django.db.models import Count, FloatField, Q, Sum
from django.db.models.functions import Cast
from django.shortcuts import render
from django.views.decorators.cache import cache_page

Expand Down Expand Up @@ -137,7 +138,9 @@ def center_summary(request):

# Grants Card
total_grants_by_agency_sum = list(
Grant.objects.values("funding_agency__name").annotate(total_amount=Sum("total_amount_awarded"))
Grant.objects.values("funding_agency__name").annotate(
total_amount=Sum(Cast("total_amount_awarded", FloatField()))
)
)

total_grants_by_agency_count = list(
Expand Down