diff options
author | prathamesh | 2017-11-13 17:19:11 +0530 |
---|---|---|
committer | prathamesh | 2017-11-13 17:19:11 +0530 |
commit | a3a94ded76f02820b3a1536055dad0dc2dac81c5 (patch) | |
tree | c474bc7d251b0e43eb2e48f5af1906ebcf053909 | |
parent | 847c24c0fe3c9d9f31ae4e5c3c0a68b783873592 (diff) | |
download | online_test-a3a94ded76f02820b3a1536055dad0dc2dac81c5.tar.gz online_test-a3a94ded76f02820b3a1536055dad0dc2dac81c5.tar.bz2 online_test-a3a94ded76f02820b3a1536055dad0dc2dac81c5.zip |
Added test case for add, update and remove
-rw-r--r-- | yaksh/test_views.py | 27 | ||||
-rw-r--r-- | yaksh/views.py | 4 |
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 |