예제 #1
0
    def _lock_workflow(self, doc, edit_url):
        """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.
        """
        _login = lambda u: self.client.login(username=u.username,
                                             password='******')
        assert_is_locked = lambda r: self.assertContains(
            r, 'id="unlock-button"')
        assert_not_locked = lambda r: self.assertNotContains(
            r, 'id="unlock-button"')

        u1 = user(save=True, password='******')
        u2 = user(save=True, password='******')

        # With u1, edit the document. No lock should be found.
        _login(u1)
        r = self.client.get(edit_url)
        # Now load it again, the page should not show as being locked (since u1 has the lock)
        r = self.client.get(edit_url)
        assert_not_locked(r)

        # With u2, edit the document. It should be locked.
        _login(u2)
        r = self.client.get(edit_url)
        assert_is_locked(r)
        # Simulate stealing the lock by clicking the button.
        _document_lock_steal(doc.id, u2.username)
        r = self.client.get(edit_url)
        assert_not_locked(r)

        # Now u1 should see the page as locked.
        _login(u1)
        r = self.client.get(edit_url)
        assert_is_locked(r)

        # Now u2 submits the page, clearing the held lock.
        _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)

        # And u1 should not see a lock warning.
        _login(u1)
        r = self.client.get(edit_url)
        assert_not_locked(r)
예제 #2
0
    def _lock_workflow(self, doc, edit_url):
        """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.
        """
        _login = lambda u: self.client.login(username=u.username, password='******')
        assert_is_locked = lambda r: self.assertContains(r, 'id="unlock-button"')
        assert_not_locked = lambda r: self.assertNotContains(r, 'id="unlock-button"')

        u1 = user(save=True, password='******')
        u2 = user(save=True, password='******')

        # With u1, edit the document. No lock should be found.
        _login(u1)
        r = self.client.get(edit_url)
        # Now load it again, the page should not show as being locked (since u1 has the lock)
        r = self.client.get(edit_url)
        assert_not_locked(r)

        # With u2, edit the document. It should be locked.
        _login(u2)
        r = self.client.get(edit_url)
        assert_is_locked(r)
        # Simulate stealing the lock by clicking the button.
        _document_lock_steal(doc.id, u2.username)
        r = self.client.get(edit_url)
        assert_not_locked(r)

        # Now u1 should see the page as locked.
        _login(u1)
        r = self.client.get(edit_url)
        assert_is_locked(r)

        # Now u2 submits the page, clearing the held lock.
        _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)

        # And u1 should not see a lock warning.
        _login(u1)
        r = self.client.get(edit_url)
        assert_not_locked(r)
예제 #3
0
    def _test_lock_helpers(self, doc):
        u1 = user(save=True)
        u2 = user(save=True)

        # No one has the document locked yet.
        eq_(_document_lock_check(doc.id), None)
        # u1 should be able to lock the doc
        eq_(_document_lock_steal(doc.id, u1.username), True)
        eq_(_document_lock_check(doc.id), u1.username)
        # u2 should be able to steal the lock
        eq_(_document_lock_steal(doc.id, u2.username), True)
        eq_(_document_lock_check(doc.id), u2.username)
        # u1 can't release the lock, because u2 stole it
        eq_(_document_lock_clear(doc.id, u1.username), False)
        eq_(_document_lock_check(doc.id), u2.username)
        # u2 can release the lock
        eq_(_document_lock_clear(doc.id, u2.username), True)
        eq_(_document_lock_check(doc.id), None)
예제 #4
0
    def _test_lock_helpers(self, doc):
        u1 = user(save=True)
        u2 = user(save=True)

        # No one has the document locked yet.
        eq_(_document_lock_check(doc.id), None)
        # u1 should be able to lock the doc
        eq_(_document_lock_steal(doc.id, u1.username), True)
        eq_(_document_lock_check(doc.id), u1.username)
        # u2 should be able to steal the lock
        eq_(_document_lock_steal(doc.id, u2.username), True)
        eq_(_document_lock_check(doc.id), u2.username)
        # u1 can't release the lock, because u2 stole it
        eq_(_document_lock_clear(doc.id, u1.username), False)
        eq_(_document_lock_check(doc.id), u2.username)
        # u2 can release the lock
        eq_(_document_lock_clear(doc.id, u2.username), True)
        eq_(_document_lock_check(doc.id), None)