Esempio n. 1
0
    def test_get(self, rf):
        with factory.django.mute_signals(signals.post_save):  # Fake `WAGTAILTRANS_SYNC_TREE` setting
            fr = language.LanguageFactory(is_default=False, code='fr', position=2)

        assert TranslatablePage.objects.filter(language=fr).count() == 0

        request = rf.get('/')

        view = TranslationView()
        view.request = request
        response = view.dispatch(request, instance_id=self.last_page.pk, language_code='fr')

        parent_page_qs = view.get_form().fields['parent_page'].queryset

        assert response.status_code == 200
        assert parent_page_qs.count() == 1
        assert parent_page_qs.model is not TranslatablePage
        assert parent_page_qs.first() == self.pages[0]

        french_root = pages.TranslatablePageFactory.build(language=fr, title="French root")
        self.pages[0].add_child(instance=french_root)

        response = view.dispatch(request, instance_id=self.last_page.pk, language_code='fr')

        parent_page_qs = view.get_form().fields['parent_page'].queryset

        # We have a french page to add our new translated page to
        assert parent_page_qs.count() == 1
        assert parent_page_qs.model is TranslatablePage
        assert parent_page_qs[0].language == fr
        assert parent_page_qs[0] == french_root
Esempio n. 2
0
    def test_post_existing(self, rf):
        """It should fail when adding an existing
        page / language combination.

        """
        request = rf.post('/', {'parent_page': self.last_page.pk})

        assert self.last_page.language.code == 'en'

        with override_settings(WAGTAILTRANS_SYNC_TREE=False):
            view = TranslationView()
            view.request = request
            response = view.dispatch(request, instance_id=self.last_page.pk, language_code=self.default_language.code)

        assert response.status_code == 200
        assert not view.get_form().is_valid()