def test_delete_mark_obsolete(project0_disk, store0): """Tests that the in-DB Store and Directory are marked as obsolete after the on-disk file ceased to exist. Refs. #269. """ tp = TranslationProjectFactory( project=project0_disk, language=LanguageDBFactory() ) store = StoreDBFactory(translation_project=tp, parent=tp.directory) store.update(store.deserialize(store0.serialize())) store.sync() pootle_path = store.pootle_path # Remove on-disk file os.remove(store.file.path) # Update stores by rescanning TP tp.scan_files() # Now files that ceased to exist should be marked as obsolete updated_store = Store.objects.get(pootle_path=pootle_path) assert updated_store.obsolete # The units they contained are obsolete too assert not updated_store.units.exists() assert updated_store.unit_set.filter(state=OBSOLETE).exists()
def ordered_po(test_fs, tp0): """Create a store with ordered units.""" from tests.factories import StoreDBFactory store = StoreDBFactory(name="ordered.po", translation_project=tp0, parent=tp0.directory) with test_fs.open("data/po/ordered.po", "rb") as src: store.update(store.deserialize(src.read())) return store
def numbered_po(test_fs, project0_disk): """Create a store with numbered units.""" from tests.factories import ( LanguageDBFactory, StoreDBFactory, TranslationProjectFactory, ) tp = TranslationProjectFactory(project=project0_disk, language=LanguageDBFactory()) store = StoreDBFactory(name="numbered.po", translation_project=tp, parent=tp.directory) with test_fs.open("data/po/1234.po", "rb") as src: store.update(store.deserialize(src.read())) return store
def test_sync(project0_disk, store0): """Tests that the new on-disk file is created after sync for existing in-DB Store if the corresponding on-disk file ceased to exist. """ tp = TranslationProjectFactory(project=project0_disk, language=LanguageDBFactory()) store = StoreDBFactory(translation_project=tp, parent=tp.directory) store.update(store.deserialize(store0.serialize())) assert not store.file.exists() store.sync() assert store.file.exists() os.remove(store.file.path) assert not store.file.exists() store.sync() assert store.file.exists()
def setup_complex_po(self): import tests from tests.factories import StoreDBFactory from pootle_translationproject.models import TranslationProject po_file = os.path.join(os.path.dirname(tests.__file__), *("data", "po", "complex.po")) with open(po_file, "rb") as f: ttk = getclass(f)(f.read()) tp = TranslationProject.objects.get(project__code="project0", language__code="language0") store = StoreDBFactory(parent=tp.directory, translation_project=tp, name="complex.po") store.update(ttk)