summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--yaksh/test_views.py27
-rw-r--r--yaksh/views.py4
2 files changed, 28 insertions, 3 deletions
diff --git a/yaksh/test_views.py b/yaksh/test_views.py
index 9f46ba9..2dddcef 100644
--- a/yaksh/test_views.py
+++ b/yaksh/test_views.py
@@ -1815,6 +1815,33 @@ class TestCourseDetail(TestCase):
self.assertIn('upload_details', response.context)
self.assertTemplateUsed(response, 'yaksh/course_detail.html')
+ def test_upload_users_add_update_reject(self):
+ # Given
+ self.client.login(
+ username=self.user1.username,
+ password=self.user1_plaintext_pass
+ )
+ csv_file_path = os.path.join(FIXTURES_DIR_PATH,
+ "users_add_update_reject.csv")
+ csv_file = open(csv_file_path, 'rb')
+ upload_file = SimpleUploadedFile(csv_file_path, csv_file.read())
+
+ # When
+ response = self.client.post(reverse('yaksh:upload_users',
+ kwargs={'course_id': self.user1_course.id}),
+ data={'csv_file': upload_file})
+ csv_file.close()
+
+ # Then
+ uploaded_user = User.objects.filter(username="test")
+ user = uploaded_user[0]
+ self.assertEqual(uploaded_user.count(), 1)
+ self.assertEqual(user.first_name, "test2")
+ self.assertIn(user, self.user1_course.get_rejected())
+ self.assertEqual(response.status_code, 200)
+ self.assertIn('upload_details', response.context)
+ self.assertTemplateUsed(response, 'yaksh/course_detail.html')
+
def test_upload_users_with_wrong_csv(self):
# Given
self.client.login(
diff --git a/yaksh/views.py b/yaksh/views.py
index e7c2037..d49fad1 100644
--- a/yaksh/views.py
+++ b/yaksh/views.py
@@ -1887,7 +1887,6 @@ def _read_user_csv(reader, course):
fields = reader.fieldnames
upload_details = ["Upload Summary:"]
counter = 0
- add_users = []
for row in reader:
counter += 1
(username, email, first_name, last_name, password, roll_no, institute,
@@ -1919,12 +1918,11 @@ def _read_user_csv(reader, course):
_create_or_update_profile(user, profile_defaults)
if created:
state = "Added"
- add_users.append(user)
+ course.students.add(user)
else:
state = "Updated"
upload_details.append("{0} -- {1} -- User {2} Successfully".format(
counter, user.username, state))
- course.students.add(*add_users)
if counter == 0:
upload_details.append("No rows in the CSV file")
return upload_details