'Test that a client (logged in) receives appropriate errors for a bad update.'

def test_update_preferences_bad_data(self):

    set_user_preference(self.user, 'dict_pref', {'int_key': 10})
    set_user_preference(self.user, 'string_pref', 'value')
    set_user_preference(self.user, 'extra_pref', 'extra_value')
    set_user_preference(self.user, 'time_zone', 'Pacific/Midway')
    self.client.login(username=self.user.username, password=TEST_PASSWORD)
    response = self.send_patch(self.client, {'string_pref': 'updated_value', TOO_LONG_PREFERENCE_KEY: 'new_value', 'new_pref': 'new_value', u'empty_pref_\u023b\u0127\u023a\u024d\u0142\u0247s': '', 'time_zone': 'Asia/Africa'}, expected_status=400)
    self.assertTrue(response.data.get('field_errors', None))
    field_errors = response.data['field_errors']
    self.assertEquals(field_errors, {TOO_LONG_PREFERENCE_KEY: {'developer_message': get_expected_validation_developer_message(TOO_LONG_PREFERENCE_KEY, 'new_value'), 'user_message': get_expected_key_error_user_message(TOO_LONG_PREFERENCE_KEY, 'new_value')}, u'empty_pref_\u023b\u0127\u023a\u024d\u0142\u0247s': {'developer_message': u"Preference    'empty_pref_\u023b\u0127\u023a\u024d\u0142\u0247s'    cannot    be    set    to    an    empty    value.", 'user_message': u"Preference    'empty_pref_\u023b\u0127\u023a\u024d\u0142\u0247s'    cannot    be    set    to    an    empty    value."}, 'time_zone': {'developer_message': u"Value    'Asia/Africa'    not    valid    for    preference    'time_zone':    Not    in    timezone    set.", 'user_message': u"Value    'Asia/Africa'    is    not    a    valid    time    zone    selection."}})
    response = self.send_get(self.client)
    expected_preferences = {u'dict_pref': u"{'int_key':    10}", u'string_pref': u'value', u'extra_pref': u'extra_value', u'time_zone': u'Pacific/Midway'}
    self.assertEqual(expected_preferences, response.data)
