def test_user_has_removed_one_of_the_self_chosen_courses(self): dp_user = DataportenUserFactory() sync_dataporten_courses_with_db(dp_user.dataporten.courses.all) sync_options_of_user_with_dataporten(dp_user) course = dp_user.options.self_chosen_courses.all()[0] # The user removes one of the scc's dp_user.options.self_chosen_courses.remove(course) dp_user.options.save() dp_user.refresh_from_db() count_before = dp_user.options.self_chosen_courses.count() sync_options_of_user_with_dataporten(dp_user) # The sync process should not remove something the user has removed # by purpose. assert dp_user.options.self_chosen_courses.count() == count_before assert count_before == len(dp_user.dataporten.courses.active) - 1
def test_remove_course_which_has_already_been_hidden(self): request = MagicMock() request.user.options.get_absolute_url.return_value = '/username/' user = DataportenUserFactory() request.user = user courses = CourseFactory.create_batch(2) request.user.options.self_chosen_courses = courses response = remove_course(request, '1000') assert list(request.user.options.self_chosen_courses.all()) == courses assert response.url == '/username/'
def test_new_user(self, dataporten): dp_user = DataportenUserFactory() sync_dataporten_courses_with_db(dp_user.dataporten.courses.all) # The user has no self chosen courses (scc) before the sync process assert dp_user.options.self_chosen_courses.count() == 0 sync_options_of_user_with_dataporten(dp_user) # After the sync, all the active courses have been added to the scc assert len(dp_user.dataporten.courses.active ) == dp_user.options.self_chosen_courses.count()
def test_course_is_removed(self): request = MagicMock() request.user.options.get_absolute_url.return_value = '/username/' user = DataportenUserFactory() request.user = user courses = CourseFactory.create_batch(2) request.user.options.self_chosen_courses = courses response = remove_course(request, courses[0].id) assert list(request.user.options.self_chosen_courses.all()) \ == courses[1:] assert response.url == '/username/'
def dataporten_user(): return DataportenUserFactory()