'Test that the LANGUAGE_COOKIE is always set to the user\'s current language preferences
at the end of the request, with an expiry that\'s the same as the users current session cookie.'

@ddt.data(None, 'es', 'en')
def test_preference_setting_changes_cookie(self, lang_pref_out):

    if lang_pref_out:
        set_user_preference(self.user, LANGUAGE_KEY, lang_pref_out)
    else:
        delete_user_preference(self.user, LANGUAGE_KEY)
    response = mock.Mock(spec=HttpResponse)
    self.middleware.process_response(self.request, response)
    if lang_pref_out:
        response.set_cookie.assert_called_with(settings.LANGUAGE_COOKIE, value=lang_pref_out, domain=settings.SESSION_COOKIE_DOMAIN, max_age=COOKIE_DURATION)
    else:
        response.delete_cookie.assert_called_with(settings.LANGUAGE_COOKIE, domain=settings.SESSION_COOKIE_DOMAIN)
    self.assertNotIn(LANGUAGE_SESSION_KEY, self.request.session)
