'Test that the user can request an email change through the accounts API.
Full testing of the helper method used (do_email_change_request) exists in the package with the code.
Here just do minimal smoke testing.'

@patch.dict('django.conf.settings.PROFILE_IMAGE_SIZES_MAP', {'full': 50, 'medium': 30, 'small': 10}, clear=True)
def test_patch_email(self):

    client = self.login_client('client', 'user')
    old_email = self.user.email
    new_email = 'newemail@example.com'
    response = self.send_patch(client, {'email': new_email, 'goals': 'change    my    email'})
    self.assertEqual(old_email, response.data['email'])
    self.assertEqual('change    my    email', response.data['goals'])
    pending_change = PendingEmailChange.objects.filter(user=self.user)
    self.assertEqual(1, len(pending_change))
    activation_key = pending_change[0].activation_key
    confirm_change_url = reverse('student.views.confirm_email_change', kwargs={'key': activation_key})
    response = self.client.post(confirm_change_url)
    self.assertEqual(200, response.status_code)
    get_response = self.send_get(client)
    self.assertEqual(new_email, get_response.data['email'])
