summaryrefslogtreecommitdiff
path: root/yaksh/test_views.py
diff options
context:
space:
mode:
authorKing2020-08-27 19:52:45 +0530
committerGitHub2020-08-27 19:52:45 +0530
commit28ae003e080dcc81f1547cc7bb581293edef9da8 (patch)
tree913132dbd874c17a8739936383c0ce1202f64d51 /yaksh/test_views.py
parentf4bf8fd68fa8b9aea29a0a688409f44288494cda (diff)
parent570b141055f9baa27c539842b14756838949ba60 (diff)
downloadonline_test-28ae003e080dcc81f1547cc7bb581293edef9da8.tar.gz
online_test-28ae003e080dcc81f1547cc7bb581293edef9da8.tar.bz2
online_test-28ae003e080dcc81f1547cc7bb581293edef9da8.zip
Merge pull request #744 from prathamesh920/fix-upload-users
Avoid duplicate user entry with same email address during upload.
Diffstat (limited to 'yaksh/test_views.py')
-rw-r--r--yaksh/test_views.py27
1 files changed, 27 insertions, 0 deletions
diff --git a/yaksh/test_views.py b/yaksh/test_views.py
index a7ccac2..5876f03 100644
--- a/yaksh/test_views.py
+++ b/yaksh/test_views.py
@@ -2755,6 +2755,33 @@ class TestCourseDetail(TestCase):
id=uploaded_users.first().id).exists()
)
+ def test_upload_existing_user_email(self):
+ # Given
+ self.client.login(
+ username=self.user1.username, password=self.user1_plaintext_pass)
+ csv_file_path = os.path.join(FIXTURES_DIR_PATH,
+ 'user_existing_email.csv')
+ csv_file = open(csv_file_path, 'rb')
+ upload_file = SimpleUploadedFile(csv_file_path, csv_file.read())
+ csv_file.close()
+
+ # When
+ response = self.client.post(
+ reverse('yaksh:upload_users',
+ kwargs={'course_id': self.user1_course.id}),
+ data={'csv_file': upload_file})
+
+ # Then
+ uploaded_users = User.objects.filter(email='demo_student@test.com')
+ self.assertEqual(response.status_code, 302)
+ messages = [m.message for m in get_messages(response.wsgi_request)]
+ self.assertIn('demo_student', messages[0])
+ self.assertTrue(
+ self.user1_course.students.filter(
+ id=uploaded_users.first().id).exists()
+ )
+ self.assertEqual(uploaded_users.count(), 1)
+
def test_upload_users_add_update_reject(self):
# Given
self.client.login(