From 28c5587a1595394ed097964661943c6ac588a89f Mon Sep 17 00:00:00 2001 From: abram axel booth Date: Thu, 5 Dec 2024 10:11:10 -0500 Subject: [PATCH] add report_yearmonth to insti-metrics serializers --- api/institutions/serializers.py | 2 ++ .../institutions/views/test_institution_summary_metrics.py | 2 ++ .../institutions/views/test_institution_user_metric_list.py | 5 +++++ 3 files changed, 9 insertions(+) diff --git a/api/institutions/serializers.py b/api/institutions/serializers.py index e3679b2a9c5..1d1e0761715 100644 --- a/api/institutions/serializers.py +++ b/api/institutions/serializers.py @@ -330,6 +330,7 @@ class Meta: }) id = IDField(source='meta.id', read_only=True) + report_yearmonth = YearmonthField(read_only=True) user_name = ser.CharField(read_only=True) department = ser.CharField(read_only=True, source='department_name') orcid_id = ser.CharField(read_only=True) @@ -372,6 +373,7 @@ class Meta: id = IDField(read_only=True) + report_yearmonth = YearmonthField(read_only=True) user_count = ser.IntegerField(read_only=True) public_project_count = ser.IntegerField(read_only=True) private_project_count = ser.IntegerField(read_only=True) diff --git a/api_tests/institutions/views/test_institution_summary_metrics.py b/api_tests/institutions/views/test_institution_summary_metrics.py index d423663ea89..f1641ea923c 100644 --- a/api_tests/institutions/views/test_institution_summary_metrics.py +++ b/api_tests/institutions/views/test_institution_summary_metrics.py @@ -188,6 +188,7 @@ def test_get_report(self, app, url, institutional_admin, institution, reports, u assert data['type'] == 'institution-summary-metrics' attributes = data['attributes'] + assert attributes['report_yearmonth'] == '2024-08' assert attributes['user_count'] == 200 assert attributes['public_project_count'] == 150 assert attributes['private_project_count'] == 125 @@ -254,6 +255,7 @@ def test_get_report_with_multiple_months_and_institutions( attributes = data['attributes'] + assert attributes['report_yearmonth'] == '2024-09' assert attributes['user_count'] == 250 assert attributes['public_project_count'] == 200 assert attributes['private_project_count'] == 150 diff --git a/api_tests/institutions/views/test_institution_user_metric_list.py b/api_tests/institutions/views/test_institution_user_metric_list.py index f83fd7fc3fa..b1bf3490788 100644 --- a/api_tests/institutions/views/test_institution_user_metric_list.py +++ b/api_tests/institutions/views/test_institution_user_metric_list.py @@ -445,6 +445,7 @@ def test_get_report_formats_csv_tsv(self, app, url, institutional_admin, institu response_body = resp.text expected_response = [ [ + 'report_yearmonth', 'account_creation_date', 'department', 'embargoed_registration_count', @@ -460,6 +461,7 @@ def test_get_report_formats_csv_tsv(self, app, url, institutional_admin, institu 'user_name' ], [ + '2024-08', '2018-02', 'Center, \t Greatest Ever', '1', @@ -512,6 +514,7 @@ def test_csv_tsv_ignores_pagination(self, app, url, institutional_admin, institu month_last_login='2018-02', ) expected_data.append([ + '2024-08', '2018-02', 'QBatman', '1', @@ -552,6 +555,7 @@ def test_csv_tsv_ignores_pagination(self, app, url, institutional_admin, institu response_rows = list(reader) # Validate header row expected_header = [ + 'report_yearmonth', 'account_creation_date', 'department', 'embargoed_registration_count', @@ -606,6 +610,7 @@ def test_get_report_format_table_json(self, app, url, institutional_admin, insti response_data = json.loads(resp.body) expected_data = [ { + 'report_yearmonth': '2024-08', 'account_creation_date': '2018-02', 'department': 'Safety "The Wolverine" Weapon X', 'embargoed_registration_count': 1,