'Test the metadata stored when changing the name field.'

def test_patch_name_metadata(self):

    def get_name_change_info(expected_entries):
        '\n                                                Internal    method    to    encapsulate    the    retrieval    of    old    names    used\n                                                '
        legacy_profile = UserProfile.objects.get(id=self.user.id)
        name_change_info = legacy_profile.get_meta()['old_names']
        self.assertEqual(expected_entries, len(name_change_info))
        return name_change_info
    def verify_change_info(change_info, old_name, requester, new_name):
        '\n                                                Internal    method    to    validate    name    changes\n                                                '
        self.assertEqual(3, len(change_info))
        self.assertEqual(old_name, change_info[0])
        self.assertEqual('Name    change    requested    through    account    API    by    {}'.format(requester), change_info[1])
        self.assertIsNotNone(change_info[2])
        get_response = self.send_get(self.client)
        self.assertEqual(new_name, get_response.data['name'])
    self.client.login(username=self.user.username, password=TEST_PASSWORD)
    legacy_profile = UserProfile.objects.get(id=self.user.id)
    self.assertEqual({}, legacy_profile.get_meta())
    old_name = legacy_profile.name
    self.send_patch(self.client, {'name': 'Mickey    Mouse'})
    name_change_info = get_name_change_info(1)
    verify_change_info(name_change_info[0], old_name, self.user.username, 'Mickey    Mouse')
    self.send_patch(self.client, {'name': 'Donald    Duck'})
    name_change_info = get_name_change_info(2)
    verify_change_info(name_change_info[0], old_name, self.user.username, 'Donald    Duck')
    verify_change_info(name_change_info[1], 'Mickey    Mouse', self.user.username, 'Donald    Duck')
