'Tests that updates to state impact the creator group maintained in authz.py and that e-mails are sent.'

@mock.patch('course_creators.admin.render_to_string', mock.Mock(side_effect=mock_render_to_string, autospec=True))
@mock.patch('django.contrib.auth.models.User.email_user')
def test_change_status(self, email_user):

    def change_state_and_verify_email(state, is_creator):
        '    Changes    user    state,    verifies    creator    status,    and    verifies    e-mail    is    sent    based    on    transition    '
        self._change_state(state)
        self.assertEqual(is_creator, auth.user_has_role(self.user, CourseCreatorRole()))
        context = {'studio_request_email': self.studio_request_email}
        if (state == CourseCreator.GRANTED):
            template = 'emails/course_creator_granted.txt'
        elif (state == CourseCreator.DENIED):
            template = 'emails/course_creator_denied.txt'
        else:
            template = 'emails/course_creator_revoked.txt'
        email_user.assert_called_with(mock_render_to_string('emails/course_creator_subject.txt', context), mock_render_to_string(template, context), self.studio_request_email)
    with mock.patch.dict('django.conf.settings.FEATURES', self.enable_creator_group_patch):
        self.assertFalse(auth.user_has_role(self.user, CourseCreatorRole()))
        change_state_and_verify_email(CourseCreator.GRANTED, True)
        change_state_and_verify_email(CourseCreator.DENIED, False)
        change_state_and_verify_email(CourseCreator.GRANTED, True)
        change_state_and_verify_email(CourseCreator.PENDING, False)
        change_state_and_verify_email(CourseCreator.GRANTED, True)
        change_state_and_verify_email(CourseCreator.UNREQUESTED, False)
        change_state_and_verify_email(CourseCreator.DENIED, False)
