def testIndexRecreation(self):
        register_smart_link(('m', 'movie'), SmartLinkConf(
            Movie.objects,
            searched_fields=('title',)
            )
        )

        self.m1 = Movie.objects.create(
            title="Mad Max",
            slug="mad-max",
            year="1986"
        )
        self.m2 = Movie.objects.create(
            title="Once upon a time in the West",
            slug="once",
            year="1990"
        )

        # Now let's tinker with the smartlink index and see whether it would
        # be able to restore itself to the initial state.
        IndexEntry.objects.all().delete()

        IndexEntry.objects.create(
            value="bogus",
            content_type=ContentType.objects.all()[0],
            object_id=200
        )

        IndexEntry.objects.create(
            value="bogus2",
            content_type=ContentType.objects.all()[0],
            object_id=200
        )

        # ...and see whether it can re-create itself properly.
        call_command('reset_smartlink_index')

        self.assertEqual(IndexEntry.objects.count(),
            2)

        # As only one field is searched, it should create one entry per
        # :py:class:`Movie` object.
        self.assertEqual(IndexEntry.objects.filter(object_id=self.m1.pk).count(),
         1)

        self.assertEqual(IndexEntry.objects.filter(object_id=self.m2.pk).count(),
         1)
Exemple #2
0
    def testRegisterLink(self):
        conf = SmartLinkConf(queryset=Event.objects)

        smartlinks_conf = register_smart_link(
            ('e', 'event'), conf)

        self.assertEqual(smartlinks_conf, {
            'e': conf,
            'event': conf
        })
Exemple #3
0
    def testSanityChecks(self):
        # No such field on the model => exception.
        self.assertRaises(IncorrectlyConfiguredSmartlinkException,
            register_smart_link,
            ('e',),
            SmartLinkConf(Event.objects, searched_fields=('blah',)))

        # Searched field is a function with too many argument => exception.
        self.assertRaises(IncorrectlyConfiguredSmartlinkException,
            register_smart_link,
            ('e'),
            SmartLinkConf(Event.objects, searched_fields=('my_favourite_func')))

        # While registering the callable with no args should work just fine.
        register_smart_link(('zzz',), SmartLinkConf(Event.objects,
                                        searched_fields=('my_func_without_args',)))

        # We also can't register the model with same shortcut twice.
        self.assertRaises(AlreadyRegisteredSmartlinkException,
            register_smart_link,
            ('zzz',), SmartLinkConf(Event.objects))
Exemple #4
0
    def testSanityChecks(self):
        # No such field on the model => exception.
        self.assertRaises(
            IncorrectlyConfiguredSmartlinkException, register_smart_link,
            ('e', ), SmartLinkConf(Event.objects, searched_fields=('blah', )))

        # Searched field is a function with too many argument => exception.
        self.assertRaises(
            IncorrectlyConfiguredSmartlinkException, register_smart_link,
            ('e'),
            SmartLinkConf(Event.objects,
                          searched_fields=('my_favourite_func')))

        # While registering the callable with no args should work just fine.
        register_smart_link(
            ('zzz', ),
            SmartLinkConf(Event.objects,
                          searched_fields=('my_func_without_args', )))

        # We also can't register the model with same shortcut twice.
        self.assertRaises(AlreadyRegisteredSmartlinkException,
                          register_smart_link, ('zzz', ),
                          SmartLinkConf(Event.objects))
Exemple #5
0
    def testIndexRecreation(self):
        register_smart_link(('m', 'movie'),
                            SmartLinkConf(Movie.objects,
                                          searched_fields=('title', )))

        self.m1 = Movie.objects.create(title="Mad Max",
                                       slug="mad-max",
                                       year="1986")
        self.m2 = Movie.objects.create(title="Once upon a time in the West",
                                       slug="once",
                                       year="1990")

        # Now let's tinker with the smartlink index and see whether it would
        # be able to restore itself to the initial state.
        IndexEntry.objects.all().delete()

        IndexEntry.objects.create(value="bogus",
                                  content_type=ContentType.objects.all()[0],
                                  object_id=200)

        IndexEntry.objects.create(value="bogus2",
                                  content_type=ContentType.objects.all()[0],
                                  object_id=200)

        # ...and see whether it can re-create itself properly.
        call_command('reset_smartlink_index')

        self.assertEqual(IndexEntry.objects.count(), 2)

        # As only one field is searched, it should create one entry per
        # :py:class:`Movie` object.
        self.assertEqual(
            IndexEntry.objects.filter(object_id=self.m1.pk).count(), 1)

        self.assertEqual(
            IndexEntry.objects.filter(object_id=self.m2.pk).count(), 1)
Exemple #6
0
    def testRegisterLink(self):
        conf = SmartLinkConf(queryset=Event.objects)

        smartlinks_conf = register_smart_link(('e', 'event'), conf)

        self.assertEqual(smartlinks_conf, {'e': conf, 'event': conf})
Exemple #7
0
    def setUp(self):
        if not 'zzz' in conf.smartlinks_conf:
            register_smart_link(('zzz',), SmartLinkConf(queryset=Movie2.objects,
                searched_fields=('title', 'slug',),))

        self.l = LinkModel(link=u'[[ my awesome Movie2 | Terrible ]]')