'Tests that FEATURES[\'BYPASS_ACTIVATION_EMAIL_FOR_EXTAUTH\'] means extauth automatically
linked users, activates them, and logs them in'

def _test_auto_activate_user_with_flag(self, log_user_string='inactive@stanford.edu'):

    inactive_user = UserFactory.create(email='inactive@stanford.edu')
    inactive_user.is_active = False
    inactive_user.save()
    request = self.request_factory.get('/shib-login')
    request.session = import_module(settings.SESSION_ENGINE).SessionStore()
    request.META.update({'Shib-Identity-Provider': 'https://idp.stanford.edu/', 'REMOTE_USER': 'inactive@stanford.edu', 'mail': 'inactive@stanford.edu'})
    request.user = AnonymousUser()
    with patch('openedx.core.djangoapps.external_auth.views.AUDIT_LOG') as mock_audit_log:
        response = shib_login(request)
    audit_log_calls = mock_audit_log.method_calls
    inactive_user = User.objects.get(id=inactive_user.id)
    self.assertIsNotNone(ExternalAuthMap.objects.get(user=inactive_user))
    self.assertTrue(inactive_user.is_active)
    self.assertIsInstance(response, HttpResponseRedirect)
    self.assertEqual(request.user, inactive_user)
    self.assertEqual(response['Location'], '/dashboard')
    self.assertEquals(len(audit_log_calls), 3)
    self._assert_shib_login_is_logged(audit_log_calls[0], log_user_string)
    (method_name, args, _kwargs) = audit_log_calls[2]
    self.assertEquals(method_name, 'info')
    self.assertEquals(len(args), 1)
    self.assertIn(u'Login    success', args[0])
    self.assertIn(log_user_string, args[0])
