コード例 #1
0
ファイル: test_models.py プロジェクト: aldryn/aldryn-faq
    def test_get_absolute_url_pk_slug(self):
        question_1 = self.question1
        category_1 = self.category1

        old = self.app_config.permalink_type
        self.app_config.permalink_type = "Ps"
        self.app_config.save()

        with force_language('en'):
            question_1_url_en = reverse(
                'aldryn_faq:faq-answer',
                kwargs={
                    'category_pk': category_1.pk,
                    'slug': get_slug_in_language(question_1, 'en'),
                }
            )

        with force_language('de'):
            question_1_url_de = reverse(
                'aldryn_faq:faq-answer',
                kwargs={
                    'category_pk': category_1.pk,
                    'slug': get_slug_in_language(question_1, 'de'),
                }
            )

        self.assertEqual(question_1.get_absolute_url("en"), question_1_url_en)
        self.assertEqual(question_1.get_absolute_url("de"), question_1_url_de)

        self.app_config.permalink_type = old
        self.app_config.save()
コード例 #2
0
ファイル: test_models.py プロジェクト: zwjwhxz/aldryn-faq
    def test_get_absolute_url_pk_slug(self):
        question_1 = self.question1
        category_1 = self.category1

        old = self.app_config.permalink_type
        self.app_config.permalink_type = "Ps"
        self.app_config.save()

        with force_language('en'):
            question_1_url_en = reverse('aldryn_faq:faq-answer',
                                        kwargs={
                                            'category_pk':
                                            category_1.pk,
                                            'slug':
                                            get_slug_in_language(
                                                question_1, 'en'),
                                        })

        with force_language('de'):
            question_1_url_de = reverse('aldryn_faq:faq-answer',
                                        kwargs={
                                            'category_pk':
                                            category_1.pk,
                                            'slug':
                                            get_slug_in_language(
                                                question_1, 'de'),
                                        })

        self.assertEqual(question_1.get_absolute_url("en"), question_1_url_en)
        self.assertEqual(question_1.get_absolute_url("de"), question_1_url_de)

        self.app_config.permalink_type = old
        self.app_config.save()
コード例 #3
0
ファイル: test_models.py プロジェクト: aldryn/aldryn-faq
    def test_get_absolute_url(self):
        category = self.question1.category

        with force_language('en'):
            question_1_url_en = reverse(
                'aldryn_faq:faq-answer',
                kwargs={
                    'category_pk': category.pk,
                    'pk': self.question1.pk,
                    'category_slug': get_slug_in_language(category, 'en'),
                }
            )

        with force_language('de'):
            question_1_url_de = reverse(
                'aldryn_faq:faq-answer',
                kwargs={
                    'category_pk': category.pk,
                    'pk': self.question1.pk,
                    'category_slug': get_slug_in_language(category, 'de'),
                }
            )

        self.assertEqual(self.question1.get_absolute_url("en"), question_1_url_en)
        self.assertEqual(self.question1.get_absolute_url("de"), question_1_url_de)
コード例 #4
0
    def test_get_absolute_url_slug_pk(self):
        question_1 = self.question1
        category_1 = self.category1

        old = self.app_config.permalink_type
        self.app_config.permalink_type = "Sp"
        self.app_config.save()

        self.assertEqual(
            question_1.get_absolute_url("en"),
            "/en/faq/{category_slug}/{pk}/".format(
                category_slug=get_slug_in_language(category_1, "en"),
                pk=question_1.pk
            )
        )
        self.assertEqual(
            question_1.get_absolute_url("de"),
            "/de/faq/{category_slug}/{pk}/".format(
                category_slug=get_slug_in_language(category_1, "de"),
                pk=question_1.pk
            )
        )

        self.app_config.permalink_type = old
        self.app_config.save()
コード例 #5
0
ファイル: test_models.py プロジェクト: zwjwhxz/aldryn-faq
    def test_get_absolute_url(self):
        category = self.question1.category

        with force_language('en'):
            question_1_url_en = reverse('aldryn_faq:faq-answer',
                                        kwargs={
                                            'category_pk':
                                            category.pk,
                                            'pk':
                                            self.question1.pk,
                                            'category_slug':
                                            get_slug_in_language(
                                                category, 'en'),
                                        })

        with force_language('de'):
            question_1_url_de = reverse('aldryn_faq:faq-answer',
                                        kwargs={
                                            'category_pk':
                                            category.pk,
                                            'pk':
                                            self.question1.pk,
                                            'category_slug':
                                            get_slug_in_language(
                                                category, 'de'),
                                        })

        self.assertEqual(self.question1.get_absolute_url("en"),
                         question_1_url_en)
        self.assertEqual(self.question1.get_absolute_url("de"),
                         question_1_url_de)
コード例 #6
0
ファイル: test_models.py プロジェクト: zwjwhxz/aldryn-faq
 def test_get_slug_in_language(self):
     self.assertIsNone(get_slug_in_language(None, 'en'), None)
     self.assertIsNone(get_slug_in_language(object, 'en'), None)
     self.assertEqual(get_slug_in_language(self.category1, 'en'),
                      self.data["category1"]["en"]["slug"])
     self.assertEqual(get_slug_in_language(self.category1, 'de'),
                      self.data["category1"]["de"]["slug"])
コード例 #7
0
    def test_question_urls(self):
        question_1 = self.question1
        category_1 = question_1.category

        question_2 = self.question2
        category_2 = question_2.category

        with override('en'):
            question_1_url_en = reverse('aldryn_faq:faq-answer',
                                        kwargs={
                                            'category_pk':
                                            category_1.pk,
                                            'category_slug':
                                            get_slug_in_language(
                                                category_1, 'en'),
                                            'pk':
                                            question_1.pk,
                                        })

            question_2_url_en = reverse('aldryn_faq:faq-answer',
                                        kwargs={
                                            'category_pk':
                                            category_2.pk,
                                            'category_slug':
                                            get_slug_in_language(
                                                category_2, 'de'),
                                            'pk':
                                            question_2.pk,
                                        })

            self.assertEquals(question_1.get_absolute_url(), question_1_url_en)
            self.assertEquals(question_2.get_absolute_url(), question_2_url_en)

        with override('de'):
            question_1_url_de = reverse('aldryn_faq:faq-answer',
                                        kwargs={
                                            'category_pk':
                                            category_1.pk,
                                            'category_slug':
                                            get_slug_in_language(
                                                category_1, 'de'),
                                            'pk':
                                            question_1.pk,
                                        })

            question_2_url_de = reverse('aldryn_faq:faq-answer',
                                        kwargs={
                                            'category_pk':
                                            category_2.pk,
                                            'category_slug':
                                            get_slug_in_language(
                                                category_2, 'de'),
                                            'pk':
                                            question_2.pk,
                                        })

            self.assertEquals(question_1.get_absolute_url(), question_1_url_de)
            self.assertEquals(question_2.get_absolute_url(), question_2_url_de)
コード例 #8
0
ファイル: test_i18n.py プロジェクト: aldryn/aldryn-faq
    def test_category_urls(self):
        category_1 = self.category1
        category_2 = self.category2

        with override('en'):
            category_1_url_en = reverse(
                'aldryn_faq:faq-category',
                kwargs={
                    'category_pk': category_1.pk,
                    'category_slug': get_slug_in_language(category_1, 'en'),
                }
            )

            category_2_url_fallback_de = reverse(
                'aldryn_faq:faq-category',
                kwargs={
                    'category_pk': category_2.pk,
                    'category_slug': get_slug_in_language(category_2, 'de'),
                }
            )

            self.assertEquals(self.category1.get_absolute_url(), category_1_url_en)
            # category2 doesn't exist EN, so this should fallback to DE
            self.assertEquals(self.category2.get_absolute_url(), category_2_url_fallback_de)

        with override('de'):
            category_1_url_de = reverse(
                'aldryn_faq:faq-category',
                kwargs={
                    'category_pk': category_1.pk,
                    'category_slug': get_slug_in_language(category_1, 'de'),
                }
            )

            category_2_url_de = reverse(
                'aldryn_faq:faq-category',
                kwargs={
                    'category_pk': category_2.pk,
                    'category_slug': get_slug_in_language(category_2, 'de'),
                }
            )

            self.assertEquals(self.category1.get_absolute_url(), category_1_url_de)
            self.assertEquals(self.category2.get_absolute_url(), category_2_url_de)

        # test that we can override the context with the language parameter
        with override('en'):
            self.assertEquals(self.category1.get_absolute_url(language='de'), category_1_url_de)
            self.assertEquals(self.category2.get_absolute_url(language='de'), category_2_url_de)

        # For completeness, do the other way too
        with override('de'):
            self.assertEquals(self.category1.get_absolute_url(language='en'), category_1_url_en)
            # category2 doesn't exist EN, so this should fallback to DE
            self.assertEquals(self.category2.get_absolute_url(language='en'), category_2_url_fallback_de)
コード例 #9
0
ファイル: test_models.py プロジェクト: czpython/aldryn-faq
 def test_get_slug_in_language(self):
     self.assertIsNone(get_slug_in_language(None, 'en'), None)
     self.assertIsNone(get_slug_in_language(object, 'en'), None)
     self.assertEqual(
         get_slug_in_language(self.category1, 'en'),
         self.data["category1"]["en"]["slug"]
     )
     self.assertEqual(
         get_slug_in_language(self.category1, 'de'),
         self.data["category1"]["de"]["slug"]
     )
コード例 #10
0
ファイル: test_i18n.py プロジェクト: aldryn/aldryn-faq
    def test_question_urls(self):
        question_1 = self.question1
        category_1 = question_1.category

        question_2 = self.question2
        category_2 = question_2.category

        with override('en'):
            question_1_url_en = reverse(
                'aldryn_faq:faq-answer',
                kwargs={
                    'category_pk': category_1.pk,
                    'category_slug': get_slug_in_language(category_1, 'en'),
                    'pk': question_1.pk,
                }
            )

            question_2_url_en = reverse(
                'aldryn_faq:faq-answer',
                kwargs={
                    'category_pk': category_2.pk,
                    'category_slug': get_slug_in_language(category_2, 'de'),
                    'pk': question_2.pk,
                }
            )

            self.assertEquals(question_1.get_absolute_url(), question_1_url_en)
            self.assertEquals(question_2.get_absolute_url(), question_2_url_en)

        with override('de'):
            question_1_url_de = reverse(
                'aldryn_faq:faq-answer',
                kwargs={
                    'category_pk': category_1.pk,
                    'category_slug': get_slug_in_language(category_1, 'de'),
                    'pk': question_1.pk,
                }
            )

            question_2_url_de = reverse(
                'aldryn_faq:faq-answer',
                kwargs={
                    'category_pk': category_2.pk,
                    'category_slug': get_slug_in_language(category_2, 'de'),
                    'pk': question_2.pk,
                }
            )

            self.assertEquals(question_1.get_absolute_url(), question_1_url_de)
            self.assertEquals(question_2.get_absolute_url(), question_2_url_de)
コード例 #11
0
    def test_question_urls_fallbacks(self):
        question_1 = self.question1
        category_1 = question_1.category

        question_2 = self.question2
        category_2 = question_2.category

        with force_language('en'):
            question_2_url_fallback_de = reverse('aldryn_faq:faq-answer',
                                                 kwargs={
                                                     'category_pk':
                                                     category_2.pk,
                                                     'category_slug':
                                                     get_slug_in_language(
                                                         category_2, 'de'),
                                                     'pk':
                                                     question_2.pk,
                                                 })

        with force_language('fr'):
            question_1_url_fallback_fr = reverse('aldryn_faq:faq-answer',
                                                 kwargs={
                                                     'category_pk':
                                                     category_1.pk,
                                                     'category_slug':
                                                     get_slug_in_language(
                                                         category_1, 'en'),
                                                     'pk':
                                                     question_1.pk,
                                                 })

        # question 2 is not translated in english
        # so given our test fallback config
        # this should fallback to the german category
        self.assertEqual(self.question2.get_absolute_url("en"),
                         question_2_url_fallback_de)

        # question 1 is not translated in french
        # so given our test fallback config
        # this should fallback to the english category
        self.assertEqual(self.question1.get_absolute_url("fr"),
                         question_1_url_fallback_fr)

        with self.assertRaises(NoReverseMatch):
            # this should raise a NoRerverseMatch error
            # because category 2 is not translated in french
            # so it falls back to english which also does not exist
            question_2.get_absolute_url("fr")
コード例 #12
0
ファイル: test_i18n.py プロジェクト: aldryn/aldryn-faq
    def test_question_urls_fallbacks(self):
        question_1 = self.question1
        category_1 = question_1.category

        question_2 = self.question2
        category_2 = question_2.category

        with force_language('en'):
            question_2_url_fallback_de = reverse(
                'aldryn_faq:faq-answer',
                kwargs={
                    'category_pk': category_2.pk,
                    'category_slug': get_slug_in_language(category_2, 'de'),
                    'pk': question_2.pk,
                }
            )

        with force_language('fr'):
            question_1_url_fallback_fr = reverse(
                'aldryn_faq:faq-answer',
                kwargs={
                    'category_pk': category_1.pk,
                    'category_slug': get_slug_in_language(category_1, 'en'),
                    'pk': question_1.pk,
                }
            )

        # question 2 is not translated in english
        # so given our test fallback config
        # this should fallback to the german category
        self.assertEqual(self.question2.get_absolute_url("en"), question_2_url_fallback_de)

        # question 1 is not translated in french
        # so given our test fallback config
        # this should fallback to the english category
        self.assertEqual(self.question1.get_absolute_url("fr"), question_1_url_fallback_fr)

        with self.assertRaises(NoReverseMatch):
            # this should raise a NoRerverseMatch error
            # because category 2 is not translated in french
            # so it falls back to english which also does not exist
            question_2.get_absolute_url("fr")
コード例 #13
0
    def test_category_urls(self):
        category_1 = self.category1
        category_2 = self.category2

        with override('en'):
            category_1_url_en = reverse('aldryn_faq:faq-category',
                                        kwargs={
                                            'category_pk':
                                            category_1.pk,
                                            'category_slug':
                                            get_slug_in_language(
                                                category_1, 'en'),
                                        })

            category_2_url_fallback_de = reverse('aldryn_faq:faq-category',
                                                 kwargs={
                                                     'category_pk':
                                                     category_2.pk,
                                                     'category_slug':
                                                     get_slug_in_language(
                                                         category_2, 'de'),
                                                 })

            self.assertEquals(self.category1.get_absolute_url(),
                              category_1_url_en)
            # category2 doesn't exist EN, so this should fallback to DE
            self.assertEquals(self.category2.get_absolute_url(),
                              category_2_url_fallback_de)

        with override('de'):
            category_1_url_de = reverse('aldryn_faq:faq-category',
                                        kwargs={
                                            'category_pk':
                                            category_1.pk,
                                            'category_slug':
                                            get_slug_in_language(
                                                category_1, 'de'),
                                        })

            category_2_url_de = reverse('aldryn_faq:faq-category',
                                        kwargs={
                                            'category_pk':
                                            category_2.pk,
                                            'category_slug':
                                            get_slug_in_language(
                                                category_2, 'de'),
                                        })

            self.assertEquals(self.category1.get_absolute_url(),
                              category_1_url_de)
            self.assertEquals(self.category2.get_absolute_url(),
                              category_2_url_de)

        # test that we can override the context with the language parameter
        with override('en'):
            self.assertEquals(self.category1.get_absolute_url(language='de'),
                              category_1_url_de)
            self.assertEquals(self.category2.get_absolute_url(language='de'),
                              category_2_url_de)

        # For completeness, do the other way too
        with override('de'):
            self.assertEquals(self.category1.get_absolute_url(language='en'),
                              category_1_url_en)
            # category2 doesn't exist EN, so this should fallback to DE
            self.assertEquals(self.category2.get_absolute_url(language='en'),
                              category_2_url_fallback_de)