def _test_properties_save2db(self): """Test creating source strings from a PROPERTIES file works""" handler = JavaPropertiesHandler( os.path.join(os.path.dirname(__file__), 'complex.properties')) handler.set_language(self.resource.source_language) handler.parse_file(is_source=True) r = self.resource l = self.resource.source_language handler.bind_resource(r) handler.save2db(is_source=True) # Check that all 25 entities are created in the db self.assertEqual(SourceEntity.objects.filter(resource=r).count(), 25) # Check that all source translations are there self.assertEqual( len( Translation.objects.filter(source_entity__resource=r, language=l)), 25) # Import and save the finish translation handler.bind_file( os.path.join(os.path.dirname(__file__), 'complex_hi_IN-ascii.properties')) l = Language.objects.get(code='hi_IN') handler.set_language(l) handler.parse_file() entities = 0 translations = 0 for s in handler.stringset: entities += 1 if s.translation.strip() != '': translations += 1 self.assertEqual(entities, 23) self.assertEqual(translations, 23) handler.save2db() # Check if all Source strings are untouched self.assertEqual(SourceEntity.objects.filter(resource=r).count(), 25) # Check that all translations are there self.assertEqual( len(Translation.objects.filter(resource=r, language=l)), 23) self._mark_translation_as_reviewed(self.resource, ['Key00', 'Key02'], l, 2) return handler
def test_properties_save2db(self): """Test creating source strings from a PROPERTIES file works""" handler = JavaPropertiesHandler( os.path.join(os.path.dirname(__file__), 'complex.properties') ) handler.set_language(self.resource.source_language) handler.parse_file(is_source=True) r = self.resource l = self.resource.source_language handler.bind_resource(r) handler.save2db(is_source=True) # Check that all 25 entities are created in the db self.assertEqual( SourceEntity.objects.filter(resource=r).count(), 25) # Check that all source translations are there self.assertEqual( len(Translation.objects.filter(source_entity__resource=r, language=l)), 25 ) # Import and save the finish translation handler.bind_file(os.path.join(os.path.dirname(__file__),'complex_hi_IN-ascii.properties')) l = Language.objects.get(code='hi_IN') handler.set_language(l) handler.parse_file() entities = 0 translations = 0 for s in handler.stringset.strings: entities += 1 if s.translation.strip() != '': translations += 1 self.assertEqual(entities, 23) self.assertEqual(translations, 23) handler.save2db() # Check if all Source strings are untouched self.assertEqual(SourceEntity.objects.filter(resource=r).count(), 25) # Check that all translations are there self.assertEqual(len(Translation.objects.filter(source_entity__resource=r, language=l)), 23) handler.bind_file(os.path.join(os.path.dirname(__file__),'complex_hi_IN.properties')) self.assertRaises(JavaParseError, handler.parse_file) r.delete()
def test_properties_parser(self): """PROPERTIES file tests.""" # Parsing PROPERTIES file handler = JavaPropertiesHandler( os.path.join(os.path.dirname(__file__), 'complex.properties')) handler.set_language(self.resource.source_language) handler.parse_file(is_source=True) self.stringset = handler.stringset entities = 0 translations = 0 for s in self.stringset: entities += 1 if s.translation.strip() != '': translations += 1 # Asserting number of entities - PROPERTIES file has 25 entries. # we ignore keys without a value self.assertEqual(entities, 25) self.assertEqual(translations, 25)
def test_properties_parser(self): """PROPERTIES file tests.""" # Parsing PROPERTIES file handler = JavaPropertiesHandler( os.path.join(os.path.dirname(__file__), 'complex.properties') ) handler.set_language(self.resource.source_language) handler.parse_file(is_source=True) self.stringset = handler.stringset entities = 0 translations = 0 for s in self.stringset.strings: entities += 1 if s.translation.strip() != '': translations += 1 # Asserting number of entities - PROPERTIES file has 25 entries. # we ignore keys without a value self.assertEqual(entities, 25) self.assertEqual(translations, 25)