-
Notifications
You must be signed in to change notification settings - Fork 58
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
1 parent
5cf7d87
commit 8ef7f6e
Showing
3 changed files
with
110 additions
and
60 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 |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import csv | ||
import io | ||
|
||
from django.urls import reverse | ||
from oppia.test import OppiaTestCase | ||
|
||
|
||
class ExportUsersViewsTest(OppiaTestCase): | ||
|
||
fixtures = ['tests/test_user.json', | ||
'tests/test_oppia.json', | ||
'tests/test_permissions.json', | ||
'tests/test_course_permissions.json', | ||
'tests/test_customfields.json'] | ||
|
||
STR_EXPECTED_CONTENT_TYPE = 'text/csv' | ||
STR_URL = 'profile:users_list' | ||
|
||
def test_permissions(self): | ||
for user in [self.normal_user, | ||
self.teacher_user]: | ||
self.client.force_login(user) | ||
response = self.client.get(reverse(self.STR_URL) + "?export=csv&username=&first_name=&last_name=&email=" + | ||
"&is_active=&is_staff=&start_date=&end_date=&userprofilecustomfield_test=") | ||
self.assertEqual(403, response.status_code) | ||
|
||
def test_download_all_users_all_data(self): | ||
for user in [self.admin_user, | ||
self.staff_user]: | ||
self.client.force_login(user) | ||
response = self.client.get(reverse(self.STR_URL) + "?export=csv&username=&first_name=&last_name=" + | ||
"&email=&is_active=&is_staff=&start_date=&end_date=" + | ||
"&userprofilecustomfield_test=") | ||
self.assertEqual(200, response.status_code) | ||
self.assertEqual(response['content-type'], self.STR_EXPECTED_CONTENT_TYPE) | ||
csv_file = csv.DictReader(io.StringIO(response.content.decode())) | ||
self.assertEqual(6, len(list(csv_file))) | ||
|
||
def test_download_filtered_by_registration_date_all_data(self): | ||
for user in [self.admin_user, | ||
self.staff_user]: | ||
self.client.force_login(user) | ||
response = self.client.get(reverse(self.STR_URL) + "?export=csv&username=&first_name=&last_name=&email=" + | ||
"&is_active=&is_staff=&start_date=2022-01-01&end_date=2022-12-31" + | ||
"&userprofilecustomfield_test=") | ||
self.assertEqual(200, response.status_code) | ||
self.assertEqual(response['content-type'], self.STR_EXPECTED_CONTENT_TYPE) | ||
csv_file = csv.DictReader(io.StringIO(response.content.decode())) | ||
self.assertEqual(0, len(list(csv_file))) | ||
|
||
def test_download_all_users_username_only(self): | ||
for user in [self.admin_user, | ||
self.staff_user]: | ||
self.client.force_login(user) | ||
response = self.client.get(reverse(self.STR_URL) + "?export=csv&username=&first_name=&last_name=&email=" + | ||
"&is_active=&is_staff=&start_date=&end_date=&userprofilecustomfield_test=" + | ||
"&csv_fields%5B%5D=username") | ||
self.assertEqual(200, response.status_code) | ||
self.assertEqual(response['content-type'], self.STR_EXPECTED_CONTENT_TYPE) | ||
csv_file = csv.DictReader(io.StringIO(response.content.decode())) | ||
self.assertEqual(6, len(list(csv_file))) | ||
|
||
def test_download_all_users_invalid_field(self): | ||
for user in [self.admin_user, | ||
self.staff_user]: | ||
self.client.force_login(user) | ||
response = self.client.get(reverse(self.STR_URL) + "?export=csv&username=&first_name=&last_name=&email=" + | ||
"¬afield=&is_staff=&start_date=&end_date=&userprofilecustomfield_test=" + | ||
"&userprofilecustomfield_notafield=&csv_fields%5B%5D=invalidnotafield") | ||
self.assertEqual(200, response.status_code) | ||
self.assertEqual(response['content-type'], self.STR_EXPECTED_CONTENT_TYPE) | ||
csv_file = csv.DictReader(io.StringIO(response.content.decode())) | ||
self.assertEqual(0, len(list(csv_file))) | ||
|