-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for exporting all org users to CSV (#3667)
* Pull repeated CSV export logic into export_queryset * Consolidate existing export code using export_queryset * Add endpoint for exporting all org users * Add download icon in org user management template * Add test for new endpoint * Add date_joined, last_login to single org users export * Simplify org users query * Add new view to test_permissions URL list * Update permissions in view access decorator
- Loading branch information
Showing
6 changed files
with
160 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 |
---|---|---|
|
@@ -351,6 +351,54 @@ def test_org_export_user_list(self): | |
reader_record_count += 1 | ||
self.assertEqual(reader_record_count, record_count) | ||
|
||
def test_organization_user_export_user_list(self): | ||
expected_results = [ | ||
('[email protected]', 'Some Case'), | ||
('[email protected]', 'Another Journal'), | ||
('[email protected]', "Another Library's Journal"), | ||
('[email protected]', 'A Third Journal'), | ||
('[email protected]', 'Test Journal'), | ||
('[email protected]', "Another Library's Journal"), | ||
('[email protected]', 'A Third Journal'), | ||
('[email protected]', "Another Library's Journal"), | ||
('[email protected]', 'A Third Journal'), | ||
('[email protected]', 'Test Journal'), | ||
('[email protected]', 'Test Journal'), | ||
] | ||
|
||
# Get CSV export output | ||
csv_response: HttpResponse = self.get( | ||
'user_management_manage_organization_user_export_user_list', | ||
request_kwargs={'data': {'format': 'csv'}}, | ||
user=self.admin_user, | ||
) | ||
self.assertEqual(csv_response.headers['Content-Type'], 'text/csv') | ||
|
||
# Validate CSV output against expected results | ||
csv_file = StringIO(csv_response.content.decode('utf8')) | ||
reader = csv.DictReader(csv_file) | ||
for index, record in enumerate(reader): | ||
expected_email, expected_organization_name = expected_results[index] | ||
self.assertEqual(record['email'], expected_email) | ||
self.assertEqual(record['organization_name'], expected_organization_name) | ||
self.assertEqual(index + 1, len(expected_results)) | ||
|
||
# Get JSON export output | ||
json_response: HttpResponse = self.get( | ||
'user_management_manage_organization_user_export_user_list', | ||
request_kwargs={'data': {'format': 'json'}}, | ||
user=self.admin_user, | ||
) | ||
self.assertEqual(json_response.headers['Content-Type'], 'application/json') | ||
|
||
# Validate JSON output against expected results | ||
reader = json.loads(json_response.content) | ||
for index, record in enumerate(reader): | ||
expected_email, expected_organization_name = expected_results[index] | ||
self.assertEqual(record['email'], expected_email) | ||
self.assertEqual(record['organization_name'], expected_organization_name) | ||
self.assertEqual(index + 1, len(expected_results)) | ||
|
||
def test_sponsored_user_export_user_list(self): | ||
expected_results = [ | ||
('[email protected]', 'inactive'), | ||
|
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