def test_po_extensions(self): """Test PO/POT extensions. If language is None: extension == 'pot'. """ self.resource.i18n_method = 'PO' for lang in ('en', 'el', None): extension = registry.file_extension_for(self.resource, lang) if lang is None: self.assertEqual(extension, registry.extensions_for('POT')[0]) else: self.assertEqual(extension, registry.extensions_for('PO')[0])
def create(self): """ Create a new translation supplied as a string. Returns: A dict with information for the request. Raises: BadRequestError: There was a problem with the request. NoContentError: There was no content string in the request. """ if 'content' not in self.data: raise NoContentError("No content found.") parser = registry.appropriate_handler( self.resource, language=self.language ) if parser is None: raise BadRequestError("I18n type is not supported: %s" % i18n_type) file_ = tempfile.NamedTemporaryFile( mode='wb', suffix=registry.extensions_for(self.resource.i18n_method)[0], delete=False, ) try: file_.write(self.data['content'].encode('UTF-8')) file_.close() try: parser.bind_file(file_.name) parser.is_content_valid() except (FileCheckError, ParseError), e: raise BadRequestError(unicode(e)) except Exception, e: logger.error(unicode(e), exc_info=True) raise BadRequestError("A strange error has happened.")
def create(self): """ Create a new translation supplied as a string. Returns: A dict with information for the request. Raises: BadRequestError: There was a problem with the request. NoContentError: There was no content string in the request. """ if 'content' not in self.data: raise NoContentError("No content found.") parser = registry.appropriate_handler(self.resource, language=self.language) if parser is None: raise BadRequestError("I18n type is not supported: %s" % i18n_type) file_ = tempfile.NamedTemporaryFile( mode='wb', suffix=registry.extensions_for(self.resource.i18n_method)[0], delete=False, ) try: file_.write(self.data['content'].encode('UTF-8')) file_.close() try: parser.bind_file(file_.name) parser.is_content_valid() except (FileCheckError, ParseError), e: raise BadRequestError(unicode(e)) except Exception, e: logger.error(unicode(e), exc_info=True) raise BadRequestError("A strange error has happened.")
def test_extensions(self): for method in registry.available_methods: if method == 'POT': continue self.resource.i18n_method = method correct_extensions = registry.extensions_for(method) for lang in ('en', 'el'): extension_returned = registry.file_extension_for( self.resource, lang ) self.assertIn(extension_returned, correct_extensions)