def update_allowlist(user, course, enable): """ Update the status of a user on the allowlist. """ if enable and can_be_added_to_allowlist(user, course): create_or_update_certificate_allowlist_entry(user, course, "Updated by mngmt cmd", enable) elif not enable: remove_allowlist_entry(user, course) else: print( f"Failed to process allowlist request for student {user.id} in course {course} and enable={enable}." )
def test_create_certificate_allowlist_entry(self): """ Test for creating and updating allowlist entries. """ result, __ = create_or_update_certificate_allowlist_entry(self.user, self.course_run_key, "Testing!") assert result.course_id == self.course_run_key assert result.user == self.user assert result.notes == "Testing!" result, __ = create_or_update_certificate_allowlist_entry(self.user, self.course_run_key, "New test", False) assert result.notes == "New test" assert not result.allowlist
def test_remove(self): """ Test removal from the allowlist """ u1 = UserFactory() notes = 'I had a thought....' # Add user create_or_update_certificate_allowlist_entry(u1, self.course_run_key, notes) entry = get_allowlist_entry(u1, self.course_run_key) assert entry.notes == notes # Remove user remove_allowlist_entry(u1, self.course_run_key) entry = get_allowlist_entry(u1, self.course_run_key) assert entry is None
def test_add_and_update(self): """ Test add and update of the allowlist """ u1 = UserFactory() notes = 'blah' # Check before adding user entry = get_allowlist_entry(u1, self.course_run_key) assert entry is None # Add user create_or_update_certificate_allowlist_entry(u1, self.course_run_key, notes) entry = get_allowlist_entry(u1, self.course_run_key) assert entry.notes == notes # Update user new_notes = 'really useful info' create_or_update_certificate_allowlist_entry(u1, self.course_run_key, new_notes) entry = get_allowlist_entry(u1, self.course_run_key) assert entry.notes == new_notes