diff --git a/osf/metrics/reporters/institutional_users.py b/osf/metrics/reporters/institutional_users.py index 9e585a61ce5..0a0598172e0 100644 --- a/osf/metrics/reporters/institutional_users.py +++ b/osf/metrics/reporters/institutional_users.py @@ -16,9 +16,15 @@ class InstitutionalUsersReporter(MonthlyReporter): + '''build an InstitutionalUserReport for each institution-user affiliation + + built for the institution dashboard at ://osf.example/institutions//dashboard/, + which offers institutional admins insight into how people at their institution are + using osf, based on their explicitly-affiliated osf objects + ''' def report(self, yearmonth: YearMonth): _before_datetime = yearmonth.next_month() - for _institution in osfdb.Institution.objects.all(): + for _institution in osfdb.Institution.objects.filter(created__lt=_before_datetime): _user_qs = _institution.get_institution_users().filter(created__lt=_before_datetime) for _user in _user_qs.iterator(chunk_size=_CHUNK_SIZE): _helper = _InstiUserReportHelper(_institution, _user, yearmonth, _before_datetime) diff --git a/osf_tests/metrics/reporters/test_institutional_users_reporter.py b/osf_tests/metrics/reporters/test_institutional_users_reporter.py index 4f5a1799228..6af191cc669 100644 --- a/osf_tests/metrics/reporters/test_institutional_users_reporter.py +++ b/osf_tests/metrics/reporters/test_institutional_users_reporter.py @@ -59,14 +59,11 @@ def _assert_report_matches_setup(self, report: InstitutionalUserReport, setup: _ self.assertEqual(report.month_last_login, YearMonth.from_date(setup.user.date_last_login)) self.assertEqual(report.account_creation_date, YearMonth.from_date(setup.user.created)) self.assertEqual(report.orcid_id, setup.orcid_id) - # counts: + # counts (NOTE: report.public_file_count and report.storage_byte_count tested separately) self.assertEqual(report.public_project_count, setup.public_project_count) self.assertEqual(report.private_project_count, setup.private_project_count) self.assertEqual(report.public_registration_count, setup.public_registration_count) self.assertEqual(report.embargoed_registration_count, setup.embargoed_registration_count) - # NOTE: currently untested due to the annoyance involved: - # self.assertEqual(report.public_file_count, ...) - # self.assertEqual(report.storage_byte_count, ...) if _can_affiliate_preprints(): self.assertEqual(report.published_preprint_count, setup.published_preprint_count) else: @@ -142,10 +139,13 @@ def test_several_users(self): _setup = _setup_by_userid[_actual_report.user_id] self._assert_report_matches_setup(_actual_report, _setup) -# helper class for test-case setup + @dataclasses.dataclass class _InstiUserSetup: - '''oof, so many things to set up, gross''' + '''helper class to simplify database setup for a test-case + + (note: public_file_count and storage_byte_count set up separately) + ''' public_project_count: int private_project_count: int public_registration_count: int