Beispiel #1
0
    def test_title_slug_collision_errors(self):
        """When an attempt is made to retitle an article and another with that
        title already exists, there should be form errors"""
        client = LocalizingClient()
        client.login(username='******', password='******')

        exist_title = "Existing doc"
        exist_slug = "existing-doc"

        # Create a new doc.
        data = new_document_data()
        data.update({"title": exist_title, "slug": exist_slug})
        resp = client.post(reverse('wiki.new_document'), data)
        eq_(302, resp.status_code)

        # Create another new doc.
        data = new_document_data()
        data.update({"title": 'Some new title', "slug": 'some-new-title'})
        response = client.post(reverse('wiki.new_document'), data)
        eq_(302, resp.status_code)

        # Now, post an update with duplicate slug and title
        data.update({'form': 'rev', 'title': exist_title, 'slug': exist_slug})
        resp = client.post(
            reverse('wiki.edit_document', args=['some-new-title']), data)
        eq_(200, resp.status_code)
        p = pq(resp.content)

        ok_(p.find('.errorlist').length > 0)
        ok_(p.find('.errorlist a[href="#id_title"]').length > 0)
        ok_(p.find('.errorlist a[href="#id_slug"]').length > 0)
Beispiel #2
0
    def test_title_slug_collision_errors(self):
        """When an attempt is made to retitle an article and another with that
        title already exists, there should be form errors"""
        client = LocalizingClient()
        client.login(username='******', password='******')

        exist_title = "Existing doc"
        exist_slug = "existing-doc"

        # Create a new doc.
        data = new_document_data()
        data.update({ "title": exist_title, "slug": exist_slug })
        resp = client.post(reverse('wiki.new_document'), data)
        eq_(302, resp.status_code)

        # Create another new doc.
        data = new_document_data()
        data.update({ "title": 'Some new title', "slug": 'some-new-title' })
        response = client.post(reverse('wiki.new_document'), data)
        eq_(302, resp.status_code)

        # Now, post an update with duplicate slug and title
        data.update({
            'form': 'rev',
            'title': exist_title,
            'slug': exist_slug
        })
        resp = client.post(reverse('wiki.edit_document', args=['some-new-title']), data)
        eq_(200, resp.status_code)
        p = pq(resp.content)

        ok_(p.find('.errorlist').length > 0)
        ok_(p.find('.errorlist a[href="#id_title"]').length > 0)
        ok_(p.find('.errorlist a[href="#id_slug"]').length > 0)
Beispiel #3
0
    def test_needs_change(self):
        """Test setting and unsetting the needs change flag"""
        # Create a new document and edit it, setting needs_change.
        comment = 'Please update for Firefix.next'
        doc = revision(save=True).document
        data = new_document_data()
        data.update({'needs_change': True,
                     'needs_change_comment': comment,
                     'form': 'doc'})

        # Verify that needs_change can't be set if the user doesn't have
        # the permission.
        self.client.post(reverse('wiki.edit_document', args=[doc.slug]), data)
        doc = Document.uncached.get(pk=doc.pk)
        assert not doc.needs_change
        assert not doc.needs_change_comment

        # Give the user permission, now it should work.
        add_permission(self.u, Document, 'edit_needs_change')
        self.client.post(reverse('wiki.edit_document', args=[doc.slug]), data)
        doc = Document.uncached.get(pk=doc.pk)
        assert doc.needs_change
        eq_(comment, doc.needs_change_comment)

        # Clear out needs_change.
        data.update({'needs_change': False,
                     'needs_change_comment': comment})
        self.client.post(reverse('wiki.edit_document', args=[doc.slug]), data)
        doc = Document.uncached.get(pk=doc.pk)
        assert not doc.needs_change
        eq_('', doc.needs_change_comment)
Beispiel #4
0
    def test_invalid_slugs(self, get_current):
        """Slugs cannot contain /."""
        get_current.return_value.domain = 'testserver'
        data = new_document_data()
        error = 'The slug provided is not valid.'

        data['slug'] = 'inva/lid'
        response = self.client.post(reverse('wiki.new_document'), data)
        self.assertContains(response, error)

        data['slug'] = 'no-question-marks?'
        response = self.client.post(reverse('wiki.new_document'), data)
        self.assertContains(response, error)

        data['slug'] = 'no+plus'
        response = self.client.post(reverse('wiki.new_document'), data)
        self.assertContains(response, error)

        data['slug'] = 'valid'
        response = self.client.post(reverse('wiki.new_document'), data)
        self.assertRedirects(
            response,
            reverse('wiki.document_revisions',
                    args=[data['slug']],
                    locale='en-US'))
Beispiel #5
0
    def test_changing_products(self):
        """Changing products works as expected."""
        d, r = doc_rev()
        prod_desktop = product(title=u'desktop', save=True)
        prod_mobile = product(title=u'mobile', save=True)

        data = new_document_data()
        data.update({
            'products': [prod_desktop.id, prod_mobile.id],
            'title': d.title,
            'slug': d.slug,
            'form': 'doc'
        })
        self.client.post(reverse('wiki.edit_document', args=[d.slug]), data)

        eq_(
            sorted(
                Document.uncached.get(slug=d.slug).products.values_list(
                    'id', flat=True)),
            sorted([prod.id for prod in [prod_desktop, prod_mobile]]))

        data.update({'products': [prod_desktop.id], 'form': 'doc'})
        self.client.post(reverse('wiki.edit_document', args=[data['slug']]),
                         data)
        eq_(
            sorted(
                Document.uncached.get(slug=d.slug).products.values_list(
                    'id', flat=True)),
            sorted([prod.id for prod in [prod_desktop]]))
Beispiel #6
0
    def test_redirect_can_be_clobbered(self):
        """When an attempt is made to retitle an article, and another article
        with that title exists but is a redirect, there should be no errors and
        the redirect should be replaced."""
        client = LocalizingClient()
        client.login(username='******', password='******')

        exist_title = "Existing doc"
        exist_slug = "existing-doc"

        # Create a new doc.
        data = new_document_data()
        data.update({"title": exist_title, "slug": exist_slug})
        resp = client.post(reverse('wiki.new_document'), data)
        eq_(302, resp.status_code)

        # Change title and slug
        data.update({
            'form': 'rev',
            'title': "Changed title",
            'slug': "changed-title"
        })
        resp = client.post(reverse('wiki.edit_document', args=[exist_slug]),
                           data)
        eq_(302, resp.status_code)

        # Change title and slug back to originals, clobbering the redirect
        data.update({'form': 'rev', 'title': exist_title, 'slug': exist_slug})
        resp = client.post(
            reverse('wiki.edit_document', args=["changed-title"]), data)
        eq_(302, resp.status_code)
Beispiel #7
0
    def test_invalid_slug(self):
        """Slugs cannot contain "$", but can contain "/"."""
        client = LocalizingClient()
        client.login(username='******', password='******')
        data = new_document_data()

        data['title'] = 'valid slug'
        data['slug'] = 'valid'
        response = client.post(reverse('wiki.new_document'), data)
        self.assertRedirects(response,
                             reverse('wiki.document', args=[data['slug']]))

        # Slashes should be fine
        data['title'] = 'valid with slash'
        data['slug'] = 'va/lid'
        response = client.post(reverse('wiki.new_document'), data)
        self.assertRedirects(response,
                             reverse('wiki.document', args=[data['slug']]))

        # Dollar sign is reserved for verbs
        data['title'] = 'invalid with dollars'
        data['slug'] = 'inva$lid'
        response = client.post(reverse('wiki.new_document'), data)
        self.assertContains(response, 'The slug provided is not valid.')

        # Question mark is reserved for query params
        data['title'] = 'invalid with questions'
        data['slug'] = 'inva?lid'
        response = client.post(reverse('wiki.new_document'), data)
        self.assertContains(response, 'The slug provided is not valid.')
Beispiel #8
0
    def test_invalid_reserved_term_slug(self):
        """Slugs should not collide with reserved URL patterns"""
        client = LocalizingClient()
        client.login(username='******', password='******')
        data = new_document_data()

        # TODO: This is info derived from urls.py, but unsure how to DRY it
        reserved_slugs = (
            'ckeditor_config.js',
            'watch-ready-for-review',
            'unwatch-ready-for-review',
            'watch-approved',
            'unwatch-approved',
            '.json',
            'new',
            'all',
            'preview-wiki-content',
            'category/10',
            'needs-review/technical',
            'needs-review/',
            'feeds/atom/all/',
            'feeds/atom/needs-review/technical',
            'feeds/atom/needs-review/',
            'tag/tasty-pie'
        )

        for term in reserved_slugs:
            data['title'] = 'invalid with %s' % term
            data['slug'] = term
            response = client.post(reverse('wiki.new_document'), data)
            self.assertContains(response, 'The slug provided is not valid.')
Beispiel #9
0
    def test_invalid_slug(self):
        """Slugs cannot contain "$", but can contain "/"."""
        client = LocalizingClient()
        client.login(username='******', password='******')
        data = new_document_data()

        data['title'] = 'valid slug'
        data['slug'] = 'valid'
        response = client.post(reverse('wiki.new_document'), data)
        self.assertRedirects(response, reverse('wiki.document',
                                               args=[data['slug']],
                                               locale='en-US'))

        # Slashes should be fine
        data['title'] = 'valid with slash'
        data['slug'] = 'va/lid'
        response = client.post(reverse('wiki.new_document'), data)
        self.assertRedirects(response, reverse('wiki.document',
                                               args=[data['slug']],
                                               locale='en-US'))

        # Dollar sign is reserved for verbs
        data['title'] = 'invalid with dollars'
        data['slug'] = 'inva$lid'
        response = client.post(reverse('wiki.new_document'), data)
        self.assertContains(response, 'The slug provided is not valid.')

        # Question mark is reserved for query params
        data['title'] = 'invalid with questions'
        data['slug'] = 'inva?lid'
        response = client.post(reverse('wiki.new_document'), data)
        self.assertContains(response, 'The slug provided is not valid.')
Beispiel #10
0
    def test_redirect_can_be_clobbered(self):
        """When an attempt is made to retitle an article, and another article
        with that title exists but is a redirect, there should be no errors and
        the redirect should be replaced."""
        client = LocalizingClient()
        client.login(username='******', password='******')

        exist_title = "Existing doc"
        exist_slug = "existing-doc"

        # Create a new doc.
        data = new_document_data()
        data.update({ "title": exist_title, "slug": exist_slug })
        resp = client.post(reverse('wiki.new_document'), data)
        eq_(302, resp.status_code)

        # Change title and slug
        data.update({'form': 'rev', 
                     'title': "Changed title", 
                     'slug': "changed-title"})
        resp = client.post(reverse('wiki.edit_document', args=[exist_slug]), 
                           data)
        eq_(302, resp.status_code)

        # Change title and slug back to originals, clobbering the redirect
        data.update({'form': 'rev', 
                     'title': exist_title, 
                     'slug': exist_slug})
        resp = client.post(reverse('wiki.edit_document', args=["changed-title"]), 
                           data)
        eq_(302, resp.status_code)
Beispiel #11
0
    def test_invalid_slugs(self, get_current):
        """Slugs cannot contain /."""
        get_current.return_value.domain = 'testserver'
        client = LocalizingClient()
        client.login(username='******', password='******')
        data = new_document_data()
        error = 'The slug provided is not valid.'

        data['slug'] = 'inva/lid'
        response = client.post(reverse('wiki.new_document'), data)
        self.assertContains(response, error)

        data['slug'] = 'no-question-marks?'
        response = client.post(reverse('wiki.new_document'), data)
        self.assertContains(response, error)

        data['slug'] = 'no+plus'
        response = client.post(reverse('wiki.new_document'), data)
        self.assertContains(response, error)

        data['slug'] = 'valid'
        response = client.post(reverse('wiki.new_document'), data)
        self.assertRedirects(response, reverse('wiki.document_revisions',
                                               args=[data['slug']],
                                               locale='en-US'))
Beispiel #12
0
    def test_review_tags(self):
        client = LocalizingClient()
        client.login(username='******', password='******')

        data = new_document_data()
        data.update({'review_tags':['editorial']})
        response = client.post(reverse('wiki.new_document'), data)

        doc = Document.objects.get(slug="a-test-article")

        combos = (
            ([], 0, 0, 0, 0),
            (['technical',], 1, 1, 0, 0),
            (['editorial',], 0, 0, 1, 1),
            (['technical', 'editorial',], 1, 1, 1, 1),
        )

        for tags, a, b, c, d in combos:

            # Edit the page and set the tags for this test
            data.update({ 'form': 'rev', 'review_tags': tags })
            response = client.post(reverse('wiki.edit_document', args=[doc.slug]), data)

            response = client.get(reverse('docs.views.docs'))
            page = pq(response.content)

            # Check for the section itself, and then the doc 
            eq_(a, page('div#review-technical').length)
            eq_(b, page("div#review-technical ul li h4 a:contains('%s')" %
                doc.title).length)
            eq_(c, page('div#review-editorial').length)
            eq_(d, page("div#review-editorial ul li h4 a:contains('%s')" %
                doc.title).length)
Beispiel #13
0
    def test_needs_change(self):
        """Test setting and unsetting the needs change flag"""
        # Create a new document and edit it, setting needs_change.
        comment = 'Please update for Firefix.next'
        doc = revision(save=True).document
        data = new_document_data()
        data.update({
            'needs_change': True,
            'needs_change_comment': comment,
            'form': 'doc'
        })

        # Verify that needs_change can't be set if the user doesn't have
        # the permission.
        self.client.post(reverse('wiki.edit_document', args=[doc.slug]), data)
        doc = Document.uncached.get(pk=doc.pk)
        assert not doc.needs_change
        assert not doc.needs_change_comment

        # Give the user permission, now it should work.
        add_permission(self.u, Document, 'edit_needs_change')
        self.client.post(reverse('wiki.edit_document', args=[doc.slug]), data)
        doc = Document.uncached.get(pk=doc.pk)
        assert doc.needs_change
        eq_(comment, doc.needs_change_comment)

        # Clear out needs_change.
        data.update({'needs_change': False, 'needs_change_comment': comment})
        self.client.post(reverse('wiki.edit_document', args=[doc.slug]), data)
        doc = Document.uncached.get(pk=doc.pk)
        assert not doc.needs_change
        eq_('', doc.needs_change_comment)
Beispiel #14
0
 def test_changing_products(self):
     """Changing products works as expected."""
     d, r = doc_rev()
     data = new_document_data()
     data.update({'products': ['desktop', 'sync'], 'form': 'doc'})
     self.client.post(reverse('wiki.edit_document', args=[d.slug]), data)
     tags_eq(d, ['desktop', 'sync'])
     data.update({'products': ['mobile'], 'form': 'doc'})
     self.client.post(reverse('wiki.edit_document', args=[data['slug']]),
                      data)
     tags_eq(d, ['mobile'])
Beispiel #15
0
 def test_retitling(self):
     """When the title of an article is edited, a redirect is made."""
     # Not testing slug changes separately; the model tests cover those plus
     # slug+title changes. If title changes work in the view, the rest
     # should also.
     new_title = 'Some New Title'
     d, r = doc_rev()
     old_title = d.title
     data = new_document_data()
     data.update({'title': new_title, 'slug': d.slug, 'form': 'doc'})
     self.client.post(reverse('wiki.edit_document', args=[d.slug]), data)
     eq_(new_title, Document.uncached.get(slug=d.slug).title)
     assert Document.uncached.get(title=old_title).redirect_url()
Beispiel #16
0
 def test_changing_products(self):
     """Changing products works as expected."""
     d, r = doc_rev()
     data = new_document_data()
     data.update({'products': ['desktop', 'sync'],
                  'form': 'doc'})
     self.client.post(reverse('wiki.edit_document', args=[d.slug]), data)
     tags_eq(d, ['desktop', 'sync'])
     data.update({'products': ['mobile'],
                  'form': 'doc'})
     self.client.post(reverse('wiki.edit_document', args=[data['slug']]),
                      data)
     tags_eq(d, ['mobile'])
Beispiel #17
0
 def test_retitling(self):
     """When the title of an article is edited, a redirect is made."""
     # Not testing slug changes separately; the model tests cover those plus
     # slug+title changes. If title changes work in the view, the rest
     # should also.
     new_title = "Some New Title"
     d, r = doc_rev()
     old_title = d.title
     data = new_document_data()
     data.update({"title": new_title, "slug": d.slug, "form": "doc"})
     self.client.post(reverse("wiki.edit_document", args=[d.slug]), data)
     eq_(new_title, Document.uncached.get(slug=d.slug).title)
     assert Document.uncached.get(title=old_title).redirect_url()
Beispiel #18
0
 def test_changing_products(self):
     """Changing products works as expected."""
     client = LocalizingClient()
     client.login(username='******', password='******')
     d, r = doc_rev()
     data = new_document_data()
     data.update({'products': ['desktop', 'sync'],
                  'form': 'doc'})
     client.post(reverse('wiki.edit_document', args=[d.slug]), data)
     tags_eq(d, ['desktop', 'sync'])
     data.update({'products': ['mobile'],
                  'form': 'doc'})
     client.post(reverse('wiki.edit_document', args=[data['slug']]), data)
     tags_eq(d, ['mobile'])
Beispiel #19
0
 def test_retitling_ignored_for_iframe(self):
     """When the title of an article is edited in an iframe, the change is
     ignored."""
     client = LocalizingClient()
     client.login(username='******', password='******')
     new_title = 'Some New Title'
     d, r = doc_rev()
     old_title = d.title
     data = new_document_data()
     data.update({'title': new_title, 'slug': d.slug, 'form': 'rev'})
     client.post(
         '%s?iframe=1' % reverse('wiki.edit_document', args=[d.slug]), data)
     eq_(old_title, Document.uncached.get(slug=d.slug).title)
     assert "REDIRECT" not in Document.uncached.get(title=old_title).html
Beispiel #20
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)
Beispiel #21
0
    def test_invalid_slug(self):
        """Slugs cannot contain /."""
        client = LocalizingClient()
        client.login(username='******', password='******')
        data = new_document_data()
        data['slug'] = 'inva/lid'
        response = client.post(reverse('wiki.new_document'), data)
        self.assertContains(response, 'The slug provided is not valid.')

        data['slug'] = 'valid'
        response = client.post(reverse('wiki.new_document'), data)
        self.assertRedirects(response, reverse('wiki.document_revisions',
                                               args=[data['slug']],
                                               locale='en-US'))
Beispiel #22
0
 def test_retitling(self):
     """When the title of an article is edited, a redirect is made."""
     # Not testing slug changes separately; the model tests cover those plus
     # slug+title changes. If title changes work in the view, the rest
     # should also.
     client = LocalizingClient()
     client.login(username='******', password='******')
     new_title = 'Some New Title'
     d, r = doc_rev()
     old_title = d.title
     data = new_document_data()
     data.update({'title': new_title, 'slug': d.slug, 'form': 'rev'})
     client.post(reverse('wiki.edit_document', args=[d.slug]), data)
     eq_(new_title, Document.uncached.get(slug=d.slug).title)
     assert "REDIRECT" in Document.uncached.get(title=old_title).html
Beispiel #23
0
 def test_retitling_ignored_for_iframe(self):
     """When the title of an article is edited in an iframe, the change is
     ignored."""
     client = LocalizingClient()
     client.login(username='******', password='******')
     new_title = 'Some New Title'
     d, r = doc_rev()
     old_title = d.title
     data = new_document_data()
     data.update({'title': new_title,
                  'slug': d.slug,
                  'form': 'rev'})
     client.post('%s?iframe=1' % reverse('wiki.edit_document', args=[d.slug]), data)
     eq_(old_title, Document.uncached.get(slug=d.slug).title)
     assert "REDIRECT" not in Document.uncached.get(title=old_title).html
Beispiel #24
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)
Beispiel #25
0
    def test_invalid_slug(self, get_current):
        """Slugs cannot contain /."""
        get_current.return_value.domain = 'testserver'
        client = LocalizingClient()
        client.login(username='******', password='******')
        data = new_document_data()
        data['slug'] = 'inva/lid'
        response = client.post(reverse('wiki.new_document'), data)
        self.assertContains(response, 'The slug provided is not valid.')

        data['slug'] = 'valid'
        response = client.post(reverse('wiki.new_document'), data)
        self.assertRedirects(
            response,
            reverse('wiki.document_revisions',
                    args=[data['slug']],
                    locale='en-US'))
Beispiel #26
0
 def test_retitling(self):
     """When the title of an article is edited, a redirect is made."""
     # Not testing slug changes separately; the model tests cover those plus
     # slug+title changes. If title changes work in the view, the rest
     # should also.
     client = LocalizingClient()
     client.login(username='******', password='******')
     new_title = 'Some New Title'
     d, r = doc_rev()
     old_title = d.title
     data = new_document_data()
     data.update({'title': new_title,
                  'slug': d.slug,
                  'form': 'doc'})
     client.post(reverse('wiki.edit_document', args=[d.slug]), data)
     eq_(new_title, Document.uncached.get(slug=d.slug).title)
     assert Document.uncached.get(title=old_title).redirect_url()
Beispiel #27
0
    def test_needs_change(self):
        """Test setting and unsetting the needs change flag"""
        # Create a new document and edit it, setting needs_change.
        comment = "Please update for Firefix.next"
        doc = revision(save=True).document
        data = new_document_data()
        data.update({"needs_change": True, "needs_change_comment": comment, "form": "doc"})
        self.client.post(reverse("wiki.edit_document", args=[doc.slug]), data)
        doc = Document.uncached.get(pk=doc.pk)
        assert doc.needs_change
        eq_(comment, doc.needs_change_comment)

        # Clear out needs_change
        data.update({"needs_change": False, "needs_change_comment": comment})
        self.client.post(reverse("wiki.edit_document", args=[doc.slug]), data)
        doc = Document.uncached.get(pk=doc.pk)
        assert not doc.needs_change
        eq_("", doc.needs_change_comment)
Beispiel #28
0
 def test_changing_metadata(self):
     """Changing metadata works as expected."""
     client = LocalizingClient()
     client.login(username='******', password='******')
     d, r = doc_rev()
     data = new_document_data()
     data.update({'firefox_versions': [1, 2, 3],
                  'operating_systems': [1, 3],
                  'form': 'doc'})
     client.post(reverse('wiki.edit_document', args=[d.slug]), data)
     eq_(3, d.firefox_versions.count())
     eq_(2, d.operating_systems.count())
     data.update({'firefox_versions': [1, 2],
                  'operating_systems': [2],
                  'form': 'doc'})
     client.post(reverse('wiki.edit_document', args=[data['slug']]), data)
     eq_(2, d.firefox_versions.count())
     eq_(1, d.operating_systems.count())
Beispiel #29
0
    def test_edit_midair_collision(self):
        client = LocalizingClient()
        client.login(username='******', password='******')

        # Post a new document.
        data = new_document_data()
        resp = client.post(reverse('wiki.new_document'), data)
        doc = Document.objects.get(slug=data['slug'])

        # Edit #1 starts...
        resp = client.get(reverse('wiki.edit_document', args=[doc.slug]))
        page = pq(resp.content)
        rev_id1 = page.find('input[name="current_rev"]').attr('value')

        # Edit #2 starts...
        resp = client.get(reverse('wiki.edit_document', args=[doc.slug]))
        page = pq(resp.content)
        rev_id2 = page.find('input[name="current_rev"]').attr('value')

        # Edit #2 submits successfully
        data.update({
            'form': 'rev',
            'content': 'This edit got there first',
            'current_rev': rev_id2
        })
        resp = client.post(reverse('wiki.edit_document', args=[doc.slug]),
                           data)
        eq_(302, resp.status_code)

        # Edit #1 submits, but receives a mid-aired notification
        data.update({
            'form': 'rev',
            'content': 'This edit gets mid-aired',
            'current_rev': rev_id1
        })
        resp = client.post(reverse('wiki.edit_document', args=[doc.slug]),
                           data)
        eq_(200, resp.status_code)

        ok_(
            unicode(MIDAIR_COLLISION).encode('utf-8') in resp.content,
            "Midair collision message should appear")
Beispiel #30
0
    def test_needs_change(self):
        """Test setting and unsetting the needs change flag"""
        # Create a new document and edit it, setting needs_change.
        comment = 'Please update for Firefix.next'
        doc = revision(save=True).document
        data = new_document_data()
        data.update({'needs_change': True,
                     'needs_change_comment': comment,
                     'form': 'doc'})
        self.client.post(reverse('wiki.edit_document', args=[doc.slug]), data)
        doc = Document.uncached.get(pk=doc.pk)
        assert doc.needs_change
        eq_(comment, doc.needs_change_comment)

        # Clear out needs_change
        data.update({'needs_change': False,
                     'needs_change_comment': comment})
        self.client.post(reverse('wiki.edit_document', args=[doc.slug]), data)
        doc = Document.uncached.get(pk=doc.pk)
        assert not doc.needs_change
        eq_('', doc.needs_change_comment)
Beispiel #31
0
    def test_changing_products(self):
        """Changing products works as expected."""
        d, r = doc_rev()
        prod_desktop = product(title=u"desktop", save=True)
        prod_mobile = product(title=u"mobile", save=True)

        data = new_document_data()
        data.update({"products": [prod_desktop.id, prod_mobile.id], "title": d.title, "slug": d.slug, "form": "doc"})
        self.client.post(reverse("wiki.edit_document", args=[d.slug]), data)

        eq_(
            sorted(Document.uncached.get(slug=d.slug).products.values_list("id", flat=True)),
            sorted([prod.id for prod in [prod_desktop, prod_mobile]]),
        )

        data.update({"products": [prod_desktop.id], "form": "doc"})
        self.client.post(reverse("wiki.edit_document", args=[data["slug"]]), data)
        eq_(
            sorted(Document.uncached.get(slug=d.slug).products.values_list("id", flat=True)),
            sorted([prod.id for prod in [prod_desktop]]),
        )
Beispiel #32
0
    def test_invalid_slugs(self, get_current):
        """Slugs cannot contain /."""
        get_current.return_value.domain = "testserver"
        data = new_document_data()
        error = "The slug provided is not valid."

        data["slug"] = "inva/lid"
        response = self.client.post(reverse("wiki.new_document"), data)
        self.assertContains(response, error)

        data["slug"] = "no-question-marks?"
        response = self.client.post(reverse("wiki.new_document"), data)
        self.assertContains(response, error)

        data["slug"] = "no+plus"
        response = self.client.post(reverse("wiki.new_document"), data)
        self.assertContains(response, error)

        data["slug"] = "valid"
        response = self.client.post(reverse("wiki.new_document"), data)
        self.assertRedirects(response, reverse("wiki.document_revisions", args=[data["slug"]], locale="en-US"))
Beispiel #33
0
    def test_invalid_reserved_term_slug(self):
        """Slugs should not collide with reserved URL patterns"""
        client = LocalizingClient()
        client.login(username='******', password='******')
        data = new_document_data()

        # TODO: This is info derived from urls.py, but unsure how to DRY it
        reserved_slugs = ('ckeditor_config.js', 'watch-ready-for-review',
                          'unwatch-ready-for-review', 'watch-approved',
                          'unwatch-approved', '.json', 'new', 'all',
                          'preview-wiki-content', 'category/10',
                          'needs-review/technical', 'needs-review/',
                          'feeds/atom/all/',
                          'feeds/atom/needs-review/technical',
                          'feeds/atom/needs-review/', 'tag/tasty-pie')

        for term in reserved_slugs:
            data['title'] = 'invalid with %s' % term
            data['slug'] = term
            response = client.post(reverse('wiki.new_document'), data)
            self.assertContains(response, 'The slug provided is not valid.')
Beispiel #34
0
 def test_changing_metadata(self):
     """Changing metadata works as expected."""
     client = LocalizingClient()
     client.login(username='******', password='******')
     d, r = doc_rev()
     data = new_document_data()
     data.update({
         'firefox_versions': [1, 2, 3],
         'operating_systems': [1, 3],
         'form': 'doc'
     })
     client.post(reverse('wiki.edit_document', args=[d.slug]), data)
     eq_(3, d.firefox_versions.count())
     eq_(2, d.operating_systems.count())
     data.update({
         'firefox_versions': [1, 2],
         'operating_systems': [2],
         'form': 'doc'
     })
     client.post(reverse('wiki.edit_document', args=[data['slug']]), data)
     eq_(2, d.firefox_versions.count())
     eq_(1, d.operating_systems.count())
Beispiel #35
0
    def test_needs_change(self):
        """Test setting and unsetting the needs change flag"""
        # Create a new document and edit it, setting needs_change.
        comment = 'Please update for Firefix.next'
        doc = revision(save=True).document
        data = new_document_data()
        data.update({
            'needs_change': True,
            'needs_change_comment': comment,
            'form': 'doc'
        })
        self.client.post(reverse('wiki.edit_document', args=[doc.slug]), data)
        doc = Document.uncached.get(pk=doc.pk)
        assert doc.needs_change
        eq_(comment, doc.needs_change_comment)

        # Clear out needs_change
        data.update({'needs_change': False, 'needs_change_comment': comment})
        self.client.post(reverse('wiki.edit_document', args=[doc.slug]), data)
        doc = Document.uncached.get(pk=doc.pk)
        assert not doc.needs_change
        eq_('', doc.needs_change_comment)
Beispiel #36
0
    def test_edit_midair_collision(self):
        client = LocalizingClient()
        client.login(username='******', password='******')

        # Post a new document.
        data = new_document_data()
        resp = client.post(reverse('wiki.new_document'), data)
        doc = Document.objects.get(slug=data['slug'])

        # Edit #1 starts...
        resp = client.get(reverse('wiki.edit_document', args=[doc.slug]))
        page = pq(resp.content)
        rev_id1 = page.find('input[name="current_rev"]').attr('value')

        # Edit #2 starts...
        resp = client.get(reverse('wiki.edit_document', args=[doc.slug]))
        page = pq(resp.content)
        rev_id2 = page.find('input[name="current_rev"]').attr('value')

        # Edit #2 submits successfully
        data.update({
            'form': 'rev',
            'content': 'This edit got there first',
            'current_rev': rev_id2
        })
        resp = client.post(reverse('wiki.edit_document', args=[doc.slug]), data)
        eq_(302, resp.status_code)

        # Edit #1 submits, but receives a mid-aired notification
        data.update({
            'form': 'rev',
            'content': 'This edit gets mid-aired',
            'current_rev': rev_id1
        })
        resp = client.post(reverse('wiki.edit_document', args=[doc.slug]), data)
        eq_(200, resp.status_code)

        ok_(unicode(MIDAIR_COLLISION).encode('utf-8') in resp.content,
            "Midair collision message should appear")
Beispiel #37
0
    def test_changing_products(self):
        """Changing products works as expected."""
        d, r = doc_rev()
        prod_desktop = product(title=u'desktop', save=True)
        prod_mobile = product(title=u'mobile', save=True)

        data = new_document_data()
        data.update({'products': [prod_desktop.id, prod_mobile.id],
                     'title': d.title,
                     'slug': d.slug,
                     'form': 'doc'})
        self.client.post(reverse('wiki.edit_document', args=[d.slug]), data)

        eq_(sorted(Document.uncached.get(slug=d.slug).products.values_list(
                    'id', flat=True)),
            sorted([prod.id for prod in [prod_desktop, prod_mobile]]))

        data.update({'products': [prod_desktop.id],
                     'form': 'doc'})
        self.client.post(reverse('wiki.edit_document', args=[data['slug']]),
                         data)
        eq_(sorted(Document.uncached.get(slug=d.slug).products.values_list(
                    'id', flat=True)),
            sorted([prod.id for prod in [prod_desktop]]))
Beispiel #38
0
    def test_review_tags(self, get_current):
        get_current.return_value.domain = 'su.mo.com'
        """Review tags can be managed on document revisions"""
        client = LocalizingClient()
        client.login(username='******', password='******')

        # Create a new doc with one review tag
        data = new_document_data()
        data.update({'review_tags': ['technical']})
        response = client.post(reverse('wiki.new_document'), data)

        # Ensure there's now a doc with that expected tag in its newest
        # revision
        doc = Document.objects.get(slug="a-test-article")
        rev = doc.revisions.order_by('-id').all()[0]
        review_tags = [x.name for x in rev.review_tags.all()]
        eq_(['technical'], review_tags)

        # Now, post an update with two tags
        data.update({
            'form': 'rev',
            'review_tags': ['editorial', 'technical'],
        })
        response = client.post(reverse('wiki.edit_document', args=[doc.slug]),
                               data)

        # Ensure the doc's newest revision has both tags.
        doc = Document.objects.get(slug="a-test-article")
        rev = doc.revisions.order_by('-id').all()[0]
        review_tags = [x.name for x in rev.review_tags.all()]
        review_tags.sort()
        eq_(['editorial', 'technical'], review_tags)

        # Now, ensure that warning boxes appear for the review tags.
        response = client.get(reverse('wiki.document', args=[doc.slug]), data)
        page = pq(response.content)
        eq_(1, page.find('.warning.review-technical').length)
        eq_(1, page.find('.warning.review-editorial').length)

        # Ensure the page appears on the listing pages
        response = client.get(reverse('wiki.list_review'))
        eq_(
            1,
            pq(response.content).find("ul.documents li a:contains('%s')" %
                                      doc.title).length)
        response = client.get(
            reverse('wiki.list_review_tag', args=('technical', )))
        eq_(
            1,
            pq(response.content).find("ul.documents li a:contains('%s')" %
                                      doc.title).length)
        response = client.get(
            reverse('wiki.list_review_tag', args=('editorial', )))
        eq_(
            1,
            pq(response.content).find("ul.documents li a:contains('%s')" %
                                      doc.title).length)

        # Also, ensure that the page appears in the proper feeds
        # HACK: Too lazy to parse the XML. Lazy lazy.
        response = client.get(
            reverse('wiki.feeds.list_review', args=('atom', )))
        ok_('<entry><title>%s</title>' % doc.title in response.content)
        response = client.get(
            reverse('wiki.feeds.list_review_tag', args=(
                'atom',
                'technical',
            )))
        ok_('<entry><title>%s</title>' % doc.title in response.content)
        response = client.get(
            reverse('wiki.feeds.list_review_tag', args=(
                'atom',
                'editorial',
            )))
        ok_('<entry><title>%s</title>' % doc.title in response.content)

        # Post an edit that removes one of the tags.
        data.update({
            'form': 'rev',
            'review_tags': [
                'editorial',
            ],
        })
        response = client.post(reverse('wiki.edit_document', args=[doc.slug]),
                               data)

        # Ensure only one of the tags' warning boxes appears, now.
        response = client.get(reverse('wiki.document', args=[doc.slug]), data)
        page = pq(response.content)
        eq_(0, page.find('.warning.review-technical').length)
        eq_(1, page.find('.warning.review-editorial').length)

        # Ensure the page appears on the listing pages
        response = client.get(reverse('wiki.list_review'))
        eq_(
            1,
            pq(response.content).find("ul.documents li a:contains('%s')" %
                                      doc.title).length)
        response = client.get(
            reverse('wiki.list_review_tag', args=('technical', )))
        eq_(
            0,
            pq(response.content).find("ul.documents li a:contains('%s')" %
                                      doc.title).length)
        response = client.get(
            reverse('wiki.list_review_tag', args=('editorial', )))
        eq_(
            1,
            pq(response.content).find("ul.documents li a:contains('%s')" %
                                      doc.title).length)

        # Also, ensure that the page appears in the proper feeds
        # HACK: Too lazy to parse the XML. Lazy lazy.
        response = client.get(
            reverse('wiki.feeds.list_review', args=('atom', )))
        ok_('<entry><title>%s</title>' % doc.title in response.content)
        response = client.get(
            reverse('wiki.feeds.list_review_tag', args=(
                'atom',
                'technical',
            )))
        ok_('<entry><title>%s</title>' % doc.title not in response.content)
        response = client.get(
            reverse('wiki.feeds.list_review_tag', args=(
                'atom',
                'editorial',
            )))
        ok_('<entry><title>%s</title>' % doc.title in response.content)
Beispiel #39
0
    def test_review_tags(self, get_current):
        get_current.return_value.domain = 'su.mo.com'
        """Review tags can be managed on document revisions"""
        client = LocalizingClient()
        client.login(username='******', password='******')

        # Create a new doc with one review tag
        data = new_document_data()
        data.update({'review_tags':['technical']})
        response = client.post(reverse('wiki.new_document'), data)

        # Ensure there's now a doc with that expected tag in its newest
        # revision
        doc = Document.objects.get(slug="a-test-article")
        rev = doc.revisions.order_by('-id').all()[0]
        review_tags = [x.name for x in rev.review_tags.all()]
        eq_(['technical'], review_tags)

        # Now, post an update with two tags
        data.update({
            'form': 'rev',
            'review_tags': ['editorial', 'technical'],
        })
        response = client.post(reverse('wiki.edit_document', args=[doc.slug]), data)

        # Ensure the doc's newest revision has both tags.
        doc = Document.objects.get(slug="a-test-article")
        rev = doc.revisions.order_by('-id').all()[0]
        review_tags = [x.name for x in rev.review_tags.all()]
        review_tags.sort()
        eq_(['editorial', 'technical'], review_tags)
        
        # Now, ensure that warning boxes appear for the review tags.
        response = client.get(reverse('wiki.document', args=[doc.slug]), data)
        page = pq(response.content)
        eq_(1, page.find('.warning.review-technical').length)
        eq_(1, page.find('.warning.review-editorial').length)

        # Ensure the page appears on the listing pages
        response = client.get(reverse('wiki.list_review'))
        eq_(1, pq(response.content).find("ul.documents li a:contains('%s')" %
                                         doc.title).length)
        response = client.get(reverse('wiki.list_review_tag',
                                      args=('technical',)))
        eq_(1, pq(response.content).find("ul.documents li a:contains('%s')" %
                                         doc.title).length)
        response = client.get(reverse('wiki.list_review_tag',
                                      args=('editorial',)))
        eq_(1, pq(response.content).find("ul.documents li a:contains('%s')" %
                                         doc.title).length)
        
        # Also, ensure that the page appears in the proper feeds
        # HACK: Too lazy to parse the XML. Lazy lazy.
        response = client.get(reverse('wiki.feeds.list_review',
                                      args=('atom',)))
        ok_('<entry><title>%s</title>' % doc.title in response.content)
        response = client.get(reverse('wiki.feeds.list_review_tag',
                                      args=('atom', 'technical', )))
        ok_('<entry><title>%s</title>' % doc.title in response.content)
        response = client.get(reverse('wiki.feeds.list_review_tag',
                                      args=('atom', 'editorial', )))
        ok_('<entry><title>%s</title>' % doc.title in response.content)

        # Post an edit that removes one of the tags.
        data.update({
            'form': 'rev',
            'review_tags': ['editorial',],
        })
        response = client.post(reverse('wiki.edit_document', args=[doc.slug]), data)

        # Ensure only one of the tags' warning boxes appears, now.
        response = client.get(reverse('wiki.document', args=[doc.slug]), data)
        page = pq(response.content)
        eq_(0, page.find('.warning.review-technical').length)
        eq_(1, page.find('.warning.review-editorial').length)

        # Ensure the page appears on the listing pages
        response = client.get(reverse('wiki.list_review'))
        eq_(1, pq(response.content).find("ul.documents li a:contains('%s')" %
                                         doc.title).length)
        response = client.get(reverse('wiki.list_review_tag',
                                      args=('technical',)))
        eq_(0, pq(response.content).find("ul.documents li a:contains('%s')" %
                                         doc.title).length)
        response = client.get(reverse('wiki.list_review_tag',
                                      args=('editorial',)))
        eq_(1, pq(response.content).find("ul.documents li a:contains('%s')" %
                                         doc.title).length)

        # Also, ensure that the page appears in the proper feeds
        # HACK: Too lazy to parse the XML. Lazy lazy.
        response = client.get(reverse('wiki.feeds.list_review',
                                      args=('atom',)))
        ok_('<entry><title>%s</title>' % doc.title in response.content)
        response = client.get(reverse('wiki.feeds.list_review_tag',
                                      args=('atom', 'technical', )))
        ok_('<entry><title>%s</title>' % doc.title not in response.content)
        response = client.get(reverse('wiki.feeds.list_review_tag',
                                      args=('atom', 'editorial', )))
        ok_('<entry><title>%s</title>' % doc.title in response.content)