class TestVersions(WebTest): csrf_checks = False def setUp(self): self.user = UserProfile.objects.create_superuser(username="******", email="*****@*****.**", password="******") self.user.is_verified = True self.user.is_active = True self.user.is_admin = True self.user.save() self.document = Document(title="title", text="text", type='I', author=self.user) with transaction.atomic(), reversion.create_revision(): self.document.save() reversion.set_user(self.user) reversion.set_comment('test version') def test_get_version_page(self): response = self.app.get(reverse('information_pages:versions', args=[self.document.url_title])) self.assertEqual(response.status_code, 302) response = self.app.get(reverse('information_pages:versions', args=[self.document.url_title]), user=self.user) self.assertEqual(response.status_code, 200) def test_save_version(self): # first get all current versions of the document from the database document = Document.objects.get() versions = reversion.get_for_object(document) self.assertEqual(len(versions), 1) # get the editor page and add a new revision response = self.app.get(reverse('information_pages:edit', args=[self.document.url_title]), user=self.user) self.assertEqual(response.status_code, 200) form = response.form new_string = self.document.text + "\nHallo Bibi Blocksberg!!" form.set('text', new_string) form.set('comment', 'hallo Bibi Blocksberg') response = form.submit().follow() self.assertEqual(response.status_code, 200) # check whether number of versions increased versions = reversion.get_for_object(self.document) self.assertEqual(len(versions), 2) # check whether the comment of the version correct self.assertEqual(versions[0].revision.comment, 'hallo Bibi Blocksberg') self.assertEqual(versions[1].revision.comment, 'test version')
def extendMarkdown(self, md, md_globals): md.inlinePatterns.add( 'InternalLinkDocumentsPattern', Document.LinkPattern(Document.DOCUMENT_LINK_REGEX, md), "_begin") md.inlinePatterns.add('InternalLinkPollsPattern', Poll.LinkPattern(Poll.POLLS_LINK_REGEX, md), "_begin")
def setUp(self): self.user = UserProfile.objects.create_superuser(username="******", email="*****@*****.**", password="******") self.user.is_verified = True self.user.is_active = True self.user.is_admin = True self.user.save() self.document = Document(title="title", text="text", type='I', author=self.user) self.document.save()
class TestEditor(WebTest): csrf_checks = False def setUp(self): self.user = UserProfile.objects.create_superuser(username="******", email="*****@*****.**", password="******") self.user.is_verified = True self.user.is_active = True self.user.is_admin = True self.user.save() self.document = Document(title="title", text="text", type='I', author=self.user) self.document.save() def test_get_editor(self): response = self.app.get(reverse('information_pages:edit', args=[self.document.url_title])) self.assertEqual(response.status_code, 302) response = self.app.get(reverse('information_pages:edit', args=[self.document.url_title]), user="******") self.assertEqual(response.status_code, 200) form = response.form self.assertEqual(form.get('title').value, self.document.title) self.assertEqual(form.get('text').value, self.document.text) form.set('comment', 'changed title') form.set('title', 'new-title') form.submit('submit') document = Document.objects.get(url_title='new-title') self.assertEqual(document.url_title, 'new-title') def test_editor_error(self): for string in ['', ' ']: response = self.app.get(reverse('information_pages:edit', args=[self.document.url_title]), user="******") form = response.form form.set('title', string) response = form.submit('submit') self.assertEqual(response.status_code, 200) self.assertIn('has-error', str(response.body))
def setUp(self): self.user = UserProfile.objects.create_superuser('test', 'test', '*****@*****.**', 'test', 'test') self.user.is_active = True self.user.is_verified = True self.user.is_admin = True self.user.save() document = Document(title="title", text="text", type='I', author=self.user) with transaction.atomic(), reversion.create_revision(): document.save() reversion.set_user(self.user) reversion.set_comment('test version') # create a second version document.text += '\nmore text' with transaction.atomic(), reversion.create_revision(): document.save() reversion.set_user(self.user) reversion.set_comment('added more text')
def slugify_callback(sender, instance, *args, **kwargs): """ creates a slugified title that can be used as URL to the Document This will be used to identify a document that a user wants to see. In case someone creates a document with the same title it is not not defined which document might show up. So please try to avoid that ;) """ if sender not in Document.__subclasses__(): return instance.url_title = slugify(instance.title)
def setUp(self): self.user = UserProfile.objects.create_superuser(username="******", email="*****@*****.**", password="******") self.user.is_verified = True self.user.is_active = True self.user.is_admin = True self.user.save() self.document = Document(title="title", text="text", type='I', author=self.user) with transaction.atomic(), reversion.create_revision(): self.document.save() reversion.set_user(self.user) reversion.set_comment('test version')
def permission_callback(sender, instance, created, *args, **kwargs): """ callback that assigns default permissions to the saved object """ if sender not in Document.__subclasses__() or not created: return permissions = get_perms_for_model(instance) groups = Group.objects.all() for group in groups: for permission in group.permissions.all(): if permission in permissions: assign_perm(permission.codename, group, instance)
def test_slugification(self): document = Document(title="titlea", text="text", type='I', author=self.user) self.assertEqual(document.url_title, '') document.save() self.assertEqual(document.url_title, "titlea") document.title="bla-keks-kekskeks" document.save() self.assertEqual(document.url_title, "bla-keks-kekskeks")
def pre_save_document(sender, instance, *args, **kwargs): """ creates a slugified title that can be used as URL to the Document This will be used to identify a document that a user wants to see. In case someone creates a document with the same title it is not not defined which document might show up. So please try to avoid that ;) """ if sender not in Document.__subclasses__(): return # get the max_length of a slug field as we need to make sure it is no longer than that # as slugify is not doing that for us for field in Document._meta.fields: if field.verbose_name == 'url_title' and instance.url_title == "": instance.url_title = slugify(instance.title)[:field.max_length] return
def pre_save_document(sender, instance, *args, **kwargs): """ creates a slugified title that can be used as URL to the Document This will be used to identify a document that a user wants to see. In case someone creates a document with the same title it is not not defined which document might show up. So please try to avoid that ;) """ if sender not in Document.__subclasses__(): return # get the max_length of a slug field as we need to make sure it is no longer than that # as slugify is not doing that for us for field in Document._meta.fields: if isinstance(field, SlugField) and instance.url_title == "": instance.url_title = slugify(instance.title)[:field.max_length] return
def extendMarkdown(self, md): md.inlinePatterns.register( Document.LinkPattern(Document.DOCUMENT_LINK_REGEX, md), 'InternalLinkDocumentsPattern', 200) md.inlinePatterns.register(Poll.LinkPattern(Poll.POLLS_LINK_REGEX, md), 'InternalLinkPollsPattern', 200)