'This is a big end to end feature test of document locking.
This tests that when a user starts editing a page, it gets locked,
users can steal locks, and that when a user submits the edit page, the
lock is cleared.'

def _lock_workflow(self, doc, edit_url):

    def _login(user):
        self.client.login(username=user.username, password='testpass')
    def assert_is_locked(r):
        self.assertContains(r, 'id="unlock-button"')
    def assert_not_locked(r):
        self.assertNotContains(r, 'id="unlock-button"')
    u1 = UserFactory(password='testpass')
    u2 = UserFactory(password='testpass')
    _login(u1)
    r = self.client.get(edit_url)
    r = self.client.get(edit_url)
    assert_not_locked(r)
    _login(u2)
    r = self.client.get(edit_url)
    assert_is_locked(r)
    _document_lock_steal(doc.id, u2.username)
    r = self.client.get(edit_url)
    assert_not_locked(r)
    _login(u1)
    r = self.client.get(edit_url)
    assert_is_locked(r)
    _login(u2)
    r = self.client.post(edit_url)
    data = new_document_data()
    data.update({'title': doc.title, 'slug': doc.slug, 'form': 'doc'})
    self.client.post(edit_url, data)
    _login(u1)
    r = self.client.get(edit_url)
    assert_not_locked(r)
