def test_unit_ts_plurals(store_po, test_fs): with test_fs.open(['data', 'ts', 'add_plurals.ts']) as f: file_store = getclass(f)(f.read()) unit = Unit(store=store_po) unit_ts = file_store.units[0] unit.update(unit_ts) assert unit.hasplural() unit.save() unit = Unit.objects.get(id=unit.id) assert unit.hasplural() unit.save() unit = Unit.objects.get(id=unit.id) assert unit.hasplural()
def test_unit_po_plurals(store_po): unit = Unit(store=store_po, index=1) unit_po = pounit('bar') unit_po.msgid_plural = ['bars'] unit.update(unit_po) assert unit.hasplural() unit.save() assert unit.hasplural()
def handle_noargs(self, **options): if options["restore"]: from pootle_store.models import Unit Revision.set(Unit.max_revision()) self.stdout.write("%s" % Revision.get())
def handle(self, **options): if (not options['flush_rqdata'] and not options['flush_lru'] and not options['flush_django_cache'] and not options['flush_all']): raise CommandError("No options were provided. Use one of " "--django-cache, --rqdata, --lru " "or --all.") self.stdout.write('Flushing cache...') if options['flush_rqdata'] or options['flush_all']: # Flush all rq data, dirty counter and restore Pootle revision # value. r_con = get_redis_connection('redis') r_con.flushdb() self.stdout.write('RQ data removed.') Revision.set(Unit.max_revision()) self.stdout.write('Max unit revision restored.') if options['flush_django_cache'] or options['flush_all']: r_con = get_redis_connection('default') r_con.flushdb() self.stdout.write('All default Django cache data removed.') if options['flush_lru'] or options['flush_all']: r_con = get_redis_connection('lru') r_con.flushdb() self.stdout.write('All lru cache data removed.')
def handle(self, **options): if options["restore"]: from pootle_store.models import Unit Revision.set(Unit.max_revision()) self.stdout.write("%s" % Revision.get())
def handle(self, **options): if (not options['flush_rqdata'] and not options['flush_lru'] and not options['flush_django_cache'] and not options['flush_all']): raise CommandError("No options were provided. Use one of " "--django-cache, --rqdata, --lru " "or --all.") if options['flush_rqdata'] or options['flush_all']: if rq_workers_are_running(): self.stdout.write("Nothing has been flushed. " "Stop RQ workers before running this " "command with --rqdata or --all option.") sys.exit() self.stdout.write('Flushing cache...') if options['flush_rqdata'] or options['flush_all']: # Flush all rq data, dirty counter and restore Pootle revision # value. r_con = get_redis_connection('redis') r_con.flushdb() self.stdout.write('RQ data removed.') Revision.set(Unit.max_revision()) self.stdout.write('Max unit revision restored.') if options['flush_django_cache'] or options['flush_all']: r_con = get_redis_connection('default') r_con.flushdb() self.stdout.write('All default Django cache data removed.') if options['flush_lru'] or options['flush_all']: r_con = get_redis_connection('lru') r_con.flushdb() self.stdout.write('All lru cache data removed.')
def check_revision(app_configs=None, **kwargs): from redis.exceptions import ConnectionError from pootle.core.models import Revision from pootle_store.models import Unit errors = [] try: revision = Revision.get() except (ConnectionError): return errors try: max_revision = Unit.max_revision() except (OperationalError, ProgrammingError): return errors if revision is None or revision < max_revision: errors.append( checks.Critical( _("Revision is missing or has an incorrect value."), hint=_( "Run `revision --restore` to reset the revision counter."), id="pootle.C016", )) return errors
def handle(self, **options): if (not options['flush_stats'] and not options['flush_rqdata'] and not options['flush_django_cache'] and not options['flush_all']): raise CommandError("No options were provided. Use one of " "--django-cache, --rqdata, --stats or --all.") self.stdout.write('Flushing cache...') if options['flush_stats'] or options['flush_all']: # Delete all stats cache data. r_con = get_redis_connection('stats') r_con.flushdb() self.stdout.write('All stats data removed.') if options['flush_rqdata'] or options['flush_all']: # Flush all rq data, dirty counter and restore Pootle revision # value. r_con = get_redis_connection('redis') r_con.flushdb() self.stdout.write('RQ data removed.') Revision.set(Unit.max_revision()) self.stdout.write('Max unit revision restored.') if options['flush_django_cache'] or options['flush_all']: r_con = get_redis_connection('default') r_con.flushdb() self.stdout.write('All default Django cache data removed.')
def fs_plugin_base(tutorial, tmpdir, settings, system, english, zulu): from django.core.cache import caches import pootle_fs_pytest from pootle.core.models import Revision from pootle_store.models import Unit caches["exports"].clear() Revision.set(Unit.max_revision()) dir_path = str(tmpdir.dirpath()) repo_path = os.path.join(dir_path, "__src__") src_path = os.path.abspath( os.path.join( os.path.dirname(pootle_fs_pytest.__file__), "data/fs/example_fs")) settings.POOTLE_FS_PATH = dir_path tutorial_path = os.path.join(dir_path, tutorial.code) if os.path.exists(tutorial_path): shutil.rmtree(tutorial_path) if os.path.exists(repo_path): shutil.rmtree(repo_path) return tutorial, src_path, repo_path, dir_path
def revision(request, clear_cache): """Sets up the cached revision counter for each test call.""" from pootle.core.models import Revision from pootle_store.models import Unit if request.node.get_marker("django_db"): Revision.set(Unit.max_revision()) else: Revision.initialize()
def test_unit_po_plurals(store_po): unit = Unit(store=store_po) unit_po = pounit('bar') unit_po.msgid_plural = ['bars'] unit.update(unit_po) assert unit.hasplural() unit.save() assert unit.hasplural()
def test_max_revision(af_tutorial_po): """Tests `max_revision()` gets the latest revision.""" initial_max_revision = Unit.max_revision() initial_revision = Revision.get() assert initial_max_revision == initial_revision assert initial_max_revision == 0 # Let's make 10 translation updates, this must also update their # revision numbers for i in range(10): _update_translation(af_tutorial_po, 0, {'target': str(i)}, sync=False) end_max_revision = Unit.max_revision() end_revision = Revision.get() assert end_max_revision == end_revision assert end_max_revision != initial_max_revision assert end_revision != initial_revision assert end_revision == 10
def test_max_revision(af_tutorial_po): """Tests `max_revision()` gets the latest revision.""" # update a store first, initial_revision = 1 after this update af_tutorial_po.update(af_tutorial_po.file.store) initial_max_revision = Unit.max_revision() initial_revision = Revision.get() assert initial_max_revision == initial_revision # Let's make 10 translation updates, this must also update their revision # numbers for i in range(10): _update_translation(af_tutorial_po, 0, {'target': str(i)}, sync=False) end_max_revision = Unit.max_revision() end_revision = Revision.get() assert end_max_revision == end_revision assert end_max_revision != initial_max_revision assert end_revision != initial_revision assert end_revision == 10 + initial_revision
def test_max_revision(revision, project0_nongnu, store0): """Tests `max_revision()` gets the latest revision.""" initial_max_revision = Unit.max_revision() initial_revision = Revision.get() assert initial_max_revision == initial_revision # Let's make 10 translation updates, this must also update their revision # numbers unit = store0.units.first() for i in range(10): unit.target = str(i) unit.save() unit.refresh_from_db() end_max_revision = Unit.max_revision() end_revision = Revision.get() assert end_max_revision == end_revision assert end_max_revision != initial_max_revision assert end_revision != initial_revision assert end_revision == 10 + initial_revision
def test_max_revision(revision, project0_disk, store0): """Tests `max_revision()` gets the latest revision.""" store0.sync() # update a store first, initial_revision = 1 after this update store0.update(store0.file.store) initial_max_revision = Unit.max_revision() initial_revision = Revision.get() assert initial_max_revision == initial_revision # Let's make 10 translation updates, this must also update their revision # numbers for i in range(10): _update_translation(store0, 0, {"target": str(i)}, sync=False) end_max_revision = Unit.max_revision() end_revision = Revision.get() assert end_max_revision == end_revision assert end_max_revision != initial_max_revision assert end_revision != initial_revision assert end_revision == 10 + initial_revision
def test_max_revision(af_tutorial_po): """Tests `max_revision()` gets the latest revision.""" # update a store first, initial_revision = 1 after this update af_tutorial_po.update(overwrite=False, only_newer=False) initial_max_revision = Unit.max_revision() initial_revision = Revision.get() assert initial_max_revision == initial_revision assert initial_max_revision == 1 # Let's make 10 translation updates, this must also update their # revision numbers for i in range(10): _update_translation(af_tutorial_po, 0, {"target": str(i)}, sync=False) end_max_revision = Unit.max_revision() end_revision = Revision.get() assert end_max_revision == end_revision assert end_max_revision != initial_max_revision assert end_revision != initial_revision assert end_revision == 10 + initial_revision
def test_max_revision(revision, project0_nongnu, store0): """Tests `max_revision()` gets the latest revision.""" store0.sync() # update a store first, initial_revision = 1 after this update store0.update(store0.file.store) initial_max_revision = Unit.max_revision() initial_revision = Revision.get() assert initial_max_revision == initial_revision # Let's make 10 translation updates, this must also update their revision # numbers for i in range(10): _update_translation(store0, 0, {'target': str(i)}, sync=False) end_max_revision = Unit.max_revision() end_revision = Revision.get() assert end_max_revision == end_revision assert end_max_revision != initial_max_revision assert end_revision != initial_revision assert end_revision == 10 + initial_revision
def setup(self): """Setup test environment by trying to load a data dump file. If this is missing, populate the DB and generate the dump for use in future test runs. """ data_file = self.data_file if os.path.isfile(data_file): from pootle_store.models import Unit self.setup_case_sensitive_schema() call_command('loaddata', data_file) self.setup_redis(revision=Unit.max_revision()) else: self.setup_site_db() with open(data_file, 'w') as file: call_command('dumpdata', '--indent=3', stdout=file)
def check_revision(app_configs=None, **kwargs): from pootle.core.models import Revision from pootle_store.models import Unit errors = [] revision = Revision.get() try: max_revision = Unit.max_revision() except (OperationalError, ProgrammingError): return errors if revision is None or revision < max_revision: errors.append(checks.Critical( _("Revision is missing or has an incorrect value."), hint=_("Run `revision --restore` to reset the revision counter."), id="pootle.C016", )) return errors
def fs_plugin_base(tutorial, tmpdir, settings, system, english, zulu): from django.core.cache import caches import pootle_fs_pytest from pootle.core.models import Revision from pootle_store.models import Unit caches["exports"].clear() Revision.set(Unit.max_revision()) dir_path = str(tmpdir.dirpath()) repo_path = os.path.join(dir_path, "__src__") src_path = os.path.abspath( os.path.join(os.path.dirname(pootle_fs_pytest.__file__), "data/fs/example_fs")) settings.POOTLE_FS_PATH = dir_path tutorial_path = os.path.join(dir_path, tutorial.code) if os.path.exists(tutorial_path): shutil.rmtree(tutorial_path) if os.path.exists(repo_path): shutil.rmtree(repo_path) return tutorial, src_path, repo_path, dir_path
def handle_noargs(self, **options): if options['restore']: from pootle_store.models import Unit Revision.set(Unit.max_revision()) self.stdout.write('%s' % Revision.get())
def create_termunit(term, unit, targets, locations, sourcenotes, transnotes, filecounts): termunit = Unit() termunit.source = term termunit.setid(term) if unit is not None: termunit.merge(unit) termunit.pending_suggestions = [] for target in targets.keys(): if target != termunit.target: termunit.pending_suggestions.append(target) for location in locations: termunit.addlocation(location) for sourcenote in sourcenotes: termunit.addnote(sourcenote, "developer") for filename, count in filecounts.iteritems(): termunit.addnote('(poterminology) %s (%d)\n' % (filename, count), 'translator') return termunit
def revision(clear_cache): """Sets up the cached revision counter for each test call.""" from pootle.core.models import Revision from pootle_store.models import Unit Revision.set(Unit.max_revision())
def test_unit_ts_plurals(store_po, test_fs): with test_fs.open(['data', 'ts', 'add_plurals.ts']) as f: file_store = getclass(f)(f.read()) unit = Unit(store=store_po, index=1) unit_ts = file_store.units[0] unit.update(unit_ts) assert unit.hasplural() unit.save() unit = Unit.objects.get(id=unit.id) assert unit.hasplural() unit.save() unit = Unit.objects.get(id=unit.id) assert unit.hasplural()
def handle(self, **options): if options['restore']: from pootle_store.models import Unit Revision.set(Unit.max_revision()) self.stdout.write('%s' % Revision.get())