def test_slug_3_chars(self): """Make sure we can create a slug with only 3 characters.""" self.client.login(username="******", password="******") data = new_document_data() data["slug"] = "ask" response = self.client.post(reverse("wiki.new_document"), data) eq_(302, response.status_code) eq_("ask", Document.objects.all()[0].slug)
def test_title_no_collision(self): """Only slugs and not titles are required to be unique per locale now, so test that we actually allow that.""" d = _create_document() self.client.login(username="******", password="******") data = new_document_data() data["slug"] = "%s-once-more-with-feeling" % d.slug response = self.client.post(reverse("wiki.new_document"), data) eq_(302, response.status_code)
def test_change_title_case(self): """Changing the case of some letters in the title should work.""" data = new_document_data() new_title = "TeST DoCuMent" data.update(title=new_title) data.update(form="doc") response = post(self.client, "wiki.edit_document", data, args=[self.d.full_path]) eq_(200, response.status_code) doc = Document.objects.get(pk=self.d.pk) eq_(new_title, doc.title)
def test_new_document_POST_invalid_category(self): """Try to create a new document with an invalid category value.""" self.client.login(username="******", password="******") data = new_document_data(["tag1", "tag2"]) data["category"] = 963 response = self.client.post(reverse("wiki.new_document"), data, follow=True) doc = pq(response.content) ul = doc("article > ul.errorlist") eq_(1, len(ul)) assert "Select a valid choice. 963 is not one of the available " "choices." in ul("li").text()
def test_new_document_POST_empty_content(self): """Trigger required field validation for content.""" self.client.login(username="******", password="******") data = new_document_data(["tag1", "tag2"]) data["content"] = "" response = self.client.post(reverse("wiki.new_document"), data, follow=True) doc = pq(response.content) ul = doc("article > ul.errorlist") eq_(1, len(ul)) eq_("Please provide content.", ul("li").text())
def test_slug_collision_validation(self): """Trying to create document with existing locale/slug should show validation error.""" d = _create_document() self.client.login(username="******", password="******") data = new_document_data() data["slug"] = d.slug response = self.client.post(reverse("wiki.new_document"), data) eq_(200, response.status_code) doc = pq(response.content) ul = doc("article > ul.errorlist") eq_(1, len(ul)) eq_("Document with this Slug and Locale already exists.", ul("li").text())
def test_new_document_missing_category(self): """Test the DocumentForm's category validation. Submit the form without a category set, and it should complain, even though it's not a strictly required field (because it cannot be set for translations). """ self.client.login(username="******", password="******") data = new_document_data() del data["category"] response = self.client.post(reverse("wiki.new_document"), data, follow=True) self.assertContains(response, "Please choose a category.")
def test_new_document_other_locale(self, get_current): """Make sure we can create a document in a non-default locale.""" # You shouldn't be able to make a new doc in a non-default locale # without marking it as non-localizable. Unskip this when the non- # localizable bool is implemented. get_current.return_value.domain = "testserver" self.client.login(username="******", password="******") data = new_document_data(["tag1", "tag2"]) locale = "es" self.client.post(reverse("wiki.new_document", locale=locale), data, follow=True) d = Document.objects.get(title=data["title"]) eq_(locale, d.locale)
def test_new_revision_POST_removes_old_tags(self): """Changing the tags on a document removes the old tags from that document.""" self.d.current_revision = None self.d.save() tags = [u"tag1", u"tag2", u"tag3"] self.d.tags.add(*tags) result_tags = list(self.d.tags.values_list("name", flat=True)) result_tags.sort() eq_(tags, result_tags) tags = [u"tag1", u"tag4"] data = new_document_data(tags) data["form"] = "rev" self.client.post(reverse("wiki.edit_document", args=[self.d.full_path]), data) result_tags = list(self.d.tags.values_list("name", flat=True)) result_tags.sort() eq_(tags, result_tags)
def test_new_document_POST(self, get_current): """HTTP POST to new document URL creates the document.""" get_current.return_value.domain = "testserver" self.client.login(username="******", password="******") tags = ["tag1", "tag2"] data = new_document_data(tags) response = self.client.post(reverse("wiki.new_document"), data, follow=True) d = Document.objects.get(title=data["title"]) eq_([("http://testserver/en-US/docs/%s" % d.slug, 302)], response.redirect_chain) eq_(settings.WIKI_DEFAULT_LANGUAGE, d.locale) eq_(data["category"], d.category) eq_(tags, sorted(t.name for t in d.tags.all())) r = d.revisions.all()[0] eq_(data["keywords"], r.keywords) eq_(data["summary"], r.summary) eq_(data["content"], r.content)
def test_can_save_document_with_translations(self): """Make sure we can save a document with translations.""" # Create a translation _create_document(title="Document Prueba", parent=self.d, locale="es") # Make sure is_localizable hidden field is rendered response = get(self.client, "wiki.edit_document", args=[self.d.full_path]) eq_(200, response.status_code) doc = pq(response.content) # is_localizable = doc('input[name="is_localizable"]') # eq_(1, len(is_localizable)) # eq_('True', is_localizable[0].attrib['value']) # And make sure we can update the document data = new_document_data() new_title = "A brand new title" data.update(title=new_title) data.update(form="doc") data.update(is_localizable="True") response = post(self.client, "wiki.edit_document", data, args=[self.d.full_path]) eq_(200, response.status_code) doc = Document.objects.get(pk=self.d.pk) eq_(new_title, doc.title)
def test_new_revision_POST_document_without_current(self, get_current, edited_fire): """HTTP POST to new revision URL creates the revision on a document. The document in this case doesn't have a current_revision, therefore the document fields are open for editing. """ get_current.return_value.domain = "testserver" self.d.current_revision = None self.d.save() tags = ["tag1", "tag2", "tag3"] data = new_document_data(tags) data["form"] = "rev" response = self.client.post(reverse("wiki.edit_document", args=[self.d.full_path]), data) eq_(302, response.status_code) eq_(2, self.d.revisions.count()) new_rev = self.d.revisions.order_by("-id")[0] # There are no approved revisions, so it's based_on nothing: eq_(None, new_rev.based_on) edited_fire.assert_called()