-
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.
update institutional dash board code
- Loading branch information
John Tordoff
committed
Aug 22, 2024
1 parent
b882e37
commit 90bdefe
Showing
3 changed files
with
128 additions
and
57 deletions.
There are no files selected for viewing
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
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
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 |
---|---|---|
|
@@ -9,6 +9,7 @@ | |
PreprintFactory | ||
) | ||
from django.shortcuts import reverse | ||
from osf.models import BaseFileNode | ||
|
||
|
||
@pytest.mark.django_db | ||
|
@@ -37,6 +38,12 @@ def institution(self): | |
|
||
@pytest.fixture() | ||
def users(self, institution): | ||
""" | ||
User_one has two public projects and one registrations. User_two has 1 public registrations. User_three has | ||
1 Public Registristion and 2 Preprints. So 2 public Projects, 3 registrations and 2 Preprints. | ||
""" | ||
from osf_tests.test_elastic_search import create_file_version | ||
|
||
user_one = AuthUserFactory( | ||
fullname='Alice Example', | ||
username='[email protected]' | ||
|
@@ -60,29 +67,46 @@ def users(self, institution): | |
creator=user_one, | ||
is_public=True | ||
) | ||
project2 = ProjectFactory( | ||
file_ = project.get_addon('osfstorage').get_root().append_file('New Test file.mp3') | ||
create_file_version(file_, user_one) | ||
file_.save() | ||
|
||
ProjectFactory( | ||
creator=user_one, | ||
is_public=True | ||
) | ||
registration = RegistrationFactory( | ||
creator=user_one, | ||
) | ||
registration = RegistrationFactory( | ||
file_ = registration.get_addon('osfstorage').get_root().append_file('New Test file 2.5.mp3') | ||
create_file_version(file_, user_one) | ||
file_.save() | ||
|
||
RegistrationFactory( | ||
creator=user_two, | ||
) | ||
registration = RegistrationFactory( | ||
|
||
RegistrationFactory( | ||
creator=user_three, | ||
) | ||
PreprintFactory( | ||
creator=user_three, | ||
) | ||
preprint = PreprintFactory( | ||
PreprintFactory( | ||
creator=user_three, | ||
) | ||
preprint = PreprintFactory( | ||
project = ProjectFactory( | ||
creator=user_three, | ||
is_public=True | ||
) | ||
file_ = project.get_addon('osfstorage').get_root().append_file('New Test file 2.mp3') | ||
create_file_version(file_, user_three) | ||
file_.save() | ||
|
||
return [user_one, user_two, user_three] | ||
|
||
def test_return_all_users(self, app, institution, users): | ||
|
||
url = reverse( | ||
'institutions:institution-users-list-dashboard', | ||
kwargs={ | ||
|
@@ -141,36 +165,3 @@ def test_sort_users(self, app, institution, users, attribute): | |
# Extracting sorted attribute values from response | ||
sorted_values = [user['attributes'][attribute] for user in res.json['data']] | ||
assert sorted_values == sorted(sorted_values), 'Values are not sorted correctly' | ||
|
||
|
||
@pytest.mark.django_db | ||
class TestInstitutionUsersListCSVRenderer: | ||
|
||
def test_csv_output(self, app, institution, users): | ||
""" | ||
Test to ensure the CSV renderer returns data in the expected CSV format with correct headers. | ||
""" | ||
url = reverse( | ||
'institutions:institution-users-list-dashboard', | ||
kwargs={ | ||
'version': 'v2', | ||
'institution_id': institution._id | ||
} | ||
) + '?format=csv' | ||
response = app.get(url) | ||
assert response.status_code == 200 | ||
assert response['Content-Type'] == 'text/csv' | ||
|
||
# Read the content of the response as CSV | ||
content = response.content.decode('utf-8') | ||
csv_reader = csv.reader(io.StringIO(content)) | ||
headers = next(csv_reader) # First line contains headers | ||
|
||
# Define expected headers based on the serializer used | ||
expected_headers = ['ID', 'Email', 'Department', 'Public Projects', 'Private Projects', 'Public Registrations', | ||
'Private Registrations', 'Preprints'] | ||
assert headers == expected_headers, "CSV headers do not match expected headers" | ||
|
||
# Optionally, check a few lines of actual data if necessary | ||
for row in csv_reader: | ||
assert len(row) == len(expected_headers), "Number of data fields in CSV does not match headers" |