'If both a revision and the edited section has changed, then a
section edit is a collision.'

@pytest.mark.midair
def test_midair_section_collision_ajax(self):

    self.client.login(username='admin', password='testpass')
    rev = revision(is_approved=True, save=True, content='\n                                                <h1    id="s1">s1</h1>\n                                                <p>test</p>\n                                                <p>test</p>\n\n                                                <h1    id="s2">s2</h1>\n                                                <p>test</p>\n                                                <p>test</p>\n\n                                                <h1    id="s3">s3</h1>\n                                                <p>test</p>\n                                                <p>test</p>\n                                ')
    replace_1 = '\n                                                <h1    id="s2">replace</h1>\n                                                <p>replace</p>\n                                '
    replace_2 = '\n                                                <h1    id="s2">first    replace</h1>\n                                                <p>first    replace</p>\n                                '
    data = {'form-type': 'rev', 'content': rev.content}
    resp = self.client.get(('%s?section=s2' % reverse('wiki.edit', args=[rev.document.slug])), HTTP_X_REQUESTED_WITH='XMLHttpRequest')
    page = pq(resp.content)
    rev_id1 = page.find('input[name="current_rev"]').attr('value')
    resp = self.client.get(('%s?section=s2' % reverse('wiki.edit', args=[rev.document.slug])), HTTP_X_REQUESTED_WITH='XMLHttpRequest')
    page = pq(resp.content)
    rev_id2 = page.find('input[name="current_rev"]').attr('value')
    data.update({'form-type': 'rev', 'content': replace_2, 'slug': rev.document.slug, 'current_rev': rev_id2})
    resp = self.client.post(('%s?section=s2&raw=true' % reverse('wiki.edit', args=[rev.document.slug])), data, HTTP_X_REQUESTED_WITH='XMLHttpRequest')
    eq_(False, json.loads(resp.content)['error'])
    data.update({'form': 'rev', 'content': replace_1, 'current_rev': rev_id1})
    resp = self.client.post(('%s?section=s2&raw=true' % reverse('wiki.edit', args=[rev.document.slug])), data, HTTP_X_REQUESTED_WITH='XMLHttpRequest')
    eq_(200, resp.status_code)
    history_url = reverse('wiki.document_revisions', kwargs={'document_path': rev.document.slug}, locale=rev.document.locale)
    midair_collission_error = (unicode(MIDAIR_COLLISION) % {'url': history_url}).encode('utf-8')
    ok_((midair_collission_error in json.loads(resp.content)['error_message']), 'Midair    collision    message    should    appear')
