Ejemplo n.º 1
0
    def test_get(self):
        concept_id = 1
        key = cache.id_key % concept_id
        self.assertFalse(djcache.has_key(key))

        concept = cache.get(concept_id)
        self.assertNotEqual(concept, None)
        self.assertEqual(djcache.get(key), concept)

        djcache.delete(key)

        queryset = Field.objects.none()
        concept = cache.get(concept_id, queryset=queryset)
        self.assertEqual(concept, None)
        self.assertFalse(djcache.has_key(key))
Ejemplo n.º 2
0
    def test_default(self):
        t = DefaultTranslator()
        c = cache.get(1)

        q, a = t(c, 'iexact', 'foo')

        self.assertEqual(str(q), str(Q(name__iexact=u'foo')))
Ejemplo n.º 3
0
    def _get_field(self, field_id=None, app_name=None, model_name=None, field_name=None):
        if field_id or (app_name and model_name):
            return cache.get(field_id=field_id, app_name=app_name, model_name=model_name,
                field_name=field_name)

        # non-optimized lookup that can result in multiple objects returned
        try:
            return Field.objects.get(field_name=field_name)
        except Field.MultipleObjectsReturned:
            raise AmbiguousField, 'Ambiguous field "%s"'