Example #1
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
Example #2
0
    def test_get_allowlist_entry(self):
        """
        Test to verify that we can retrieve an allowlist entry for a learner.
        """
        allowlist_entry = CertificateAllowlistFactory.create(course_id=self.course_run_key, user=self.user)

        retrieved_entry = get_allowlist_entry(self.user, self.course_run_key)

        assert retrieved_entry.id == allowlist_entry.id
        assert retrieved_entry.course_id == allowlist_entry.course_id
        assert retrieved_entry.user == allowlist_entry.user
Example #3
0
    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
Example #4
0
    def test_get_allowlist_entry_dne(self):
        """
        Test to verify behavior when an allowlist entry for a user does not exist
        """
        expected_messages = [
            f"Attempting to retrieve an allowlist entry for student {self.user.id} in course {self.course_run_key}.",
            f"No allowlist entry found for student {self.user.id} in course {self.course_run_key}."
        ]

        with LogCapture() as log:
            retrieved_entry = get_allowlist_entry(self.user, self.course_run_key)

        assert retrieved_entry is None

        for index, message in enumerate(expected_messages):
            assert message in log.records[index].getMessage()