Exemplo n.º 1
0
    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()
Exemplo n.º 2
0
    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()
Exemplo n.º 3
0
    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()
Exemplo n.º 4
0
    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)
Exemplo n.º 5
0
    val = node.childNodes[0].nodeValue
    if val:
        return val


def getValidNode(node):
    if hasattr(node, 'tagName'):
        return node
    return None


if sys.argv[1]:
    for f in glob.glob(path.join(sys.argv[1], "*.xml")):
        ds = open(f)
        dom = parse(ds)
        e = Entry()
        e.markup = 'brk'
        tags = []

        for node in dom.childNodes[0].childNodes:
            if getValidNode(node):
                ignore = ['owner', 'description', 'notifications', 'tags',
                        'categories']

                if not node.tagName in ignore:
                    val = getNodeValue(node)
                    if node.tagName == 'author':
                        owner = User.objects.filter(username=val)[0]
                        if owner:
                            e.owner = owner
                        else:
Exemplo n.º 6
0
    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()
Exemplo n.º 7
0
    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()