Skip to content

Commit

Permalink
Merge branch 'institutional-dashboard' of https://github.com/CenterFo…
Browse files Browse the repository at this point in the history
…rOpenScience/osf.io into institutional-dashboard

* 'institutional-dashboard' of https://github.com/CenterForOpenScience/osf.io:

# Conflicts:
#	api/institutions/views.py
#	api_tests/institutions/views/test_institution_dashboard_user.py
  • Loading branch information
John Tordoff committed Aug 22, 2024
2 parents 1b98d5d + 05f0e6e commit 5a406ec
Show file tree
Hide file tree
Showing 5 changed files with 173 additions and 0 deletions.
34 changes: 34 additions & 0 deletions api_tests/institutions/views/test_institution_dashboard_files.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import pytest

from api.base.settings.defaults import API_BASE
from osf_tests.factories import (
InstitutionFactory,
AuthUserFactory,
ProjectFactory,
RegistrationFactory,
PreprintFactory
)
from django.shortcuts import reverse


@pytest.mark.django_db
class TestInstitutionFilesList:

def test_return(self, app):

things_to_filter_and_sort = [
'_id',
'file_name',
'file_path',
'date_modified',
'date_created',
'mime_type',
'size',
'resource_type',
'doi',
'addon_used',
]

res = app.get(f'/{API_BASE}institutions/{institution._id}/users/')

assert res.status_code == 200
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import pytest

from api.base.settings.defaults import API_BASE
from osf_tests.factories import (
InstitutionFactory,
AuthUserFactory,
ProjectFactory,
RegistrationFactory,
PreprintFactory
)
from django.shortcuts import reverse


@pytest.mark.django_db
class TestInstitutionPreprintList:

def test_return(self, app):

things_to_filter_and_sort = [
'_id',
'title',
'type',
'date_modified',
'date_created',
'storage_location',
'storage_usage',
'is_public',
'doi',
'addon_used',
]

res = app.get(f'/{API_BASE}institutions/{institution._id}/users/')

assert res.status_code == 200
34 changes: 34 additions & 0 deletions api_tests/institutions/views/test_institution_dashboard_project.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import pytest

from api.base.settings.defaults import API_BASE
from osf_tests.factories import (
InstitutionFactory,
AuthUserFactory,
ProjectFactory,
RegistrationFactory,
PreprintFactory
)
from django.shortcuts import reverse


@pytest.mark.django_db
class TestInstitutionProjectList:

def test_return(self, app):

things_to_filter_and_sort = [
'_id',
'title',
'type',
'date_modified',
'date_created',
'storage_location',
'storage_usage',
'is_public',
'doi',
'addon_used',
]

res = app.get(f'/{API_BASE}institutions/{institution._id}/users/')

assert res.status_code == 200
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import pytest

from api.base.settings.defaults import API_BASE
from osf_tests.factories import (
InstitutionFactory,
AuthUserFactory,
ProjectFactory,
RegistrationFactory,
PreprintFactory
)
from django.shortcuts import reverse



@pytest.mark.django_db
class TestInstitutionRegistrationList:

def test_return(self, app):

things_to_filter_and_sort = [
'_id',
'title',
'type',
'date_modified',
'date_created',
'storage_location',
'storage_usage',
'is_public',
'doi',
'addon_used',
]

res = app.get(f'/{API_BASE}institutions/{institution._id}/users/')

assert res.status_code == 200

35 changes: 35 additions & 0 deletions api_tests/institutions/views/test_institution_dashboard_user.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import csv
import pytest

from osf_tests.factories import (
Expand Down Expand Up @@ -163,3 +164,37 @@ 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:
# Existing setup and tests...

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"

0 comments on commit 5a406ec

Please sign in to comment.