diff --git a/api_tests/institutions/views/test_institution_dashboard_files.py b/api_tests/institutions/views/test_institution_dashboard_files.py new file mode 100644 index 00000000000..56a5b350179 --- /dev/null +++ b/api_tests/institutions/views/test_institution_dashboard_files.py @@ -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 diff --git a/api_tests/institutions/views/test_institution_dashboard_preprint.py b/api_tests/institutions/views/test_institution_dashboard_preprint.py new file mode 100644 index 00000000000..872cf7c102d --- /dev/null +++ b/api_tests/institutions/views/test_institution_dashboard_preprint.py @@ -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 diff --git a/api_tests/institutions/views/test_institution_dashboard_project.py b/api_tests/institutions/views/test_institution_dashboard_project.py new file mode 100644 index 00000000000..67da603dad1 --- /dev/null +++ b/api_tests/institutions/views/test_institution_dashboard_project.py @@ -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 diff --git a/api_tests/institutions/views/test_institution_dashboard_registration.py b/api_tests/institutions/views/test_institution_dashboard_registration.py new file mode 100644 index 00000000000..ba0db19f4b1 --- /dev/null +++ b/api_tests/institutions/views/test_institution_dashboard_registration.py @@ -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 + diff --git a/api_tests/institutions/views/test_institution_dashboard_user.py b/api_tests/institutions/views/test_institution_dashboard_user.py index c6ea4fc01e5..8ff90e64566 100644 --- a/api_tests/institutions/views/test_institution_dashboard_user.py +++ b/api_tests/institutions/views/test_institution_dashboard_user.py @@ -1,3 +1,4 @@ +import csv import pytest from osf_tests.factories import ( @@ -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"