def test_entry_unicode(self): entry = Entry(owner=self.user2, title='foo', content='bar') entry.save() self.assertEqual(u'foo', str(entry)) # clean up the objecs so haystack doesn't have indexes laying around entry.delete()
def test_entry_get_html_content(self): """ Tests the get_html_content method used in the admin template to link to the entry to preview """ entry = Entry(owner=self.user2, title='foo', content='bar') entry.save() content = entry.get_html_content() # We don't care what the HTML looks like, just that it contains a link # to the entry self.assertTrue(content.find(entry.get_absolute_url()) > 0) self.assertTrue(hasattr(entry.get_html_content, 'allow_tags')) # clean up the objecs so haystack doesn't have indexes laying around entry.delete()
def test_search_only_returns_active(self): """ This verifies that only active entries return in the results, unless the user is_staff=True """ self.client = Client() # We are using db instead of mocking so that the haystack indexes # are created entry1 = Entry(owner=self.staff_user, title='Python and Django', draft=True, markup=None, tags='python, django') entry2 = Entry(owner=self.user2, title='Django', draft=False, markup=None, tags='python, django') entry1.save() entry2.save() self.client.login(username=self.user2.username, password='******') response = self.client.post('/search/?q=python') self.assertTrue(len(response.context['results']), 1)
def setUp(self): self.user = User.objects.create(username='******') self.user.save() entry1 = Entry(owner=self.user, title='Python and Django', draft=True, tags='python, django', markup=None) entry2 = Entry(owner=self.user, title='Django', draft=False, tags='python, django', content='foo bar\nbaz', markup='LinebreaksFormatter') entry1.save() entry2.save() entry1.sites = entry2.sites = Site.objects.all() entry1.save() entry2.save()
def test_featured_entry_is_first(self): """ Featured entries should always be at the beginning of the list """ entry1 = Entry(owner=self.user2, title='foo1', content='bar', draft=False) entry1.save() entry2 = Entry(owner=self.user2, title='foo2', content='bar', featured=True, draft=False) entry2.save() entry3 = Entry(owner=self.user2, title='foo3', content='bar', draft=False) entry3.save() self.assertEqual(entry2, Entry.objects.all()[0]) # clean up the objecs so haystack doesn't have indexes laying around entry1.delete() entry2.delete() entry3.delete()
val = getNodeValue(node) if node.tagName == 'author': owner = User.objects.filter(username=val)[0] if owner: e.owner = owner else: e.owner = User.objects.filter(pk=1)[0] elif hasattr(e, node.tagName): setattr(e, node.tagName, val) else: if node.tagName == 'lastModified': e.modified_on = val elif node.tagName == 'ispublished': e.draft = not val elif node.tagName == 'pubDate': e.published_on = val elif node.tagName == 'iscommentsenabled': e.allow_comments = val elif node.tagName == 'tags': for node2 in node.childNodes: if getValidNode(node2): if node2.tagName == 'tag': val = getNodeValue(node2) if val: tags.append(val) e.save() e.sites = Site.objects.filter(pk=1) e.tags = ",".join(tags) e.save()
def test_get_related(self): entry1 = Entry(owner=self.user2, title='foo1', content='bar', draft=False, tags='python, django') entry1.save() entry1.sites = Site.objects.all() entry1.save() entry2 = Entry(owner=self.user2, title='foo2', content='bar', featured=True, draft=False, tags='python, django') entry2.save() entry2.sites = Site.objects.all() entry2.save() entry3 = Entry(owner=self.user2, title='foo3', content='bar', draft=False, tags='python, django') entry3.save() entry3.sites = Site.objects.all() entry3.save() self.assertEqual(len(entry3.get_related()), 2) entry4 = Entry(owner=self.user2, title='foo3', content='bar', draft=False) entry4.save() entry4.sites = Site.objects.all() entry4.related_content.add(entry1) entry4.related_content.add(entry2) entry4.save() self.assertEqual(len(entry4.get_related(max=3)), 2) self.assertEqual(len(entry4.get_related(max=1)), 1) # clean up the objecs so haystack doesn't have indexes laying around entry1.delete() entry2.delete() entry3.delete() entry4.delete()