Пример #1
0
 def test_args(self):
     with LanguageOverride('en'):
         q = Q(language_code='ja', pk=1)
         obj = Normal.objects.using_translations().get(q)
         self.assertEqual(obj.shared_field, DOUBLE_NORMAL[1]['shared_field'])
         self.assertEqual(obj.translated_field, DOUBLE_NORMAL[1]['translated_field_ja'])
Пример #2
0
 def setUp(self):
     with LanguageOverride("en"):
         self.object = Normal.objects.language().create(
             shared_field="test", translated_field="translated test")
         self.request = self.request_factory.post('/url/')
Пример #3
0
 def test_language(self):
     with LanguageOverride('en'):
         obj = Normal.objects.language('ja').get(pk=self.normal_id[1])
         self.assertEqual(obj.shared_field, NORMAL[1].shared_field)
         self.assertEqual(obj.translated_field,
                          NORMAL[1].translated_field['ja'])
Пример #4
0
 def test_kwargs(self):
     with LanguageOverride('en'):
         kwargs = {'language_code':'ja', 'pk':self.normal_id[1]}
         obj = Normal.objects.language('all').get(**kwargs)
         self.assertEqual(obj.shared_field, NORMAL[1].shared_field)
         self.assertEqual(obj.translated_field, NORMAL[1].translated_field['ja'])
Пример #5
0
 def test_lookup_by_non_existing_field(self):
     en = Normal.objects.language('en').get(pk=1)
     with LanguageOverride('en'):
         self.assertRaises(FieldError,
                           Standard.objects.get,
                           normal__non_existing_field=1)
Пример #6
0
 def test_multi_delete(self):
     with LanguageOverride('en'):
         Normal.objects.language().delete()
         self.assertFalse(Normal.objects.untranslated().exists())
         self.assertFalse(Normal.objects.language().exists())
         self.assertFalse(Normal._meta.translations_model.objects.exists())
Пример #7
0
 def test_args(self):
     with LanguageOverride('en'):
         q = Q(language_code='ja', pk=self.normal_id[1])
         obj = Normal.objects.language('all').get(q)
         self.assertEqual(obj.shared_field, NORMAL[1].shared_field)
         self.assertEqual(obj.translated_field, NORMAL[1].translated_field['ja'])
Пример #8
0
 def test_iter_unique_reply(self):
     # Make sure .all() only returns unique rows
     with LanguageOverride('en'):
         self.assertEqual(len(Normal.objects.all()),
                          len(Normal.objects.untranslated()))
Пример #9
0
    def test_aware_qobject_filter(self):
        from hvad.utils import get_translation_aware_manager
        manager = get_translation_aware_manager(Standard)

        normal_one = Q(normal_field=STANDARD[1].normal_field)
        normal_two = Q(normal_field=STANDARD[2].normal_field)
        shared_one = Q(
            normal__shared_field=NORMAL[STANDARD[1].normal].shared_field)
        translated_one_en = Q(normal__translated_field=NORMAL[
            STANDARD[1].normal].translated_field['en'])
        translated_two_en = Q(normal__translated_field=NORMAL[
            STANDARD[2].normal].translated_field['en'])

        # control group test
        with LanguageOverride('en'):
            qs = manager.filter(shared_one)
            self.assertEqual(qs.count(), 1)
            obj = qs[0]
            self.assertEqual(obj.normal_field, STANDARD[1].normal_field)

            # basic Q object test
            qs = manager.filter(translated_one_en)
            self.assertEqual(qs.count(), 1)
            obj = qs[0]
            self.assertEqual(obj.normal_field, STANDARD[1].normal_field)

            # test various intersection combinations
            # use a spurious Q to test the logic of recursion along the way
            qs = manager.filter(Q(normal_one & shared_one & translated_one_en))
            self.assertEqual(qs.count(), 1)
            obj = qs[0]
            self.assertEqual(obj.normal_field, STANDARD[1].normal_field)

            qs = manager.filter(Q(normal_one & translated_two_en))
            self.assertEqual(qs.count(), 0)
            qs = manager.filter(Q(shared_one & translated_two_en))
            self.assertEqual(qs.count(), 0)
            qs = manager.filter(Q(translated_one_en & translated_two_en))
            self.assertEqual(qs.count(), 0)

            # test various union combinations
            qs = manager.filter(Q(normal_one | translated_one_en))
            self.assertEqual(qs.count(), 2)
            qs = manager.filter(Q(shared_one | translated_one_en))
            self.assertEqual(qs.count(), 2)

            qs = manager.filter(Q(normal_one | translated_two_en))
            self.assertEqual(qs.count(), 3)
            qs = manager.filter(Q(shared_one | translated_two_en))
            self.assertEqual(qs.count(), 3)

            qs = manager.filter(Q(translated_one_en | translated_two_en))
            self.assertEqual(qs.count(), 2)

            # misc more complex combinations
            qs = manager.filter(
                Q(normal_one & (translated_one_en | translated_two_en)))
            self.assertEqual(qs.count(), 1)
            qs = manager.filter(
                Q(normal_two & (translated_one_en | translated_two_en)))
            self.assertEqual(qs.count(), 1)
            qs = manager.filter(shared_one & ~translated_one_en)
            self.assertEqual(qs.count(), 0)
            qs = manager.filter(shared_one & ~translated_two_en)
            self.assertEqual(qs.count(), 1)
Пример #10
0
 def test_bool_caches(self):
     with LanguageOverride('en'):
         qs = Normal.objects.language().filter(pk=self.normal_id[1])
         self.assertTrue(qs)
         self._try_all_cache_using_methods(qs, 1)
Пример #11
0
 def test_pickling_caches(self):
     import pickle
     with LanguageOverride('en'):
         qs = Normal.objects.language().filter(pk=self.normal_id[1])
         pickle.dumps(qs)
         self._try_all_cache_using_methods(qs, 1)
Пример #12
0
 def create_fixtures(self):
     super(SelectRelatedTests, self).create_fixtures()
     with LanguageOverride('en'):
         self.normal1 = Normal.objects.language().get(pk=1)
         SimpleRelated.objects.language().create(normal=self.normal1,
                                                 translated_field="test1")