예제 #1
0
    def test_state_transitions(self):
        """
        Make sure we can't make unexpected status transitions.

        The status transitions we expect are::

                        → → → must_retry
                        ↑        ↑ ↓
            created → ready → submitted → approved
                                    ↓        ↑ ↓
                                    ↓ → →  denied
        """
        user = UserFactory.create()
        attempt = SoftwareSecurePhotoVerification(user=user)
        assert attempt.status == PhotoVerification.STATUS.created

        # These should all fail because we're in the wrong starting state.
        pytest.raises(VerificationException, attempt.submit)
        pytest.raises(VerificationException, attempt.approve)
        pytest.raises(VerificationException, attempt.deny)
        pytest.raises(VerificationException, attempt.mark_must_retry)
        pytest.raises(VerificationException, attempt.mark_submit)

        # Now let's fill in some values so that we can pass the mark_ready() call
        attempt.mark_ready()
        assert attempt.status == PhotoVerification.STATUS.ready

        # ready (can't approve or deny unless it's "submitted")
        pytest.raises(VerificationException, attempt.approve)
        pytest.raises(VerificationException, attempt.deny)
        attempt.mark_must_retry()
        attempt.mark_submit()

        DENY_ERROR_MSG = '[{"photoIdReasons": ["Not provided"]}]'

        # must_retry
        attempt.status = PhotoVerification.STATUS.must_retry
        attempt.system_error("System error")
        attempt.mark_must_retry()  # no-op
        attempt.mark_submit()
        attempt.approve()

        attempt.status = PhotoVerification.STATUS.must_retry
        attempt.deny(DENY_ERROR_MSG)

        # submitted
        attempt.status = PhotoVerification.STATUS.submitted
        attempt.deny(DENY_ERROR_MSG)

        attempt.status = PhotoVerification.STATUS.submitted
        attempt.mark_must_retry()

        attempt.status = PhotoVerification.STATUS.submitted
        attempt.approve()

        # approved
        pytest.raises(VerificationException, attempt.submit)
        pytest.raises(VerificationException, attempt.mark_must_retry)
        pytest.raises(VerificationException, attempt.mark_submit)
        attempt.approve()  # no-op
        attempt.system_error(
            "System error")  # no-op, something processed it without error
        attempt.deny(DENY_ERROR_MSG)

        # denied
        pytest.raises(VerificationException, attempt.submit)
        pytest.raises(VerificationException, attempt.mark_must_retry)
        pytest.raises(VerificationException, attempt.mark_submit)
        attempt.deny(DENY_ERROR_MSG)  # no-op
        attempt.system_error(
            "System error")  # no-op, something processed it without error
        attempt.approve()