def test_is_current_with_single_version(self): user = UserFactory() node = NodeFactory() page = WikiPage(page_name='foo', node=node) page.save() version = page.create_version(user=user, content='hello') assert version.is_current is True
def test_is_current_with_multiple_versions(self): user = UserFactory() node = NodeFactory() page = WikiPage(page_name='foo', node=node) page.save() ver1 = page.create_version(user=user, content='draft1') ver2 = page.create_version(user=user, content='draft2') assert ver1.is_current is False assert ver2.is_current is True
def reverse_func(state, schema): """ Reverses NodeWikiPage migration. Repoints guids back to each NodeWikiPage, repoints comment_targets, comments_viewed_timestamps, and deletes all WikiVersions and WikiPages """ nwp_content_type_id = ContentType.objects.get_for_model(NodeWikiPage).id nodes = AbstractNode.objects.exclude(wiki_pages_versions={}) progress_bar = progressbar.ProgressBar(maxval=nodes.count() or 100).start() for i, node in enumerate(nodes, 1): progress_bar.update(i) for wiki_key, version_list in node.wiki_pages_versions.iteritems(): if version_list: for index, version in enumerate(version_list): nwp = NodeWikiPage.objects.filter(former_guid=version).include(None)[0] # All NodeWikiPages associated with a certain wiki key on a node point to the same WikiPage. wp = WikiPage.load(version) guid = migrate_guid_referent(Guid.load(version), nwp, nwp_content_type_id) guid.save() nwp = guid.referent # Moved only for last item in wiki_pages_versions array for every page_name, NWP->WP is a many-to-one mapping. NWP->WV is a one-to-one mapping. move_comment_target(Guid.load(wp._id), nwp) update_comments_viewed_timestamp(node, wp._id, nwp) progress_bar.finish() WikiVersion.objects.all().delete() WikiPage.objects.all().delete() logger.info('NodeWikiPages restored and WikiVersions and WikiPages removed.')
def test_is_current_deleted_page(self): user = UserFactory() node = NodeFactory() page = WikiPage(page_name='foo', node=node) page.save() ver1 = page.create_version(user=user, content='draft1') page.deleted = datetime.datetime(2017, 1, 1, 1, 00, tzinfo=pytz.utc) page.save() assert ver1.is_current is False
def get_wiki(self, check_permissions=True): pk = self.kwargs[self.wiki_lookup_url_kwarg] wiki = WikiPage.load(pk) if not wiki: raise NotFound if wiki.node.addons_wiki_node_settings.deleted: raise NotFound(detail='The wiki for this node has been disabled.') if wiki.deleted: raise Gone(detail='The wiki for this node has been deleted.') if wiki.node.is_registration and self.request.method not in drf_permissions.SAFE_METHODS: raise MethodNotAllowed(method=self.request.method) if check_permissions: # May raise a permission denied self.check_object_permissions(self.request, wiki) return wiki
def get_wiki(self, check_permissions=True): pk = self.kwargs[self.wiki_lookup_url_kwarg] wiki = WikiPage.load(pk) if not wiki: raise NotFound if wiki.node.addons_wiki_node_settings.deleted: raise NotFound(detail='The wiki for this node has been disabled.') if wiki.deleted: raise Gone(detail='The wiki for this node has been deleted.') if wiki.node.is_registration and self.request.method not in drf_permissions.SAFE_METHODS: raise MethodNotAllowed(method=self.request.method) if check_permissions: # May raise a permission denied self.check_object_permissions(self.request, wiki) return wiki
def test_page_name_cannot_be_greater_than_100_characters(self): bad_name = 'a' * 101 page = WikiPage(page_name=bad_name) with pytest.raises(NameMaximumLengthError): page.save()