diff --git a/osf_tests/metrics/reporters/test_institutional_users_reporter.py b/osf_tests/metrics/reporters/test_institutional_users_reporter.py new file mode 100644 index 000000000000..151ff8740073 --- /dev/null +++ b/osf_tests/metrics/reporters/test_institutional_users_reporter.py @@ -0,0 +1,60 @@ +from __future__ import annotations +import dataclasses + +import pytest + +from osf import models as osfdb +from osf.metrics.reporters import InstitutionalUsersReporter +from osf_tests.factories import ( + InstitutionFactory, + PreprintFactory, + ProjectFactory, + RegistrationFactory, + UserFactory, +) + + +@pytest.mark.django_db +class TestInstitutionalUsersReporter: + @pytest.fixture() + def institution(self): + return InstitutionFactory() + + @pytest.fixture() + def affiliated_user_cases(self, institution) -> list[_UserCase]: + _cases = [ + _UserCase(1, 1, 1, 1, 1, 1), + _UserCase(2, 2, 2, 2, 2, 2), + _UserCase(3, 3, 3, 3, 3, 3), + ] + for _case in _cases: + _case.user.add_or_update_affiliated_institution(institution) + return _cases + + @pytest.fixture() + def unaffiliated_user(self): + return UserFactory() + + def _fill_user_case(self, usercase: _UserCase): + _included_projects = [] + for _user in affiliated_users: + for _public in (True, False): + _proj = ProjectFactory(creator=_user, is_public=_public) + _proj.affiliated_institutions.add(institution) + _included_projects.append(_proj) + return _included_projects + + def test_reporter(self, affiliated_user_cases, unaffiliated_user): + raise NotImplementedError('TODO') + _actual_reports = list(InstitutionalUsersReporter().report(_yearmonth)) + + +@dataclasses.dataclass +class _UserCase: + public_project_count: int + private_project_count: int + public_registration_count: int + embargoed_registration_count: int + public_file_count: int + published_preprint_count: int + user: osfdb.OSFUser = dataclasses.field(default_factory=UserFactory)