def test_43_view_property_po_file_path(self): """Confirm our class-based views properly parse/validate the path of the .po file in question derived from the url kwargs. """ self.copy_po_file_from_template('./django.po.template') # By default, when all goes well, we get our existing .po file path request = RequestFactory().get(self.xx_form_url) request.user = self.user kwargs = {'po_filter': 'third-party', 'lang_id': 'xx', 'idx': 0} view = self._setup_view(view=views.TranslationFormView(), request=request, **kwargs) self.assertEqual(view.po_file_path, self.dest_file) # But if the language isn't an option, we get a 404 with self.settings(ROSETTA_LANGUAGES=[ l for l in settings.LANGUAGES if l[0] != 'xx' ]): view = self._setup_view(view=views.TranslationFormView(), request=request, **kwargs) with self.assertRaises(Http404): view.po_file_path # And if the index doesn't correspond with a file, we get a 404 new_kwargs = {'po_filter': 'third-party', 'lang_id': 'xx', 'idx': 9} view = self._setup_view( view=views.TranslationFormView(), # Recycle request, even though url kwargs conflict with ones below. request=request, **new_kwargs) with self.assertRaises(Http404): view.po_file_path
def test_42_view_property_po_file_is_writable(self): """Confirm that we're accurately determining the filesystem write-perms on our .po file. """ self.copy_po_file_from_template('./django.po.template') # By default, we're writable request = RequestFactory().get(self.xx_form_url) request.user = self.user kwargs = {'po_filter': 'third-party', 'lang_id': 'xx', 'idx': 0} view = self._setup_view(view=views.TranslationFormView(), request=request, **kwargs) self.assertTrue(view.po_file_is_writable) # Now try again with the file not writable. (Regenerate the view, since # this po_file_is_writable is cached for the life of the request.) # make the pofile read-only os.chmod(self.dest_file, 292) # 0444 view = self._setup_view(view=views.TranslationFormView(), request=request, **kwargs) self.assertFalse(view.po_file_is_writable) # Cleanup os.chmod(self.dest_file, 420) # 0644