コード例 #1
0
ファイル: test_views.py プロジェクト: willkg/kitsune
    def test_new_document_slugs(self, get_current):
        """Slugs cannot contain /. but can be urlencoded"""
        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"] = "%2Atesttest"
        response = self.client.post(reverse("wiki.new_document"), data)
        self.assertContains(response, error)

        data["slug"] = "%20testtest"
        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"))
コード例 #2
0
ファイル: test_views.py プロジェクト: willkg/kitsune
    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.objects.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.objects.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.objects.get(pk=doc.pk)
        assert not doc.needs_change
        eq_("", doc.needs_change_comment)
コード例 #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)
コード例 #4
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]]))
コード例 #5
0
    def test_new_document_slugs(self, get_current):
        """Slugs cannot contain /. but can be urlencoded"""
        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"] = "%2Atesttest"
        response = self.client.post(reverse("wiki.new_document"), data)
        self.assertContains(response, error)

        data["slug"] = "%20testtest"
        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"))
コード例 #6
0
    def test_retitling_template(self):
        d = TemplateDocumentFactory()
        RevisionFactory(document=d)

        old_title = d.title
        new_title = 'Not a template'

        # First try and change the title without also changing the category. It should fail.
        data = new_document_data()
        data.update({
            'title': new_title,
            'category': d.category,
            'slug': d.slug,
            'form': 'doc'
        })
        url = reverse('wiki.edit_document', args=[d.slug])
        res = self.client.post(url, data, follow=True)
        eq_(Document.objects.get(id=d.id).title, old_title)
        # This message gets HTML encoded.
        assert ('Documents in the Template category must have titles that start with '
                '"Template:".'
                in res.content)

        # Now try and change the title while also changing the category.
        data['category'] = CATEGORIES[0][0]
        url = reverse('wiki.edit_document', args=[d.slug])
        self.client.post(url, data, follow=True)
        eq_(Document.objects.get(id=d.id).title, new_title)
コード例 #7
0
    def test_removing_template_category(self):
        d = TemplateDocumentFactory()
        RevisionFactory(document=d)
        eq_(d.category, TEMPLATES_CATEGORY)
        assert d.title.startswith(TEMPLATE_TITLE_PREFIX)

        # First try and change the category without also changing the title. It should fail.
        data = new_document_data()
        data.update({
            'title': d.title,
            'category': CATEGORIES[0][0],
            'slug': d.slug,
            'form': 'doc'
        })
        url = reverse('wiki.edit_document', args=[d.slug])
        res = self.client.post(url, data, follow=True)
        eq_(Document.objects.get(id=d.id).category, TEMPLATES_CATEGORY)
        # This message gets HTML encoded.
        assert ('Documents with titles that start with "Template:" must be in the '
                'templates category.' in res.content)

        # Now try and change the title while also changing the category.
        data['title'] = 'not a template'
        url = reverse('wiki.edit_document', args=[d.slug])
        self.client.post(url, data)
        eq_(Document.objects.get(id=d.id).category, CATEGORIES[0][0])
コード例 #8
0
ファイル: test_views.py プロジェクト: pirateyporat/kitsune
    def test_changing_products(self):
        """Changing products works as expected."""
        r = ApprovedRevisionFactory()
        d = r.document
        prod_desktop = ProductFactory(title=u'desktop')
        prod_mobile = ProductFactory(title=u'mobile')

        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.objects.get(id=d.id).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.objects.get(id=d.id).products.values_list('id',
                                                                   flat=True)),
            sorted([prod.id for prod in [prod_desktop]]))
コード例 #9
0
ファイル: test_views.py プロジェクト: Andisutra80/kitsune
    def test_removing_template_category(self):
        d = TemplateDocumentFactory()
        RevisionFactory(document=d)
        eq_(d.category, TEMPLATES_CATEGORY)
        assert d.title.startswith(TEMPLATE_TITLE_PREFIX)

        # First try and change the category without also changing the title. It should fail.
        data = new_document_data()
        data.update({
            'title': d.title,
            'category': CATEGORIES[0][0],
            'slug': d.slug,
            'form': 'doc'
        })
        url = reverse('wiki.edit_document', args=[d.slug])
        res = self.client.post(url, data, follow=True)
        eq_(Document.objects.get(id=d.id).category, TEMPLATES_CATEGORY)
        # This message gets HTML encoded.
        assert ('Documents with titles that start with "Template:" must be in the '
                'templates category.' in res.content)

        # Now try and change the title while also changing the category.
        data['title'] = 'not a template'
        url = reverse('wiki.edit_document', args=[d.slug])
        self.client.post(url, data)
        eq_(Document.objects.get(id=d.id).category, CATEGORIES[0][0])
コード例 #10
0
ファイル: test_views.py プロジェクト: Andisutra80/kitsune
    def test_changing_products(self):
        """Changing products works as expected."""
        r = ApprovedRevisionFactory()
        d = r.document
        prod_desktop = ProductFactory(title=u'desktop')
        prod_mobile = ProductFactory(title=u'mobile')

        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.objects.get(id=d.id).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.objects.get(id=d.id).products
                   .values_list('id', flat=True)),
            sorted([prod.id for prod in [prod_desktop]]))
コード例 #11
0
    def test_changing_products(self):
        """Changing products works as expected."""
        r = ApprovedRevisionFactory()
        d = r.document
        prod_desktop = ProductFactory(title="desktop")
        prod_mobile = ProductFactory(title="mobile")

        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.objects.get(id=d.id).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.objects.get(id=d.id).products.values_list("id",
                                                                   flat=True)),
            sorted([prod.id for prod in [prod_desktop]]),
        )
コード例 #12
0
    def test_retitling_template(self):
        d = TemplateDocumentFactory()
        RevisionFactory(document=d)

        old_title = d.title
        new_title = "Not a template"

        # First try and change the title without also changing the category. It should fail.
        data = new_document_data()
        data.update({
            "title": new_title,
            "category": d.category,
            "slug": d.slug,
            "form": "doc"
        })
        url = reverse("wiki.edit_document", args=[d.slug])
        res = self.client.post(url, data, follow=True)
        eq_(Document.objects.get(id=d.id).title, old_title)
        # This message gets HTML encoded.
        assert (
            b"Documents in the Template category must have titles that start with "
            b""Template:"." in res.content)

        # Now try and change the title while also changing the category.
        data["category"] = CATEGORIES[0][0]
        url = reverse("wiki.edit_document", args=[d.slug])
        self.client.post(url, data, follow=True)
        eq_(Document.objects.get(id=d.id).title, new_title)
コード例 #13
0
    def test_removing_template_category(self):
        d = TemplateDocumentFactory()
        RevisionFactory(document=d)
        eq_(d.category, TEMPLATES_CATEGORY)
        assert d.title.startswith(TEMPLATE_TITLE_PREFIX)

        # First try and change the category without also changing the title. It should fail.
        data = new_document_data()
        data.update({
            "title": d.title,
            "category": CATEGORIES[0][0],
            "slug": d.slug,
            "form": "doc"
        })
        url = reverse("wiki.edit_document", args=[d.slug])
        res = self.client.post(url, data, follow=True)
        eq_(Document.objects.get(id=d.id).category, TEMPLATES_CATEGORY)
        # This message gets HTML encoded.
        assert (
            b"Documents with titles that start with "Template:" must be in the "
            b"templates category." in res.content)

        # Now try and change the title while also changing the category.
        data["title"] = "not a template"
        url = reverse("wiki.edit_document", args=[d.slug])
        self.client.post(url, data)
        eq_(Document.objects.get(id=d.id).category, CATEGORIES[0][0])
コード例 #14
0
ファイル: test_views.py プロジェクト: Andisutra80/kitsune
    def test_new_document_slugs(self, get_current):
        """Slugs cannot contain /. but can be urlencoded"""
        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'] = '%2Atesttest'
        response = self.client.post(reverse('wiki.new_document'), data)
        self.assertContains(response, error)

        data['slug'] = '%20testtest'
        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'))
コード例 #15
0
ファイル: test_views.py プロジェクト: Andisutra80/kitsune
    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 = RevisionFactory().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.objects.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.objects.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.objects.get(pk=doc.pk)
        assert not doc.needs_change
        eq_('', doc.needs_change_comment)
コード例 #16
0
ファイル: test_views.py プロジェクト: Andisutra80/kitsune
    def test_retitling_template(self):
        d = TemplateDocumentFactory()
        RevisionFactory(document=d)

        old_title = d.title
        new_title = 'Not a template'

        # First try and change the title without also changing the category. It should fail.
        data = new_document_data()
        data.update({
            'title': new_title,
            'category': d.category,
            'slug': d.slug,
            'form': 'doc'
        })
        url = reverse('wiki.edit_document', args=[d.slug])
        res = self.client.post(url, data, follow=True)
        eq_(Document.objects.get(id=d.id).title, old_title)
        # This message gets HTML encoded.
        assert ('Documents in the Template category must have titles that start with '
                '"Template:".'
                in res.content)

        # Now try and change the title while also changing the category.
        data['category'] = CATEGORIES[0][0]
        url = reverse('wiki.edit_document', args=[d.slug])
        self.client.post(url, data, follow=True)
        eq_(Document.objects.get(id=d.id).title, new_title)
コード例 #17
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 = RevisionFactory().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.objects.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.objects.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.objects.get(pk=doc.pk)
        assert not doc.needs_change
        eq_("", doc.needs_change_comment)
コード例 #18
0
    def test_new_document_slugs(self, get_current):
        """Slugs cannot contain /. but can be urlencoded"""
        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'] = '%2Atesttest'
        response = self.client.post(reverse('wiki.new_document'), data)
        self.assertContains(response, error)

        data['slug'] = '%20testtest'
        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'))
コード例 #19
0
 def test_retitling_accent(self):
     d = DocumentFactory(title="Umlaut test")
     RevisionFactory(document=d, is_approved=True)
     new_title = "Ümlaut test"
     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.objects.get(id=d.id).title)
コード例 #20
0
 def test_retitling_accent(self):
     d = document(title='Umlaut test', save=True)
     revision(document=d, is_approved=True, save=True)
     new_title = u'Ümlaut test'
     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)
コード例 #21
0
ファイル: test_views.py プロジェクト: willkg/kitsune
 def test_retitling_accent(self):
     d = document(title="Umlaut test", save=True)
     revision(document=d, is_approved=True, save=True)
     new_title = u"Ümlaut test"
     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.objects.get(slug=d.slug).title)
コード例 #22
0
ファイル: test_views.py プロジェクト: pirateyporat/kitsune
 def test_retitling_accent(self):
     d = DocumentFactory(title='Umlaut test')
     RevisionFactory(document=d, is_approved=True)
     new_title = u'Ümlaut test'
     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.objects.get(id=d.id).title)
コード例 #23
0
ファイル: test_views.py プロジェクト: Andisutra80/kitsune
 def test_retitling_accent(self):
     d = DocumentFactory(title='Umlaut test')
     RevisionFactory(document=d, is_approved=True)
     new_title = u'Ümlaut test'
     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.objects.get(id=d.id).title)
コード例 #24
0
ファイル: test_views.py プロジェクト: Archaeopteryx/kitsune
 def test_retitling_accent(self):
     d = document(title='Umlaut test', save=True)
     revision(document=d, is_approved=True, save=True)
     new_title = u'Ümlaut test'
     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)
コード例 #25
0
ファイル: test_views.py プロジェクト: willkg/kitsune
    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.
        """

        def _login(user):
            self.client.login(username=user.username, password="******")

        def assert_is_locked(r):
            self.assertContains(r, 'id="unlock-button"')

        def assert_not_locked(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)
コード例 #26
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.
        """
        def _login(user):
            self.client.login(username=user.username, password='******')

        def assert_is_locked(r):
            self.assertContains(r, 'id="unlock-button"')

        def assert_not_locked(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)
コード例 #27
0
ファイル: test_views.py プロジェクト: willkg/kitsune
 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.objects.get(slug=d.slug).title)
     assert Document.objects.get(title=old_title).redirect_url()
コード例 #28
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()
コード例 #29
0
ファイル: test_views.py プロジェクト: Andisutra80/kitsune
 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'
     r = ApprovedRevisionFactory()
     d = r.document
     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.objects.get(id=d.id).title)
     assert Document.objects.get(title=old_title).redirect_url()
コード例 #30
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"
     r = ApprovedRevisionFactory()
     d = r.document
     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.objects.get(id=d.id).title)
     assert Document.objects.get(title=old_title).redirect_url()
コード例 #31
0
ファイル: test_views.py プロジェクト: willkg/kitsune
    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.objects.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.objects.get(slug=d.slug).products.values_list("id", flat=True)),
            sorted([prod.id for prod in [prod_desktop]]),
        )
コード例 #32
0
ファイル: test_views.py プロジェクト: GVRV/kitsune
    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]]))