예제 #1
0
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}."
        )
예제 #2
0
    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
예제 #3
0
    def test_remove_allowlist_entry(self):
        """
        Test for removing an allowlist entry for a user in a given course-run.
        """
        CertificateAllowlistFactory.create(course_id=self.course_run_key, user=self.user)
        assert is_on_allowlist(self.user, self.course_run_key)

        result = remove_allowlist_entry(self.user, self.course_run_key)
        assert result
        assert not is_on_allowlist(self.user, self.course_run_key)
예제 #4
0
    def test_remove_allowlist_entry(self):
        """
        Test for removing an allowlist entry for a user in a given course-run.
        """
        CertificateWhitelistFactory.create(course_id=self.course_run_key, user=self.user)

        result = remove_allowlist_entry(self.user, self.course_run_key)
        assert result

        with pytest.raises(ObjectDoesNotExist) as error:
            CertificateWhitelist.objects.get(user=self.user, course_id=self.course_run_key)
        assert str(error.value) == "CertificateWhitelist matching query does not exist."
예제 #5
0
    def test_remove_allowlist_entry_with_certificate(self):
        """
        Test for removing an allowlist entry. Verify that we also invalidate the certificate for the student.
        """
        CertificateAllowlistFactory.create(course_id=self.course_run_key, user=self.user)
        GeneratedCertificateFactory.create(
            user=self.user,
            course_id=self.course_run_key,
            status=CertificateStatuses.downloadable,
            mode='verified'
        )
        assert is_on_allowlist(self.user, self.course_run_key)

        result = remove_allowlist_entry(self.user, self.course_run_key)
        assert result

        certificate = GeneratedCertificate.objects.get(user=self.user, course_id=self.course_run_key)
        assert certificate.status == CertificateStatuses.unavailable
        assert not is_on_allowlist(self.user, self.course_run_key)
예제 #6
0
    def test_remove_allowlist_entry_with_certificate(self):
        """
        Test for removing an allowlist entry. Verify that we also invalidate the certificate for the student.
        """
        CertificateWhitelistFactory.create(course_id=self.course_run_key, user=self.user)
        GeneratedCertificateFactory.create(
            user=self.user,
            course_id=self.course_run_key,
            status=CertificateStatuses.downloadable,
            mode='verified'
        )

        result = remove_allowlist_entry(self.user, self.course_run_key)
        assert result

        certificate = GeneratedCertificate.objects.get(user=self.user, course_id=self.course_run_key)
        assert certificate.status == CertificateStatuses.unavailable

        with pytest.raises(ObjectDoesNotExist) as error:
            CertificateWhitelist.objects.get(user=self.user, course_id=self.course_run_key)
        assert str(error.value) == "CertificateWhitelist matching query does not exist."
예제 #7
0
 def test_remove_allowlist_entry_entry_dne(self):
     """
     Test for removing an allowlist entry that does not exist
     """
     result = remove_allowlist_entry(self.user, self.course_run_key)
     assert not result