-
Notifications
You must be signed in to change notification settings - Fork 330
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
60 additions
and
0 deletions.
There are no files selected for viewing
60 changes: 60 additions & 0 deletions
60
osf_tests/metrics/reporters/test_institutional_users_reporter.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |