Exemple #1
0
    def testRegisterLinks(self):
        conf = SmartLinkConf(queryset=Event.objects)
        smartlinks_conf = register((('e', 'event'), conf),
                                   (('m', 'movie'), conf))

        self.assertEqual(smartlinks_conf, {
            'e': conf,
            'event': conf,
            'm': conf,
            'movie': conf
        })
Exemple #2
0
    def testDotNotationInSearchedFields(self):
        dot_conf = SmartLinkConf(Teacher.objects,
                                 searched_fields=('person.name', ))

        p = Person.objects.create(name='Mark')

        t = Teacher.objects.create(position='None', person=p)

        dot_conf.update_index_for_object(Teacher, t, created=True)

        self.assertEqual(dot_conf.find_object('mark'), t)
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 setUp(self):
        self.ae = self.assertEqual

        self.m = Movie.objects.create(title="Mad Max",
                                      slug="mad-max",
                                      year=1984)

        self.secret_movie = Movie.objects.create(title="Secret Movie",
                                                 slug='secret-movie',
                                                 public=False,
                                                 year=2000)

        self.harry1 = Movie.objects.create(title="Dirty Harry",
                                           slug="dirty-harry",
                                           year=1971)

        self.harry2 = Movie.objects.create(title="Dirty Harry",
                                           slug='dirty-harry',
                                           year=1976)

        self.movie_conf = SmartLinkConf(Movie.objects,
                                        searched_fields=('title', 'slug', (
                                            'title',
                                            'year',
                                        ), '__unicode__', 'pk'))

        self.movie_conf.update_index_for_object(Movie, self.m, created=True)

        self.movie_conf.update_index_for_object(Movie,
                                                self.harry1,
                                                created=True)

        self.movie_conf.update_index_for_object(Movie,
                                                self.harry2,
                                                created=True)

        self.movie_conf.update_index_for_object(Movie,
                                                self.secret_movie,
                                                created=True)
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 ]]')