Example #1
0
def test_update_set_last_sync_revision(project0_nongnu, tp0, store0, test_fs):
    """Tests setting last_sync_revision after store creation.
    """
    unit = store0.units.first()
    unit.target = "UPDATED TARGET"
    unit.save()

    store0.sync()

    # Store is already parsed and store.last_sync_revision should be equal to
    # max unit revision
    assert store0.last_sync_revision == store0.get_max_unit_revision()

    # store.last_sync_revision is not changed after empty update
    saved_last_sync_revision = store0.last_sync_revision
    store0.updater.update_from_disk()
    assert store0.last_sync_revision == saved_last_sync_revision

    orig = str(store0)
    update_file = test_fs.open(
        "data/po/tutorial/ru/update_set_last_sync_revision_updated.po",
        "r")
    with update_file as sourcef:
        with open(store0.file.path, "wb") as targetf:
            targetf.write(sourcef.read())

    # any non-empty update sets last_sync_revision to next global revision
    next_revision = Revision.get() + 1
    store0.updater.update_from_disk()
    assert store0.last_sync_revision == next_revision

    # store.last_sync_revision is not changed after empty update (even if it
    # has unsynced units)
    item_index = 0
    next_unit_revision = Revision.get() + 1
    dbunit = store0.units.first()
    dbunit.target = "ANOTHER DB TARGET UPDATE"
    dbunit.save()
    assert dbunit.revision == next_unit_revision

    store0.updater.update_from_disk()
    assert store0.last_sync_revision == next_revision

    # Non-empty update sets store.last_sync_revision to next global revision
    # (even the store has unsynced units).  There is only one unsynced unit in
    # this case so its revision should be set next to store.last_sync_revision
    next_revision = Revision.get() + 1

    with open(store0.file.path, "wb") as targetf:
        targetf.write(orig)

    store0.updater.update_from_disk()
    assert store0.last_sync_revision == next_revision
    # Get unsynced unit in DB. Its revision should be greater
    # than store.last_sync_revision to allow to keep this change during
    # update from a file
    dbunit = store0.units[item_index]
    assert dbunit.revision == store0.last_sync_revision + 1
Example #2
0
def test_update_set_last_sync_revision(project0_nongnu, tp0, store0, test_fs):
    """Tests setting last_sync_revision after store creation.
    """
    unit = store0.units.first()
    unit.target = "UPDATED TARGET"
    unit.save()

    store0.sync()

    # Store is already parsed and store.last_sync_revision should be equal to
    # max unit revision
    assert store0.last_sync_revision == store0.get_max_unit_revision()

    # store.last_sync_revision is not changed after empty update
    saved_last_sync_revision = store0.last_sync_revision
    store0.updater.update_from_disk()
    assert store0.last_sync_revision == saved_last_sync_revision

    orig = str(store0)
    update_file = test_fs.open(
        "data/po/tutorial/ru/update_set_last_sync_revision_updated.po", "r")
    with update_file as sourcef:
        with open(store0.file.path, "wb") as targetf:
            targetf.write(sourcef.read())

    # any non-empty update sets last_sync_revision to next global revision
    next_revision = Revision.get() + 1
    store0.updater.update_from_disk()
    assert store0.last_sync_revision == next_revision

    # store.last_sync_revision is not changed after empty update (even if it
    # has unsynced units)
    item_index = 0
    next_unit_revision = Revision.get() + 1
    dbunit = store0.units.first()
    dbunit.target = "ANOTHER DB TARGET UPDATE"
    dbunit.save()
    assert dbunit.revision == next_unit_revision

    store0.updater.update_from_disk()
    assert store0.last_sync_revision == next_revision

    # Non-empty update sets store.last_sync_revision to next global revision
    # (even the store has unsynced units).  There is only one unsynced unit in
    # this case so its revision should be set next to store.last_sync_revision
    next_revision = Revision.get() + 1

    with open(store0.file.path, "wb") as targetf:
        targetf.write(orig)

    store0.updater.update_from_disk()
    assert store0.last_sync_revision == next_revision
    # Get unsynced unit in DB. Its revision should be greater
    # than store.last_sync_revision to allow to keep this change during
    # update from a file
    dbunit = store0.units[item_index]
    assert dbunit.revision == store0.last_sync_revision + 1
Example #3
0
def test_update_set_last_sync_revision(project0_disk, tp0, store0, test_fs):
    """Tests setting last_sync_revision after store creation."""
    unit = store0.units.first()
    unit.target = "UPDATED TARGET"
    unit.save()

    store0.sync()

    # Store is already parsed and nothing is unsynced
    assert store0.last_sync_revision == store0.get_max_unit_revision()

    # An empty update leaves `last_sync_revision` intact
    saved_last_sync_revision = store0.last_sync_revision
    assert not store0.updater.update_from_disk()
    assert store0.last_sync_revision == saved_last_sync_revision

    orig = str(store0)
    update_file = test_fs.open(
        "data/po/tutorial/ru/update_set_last_sync_revision_updated.po",
        "r")
    with update_file as sourcef:
        with open(store0.file.path, "wb") as targetf:
            targetf.write(sourcef.read())

    # any non-empty update sets last_sync_revision to next global revision
    next_revision = Revision.get() + 1
    # uses `force` to omit mtime optimizations
    assert store0.updater.update_from_disk(force=True)
    assert store0.last_sync_revision == next_revision

    # Make a change to a unit, so that it's unsynced
    next_unit_revision = Revision.get() + 1
    dbunit = store0.units.first()
    dbunit.target = "ANOTHER DB TARGET UPDATE"
    dbunit.save()
    assert dbunit.revision == next_unit_revision

    # After the next empty update, the store's revision remains the same
    assert not store0.updater.update_from_disk()
    assert store0.last_sync_revision == next_revision

    # Now that there are unsynced units, the next non-empty update
    # will set the last sync revision to the next global revision
    next_revision = Revision.get() + 1

    with open(store0.file.path, "wb") as targetf:
        targetf.write(orig)

    # uses `force` to omit mtime optimizations
    assert store0.updater.update_from_disk(force=True)
    assert store0.last_sync_revision == next_revision

    # The unsynced unit's revision should be greater than the last sync
    # revision to allow syncing it after this update
    dbunit = store0.units[0]
    assert dbunit.revision == store0.last_sync_revision + 1
Example #4
0
def test_update_set_last_sync_revision(ru_update_set_last_sync_revision_po):
    """Tests setting last_sync_revision after store creation.
    """
    store = ru_update_set_last_sync_revision_po

    # Store is already parsed and store.last_sync_revision should be equal to
    # max unit revision
    assert store.last_sync_revision == store.get_max_unit_revision()

    # store.last_sync_revision is not changed after empty update
    saved_last_sync_revision = store.last_sync_revision
    store.update_from_disk()
    assert store.last_sync_revision == saved_last_sync_revision

    dir_path = os.path.join(store.translation_project.project.get_real_path(),
                            store.translation_project.language.code)
    copied_initial_filepath = os.path.join(
        dir_path,
        'update_set_last_sync_revision.po.temp'
    )
    shutil.copy(store.file.path, copied_initial_filepath)
    updated_filepath = os.path.join(
        dir_path,
        'update_set_last_sync_revision_updated.po'
    )
    shutil.copy(updated_filepath, store.file.path)

    # any non-empty update sets last_sync_revision to next global revision
    next_revision = Revision.get() + 1
    store.update_from_disk()
    assert store.last_sync_revision == next_revision

    # store.last_sync_revision is not changed after empty update (even if it
    # has unsynced units)
    item_index = 0
    next_unit_revision = Revision.get() + 1
    dbunit = _update_translation(store, item_index, {'target': u'first'},
                                 sync=False)
    assert dbunit.revision == next_unit_revision
    store.update_from_disk()
    assert store.last_sync_revision == next_revision

    # Non-empty update sets store.last_sync_revision to next global revision
    # (even the store has unsynced units).  There is only one unsynced unit in
    # this case so its revision should be set next to store.last_sync_revision
    next_revision = Revision.get() + 1
    shutil.move(copied_initial_filepath, store.file.path)
    store.update_from_disk()
    assert store.last_sync_revision == next_revision
    # Get unsynced unit in DB. Its revision should be greater
    # than store.last_sync_revision to allow to keep this change during
    # update from a file
    dbunit = store.getitem(item_index)
    assert dbunit.revision == store.last_sync_revision + 1
Example #5
0
def test_update_set_last_sync_revision(ru_update_set_last_sync_revision_po):
    """Tests setting last_sync_revision after store creation.
    """
    store = ru_update_set_last_sync_revision_po

    # Store is already parsed and store.last_sync_revision should be equal to
    # max unit revision
    assert store.last_sync_revision == store.get_max_unit_revision()

    # store.last_sync_revision is not changed after empty update
    saved_last_sync_revision = store.last_sync_revision
    store.update_from_disk()
    assert store.last_sync_revision == saved_last_sync_revision

    dir_path = os.path.join(store.translation_project.project.get_real_path(),
                            store.translation_project.language.code)
    copied_initial_filepath = os.path.join(
        dir_path, 'update_set_last_sync_revision.po.temp')
    shutil.copy(store.file.path, copied_initial_filepath)
    updated_filepath = os.path.join(
        dir_path, 'update_set_last_sync_revision_updated.po')
    shutil.copy(updated_filepath, store.file.path)

    # any non-empty update sets last_sync_revision to next global revision
    next_revision = Revision.get() + 1
    store.update_from_disk()
    assert store.last_sync_revision == next_revision

    # store.last_sync_revision is not changed after empty update (even if it
    # has unsynced units)
    item_index = 0
    next_unit_revision = Revision.get() + 1
    dbunit = _update_translation(store,
                                 item_index, {'target': u'first'},
                                 sync=False)
    assert dbunit.revision == next_unit_revision
    store.update_from_disk()
    assert store.last_sync_revision == next_revision

    # Non-empty update sets store.last_sync_revision to next global revision
    # (even the store has unsynced units).  There is only one unsynced unit in
    # this case so its revision should be set next to store.last_sync_revision
    next_revision = Revision.get() + 1
    shutil.move(copied_initial_filepath, store.file.path)
    store.update_from_disk()
    assert store.last_sync_revision == next_revision
    # Get unsynced unit in DB. Its revision should be greater
    # than store.last_sync_revision to allow to keep this change during
    # update from a file
    dbunit = store.getitem(item_index)
    assert dbunit.revision == store.last_sync_revision + 1
Example #6
0
    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())
Example #7
0
 def _sync_to_pootle(self, merge=False, pootle_wins=None):
     """
     Update Pootle ``Store`` with the parsed FS file.
     """
     tmp_store = self.deserialize()
     if not tmp_store:
         logger.warn("File staged for sync has disappeared: %s", self.path)
         return
     if pootle_wins is None:
         resolve_conflict = (
             self.store_fs.resolve_conflict or SOURCE_WINS)
     elif pootle_wins:
         resolve_conflict = POOTLE_WINS
     else:
         resolve_conflict = SOURCE_WINS
     if merge:
         revision = self.store_fs.last_sync_revision or 0
     else:
         # We set the revision to *anything* higher than the Store's
         # This is analogous to the `overwrite` option in
         # Store.update_from_disk
         revision = Revision.get() + 1
     update_revision, __ = self.store.update(
         tmp_store,
         submission_type=SubmissionTypes.SYSTEM,
         user=self.latest_user,
         store_revision=revision,
         resolve_conflict=resolve_conflict)
     logger.debug("Pulled file: %s", self.path)
     return update_revision
Example #8
0
    def handle(self, **options):
        if options["restore"]:
            from pootle_store.models import Unit

            Revision.set(Unit.max_revision())

        self.stdout.write("%s" % Revision.get())
Example #9
0
def test_update_upload_new_revision(en_tutorial_po):
    update_store(
        en_tutorial_po,
        [("Hello, world", "Hello, world UPDATED")],
        submission_type=SubmissionTypes.UPLOAD,
        store_revision=Revision.get() + 1)
    assert en_tutorial_po.units[0].target == "Hello, world UPDATED"
Example #10
0
 def _sync_to_pootle(self, merge=False, user=None, pootle_wins=None):
     """
     Update Pootle ``Store`` with the parsed FS file.
     """
     User = get_user_model()
     if pootle_wins is None:
         resolve_conflict = (
             self.store_fs.resolve_conflict or SOURCE_WINS)
     elif pootle_wins:
         resolve_conflict = POOTLE_WINS
     else:
         resolve_conflict = SOURCE_WINS
     if merge:
         revision = self.store_fs.last_sync_revision or 0
     else:
         # We set the revision to *anything* higher than the Store's
         # This is analogous to the `overwrite` option in
         # Store.update_from_disk
         revision = Revision.get() + 1
     tmp_store = self.deserialize()
     self.store.update(
         tmp_store,
         submission_type=SubmissionTypes.SYSTEM,
         user=user or User.objects.get_system_user(),
         store_revision=revision,
         resolve_conflict=resolve_conflict)
     logger.debug("Pulled file: %s", self.path)
Example #11
0
    def handle_noargs(self, **options):
        last_known_revision = Revision.get()

        if options['after_revision'] is not None:
            after_revision = int(options['after_revision'])
        else:
            after_revision = Store.objects.all().aggregate(
                Max('last_sync_revision'))['last_sync_revision__max'] or -1

        self.stderr.write(
            'Will show languages changed between revisions %s (exclusive) '
            'and %s (inclusive)' % (after_revision, last_known_revision))

        # if the requested revision is the same or is greater than
        # the last known one, return nothing
        if after_revision >= last_known_revision:
            self.stderr.write('(no known changes)')
            return

        q = Unit.objects.filter(revision__gt=after_revision).values(
            'store__translation_project__language__code', ).order_by(
                'store__translation_project__language__code', ).distinct()

        languages = q.values_list('store__translation_project__language__code',
                                  flat=True)

        # list languages separated by comma for easy parsing
        print ','.join(languages)
Example #12
0
def test_update_upload_member_user(store0, member):
    store0.state = PARSED
    unit_source = store0.units.first().source
    update_store(store0, [(unit_source, "%s UPDATED" % unit_source)],
                 user=member,
                 store_revision=Revision.get() + 1)
    assert store0.units[0].submitted_by == member
Example #13
0
def test_update_upload_defaults(en_tutorial_po, system):
    update_store(en_tutorial_po, [("Hello, world", "Hello, world UPDATED")],
                 user=system,
                 store_revision=Revision.get() + 1)
    assert en_tutorial_po.units[0].submitted_by == system
    assert (en_tutorial_po.units[0].submission_set.first().type ==
            SubmissionTypes.SYSTEM)
Example #14
0
def test_update_upload_member_user(en_tutorial_po, member):
    update_store(
        en_tutorial_po,
        [("Hello, world", "Hello, world UPDATED")],
        user=member,
        store_revision=Revision.get() + 1)
    assert en_tutorial_po.units[0].submitted_by == member
Example #15
0
    def handle(self, **options):
        last_known_revision = Revision.get()

        if options["after_revision"] is not None:
            after_revision = int(options["after_revision"])
        else:
            after_revision = Store.objects.all().aggregate(Max("last_sync_revision"))["last_sync_revision__max"] or -1

        self.stderr.write(
            "Will show languages changed between revisions %s (exclusive) "
            "and %s (inclusive)" % (after_revision, last_known_revision)
        )

        # if the requested revision is the same or is greater than the last
        # known one, return nothing
        if after_revision >= last_known_revision:
            self.stderr.write("(no known changes)")
            return

        q = (
            Unit.objects.filter(revision__gt=after_revision)
            .values("store__translation_project__language__code")
            .order_by("store__translation_project__language__code")
            .distinct()
        )

        languages = q.values_list("store__translation_project__language__code", flat=True)

        # list languages separated by comma for easy parsing
        self.stdout.write(",".join(languages))
Example #16
0
    def handle(self, **options):
        last_known_revision = Revision.get()

        if options['after_revision'] is not None:
            after_revision = int(options['after_revision'])
        else:
            after_revision = Store.objects.all().aggregate(
                Max('last_sync_revision'))['last_sync_revision__max'] or -1

        self.stderr.write(
            'Will show languages changed between revisions %s (exclusive) '
            'and %s (inclusive)' %
            (after_revision, last_known_revision)
        )

        # if the requested revision is the same or is greater than the last
        # known one, return nothing
        if after_revision >= last_known_revision:
            self.stderr.write('(no known changes)')
            return

        q = Unit.objects.filter(
            revision__gt=after_revision
        ).values(
            'store__translation_project__language__code',
        ).order_by(
            'store__translation_project__language__code',
        ).distinct()

        languages = q.values_list('store__translation_project__language__code',
                                  flat=True)

        # list languages separated by comma for easy parsing
        print ','.join(languages)
Example #17
0
def test_update_upload_again_new_revision(en_tutorial_po_no_file):
    store = en_tutorial_po_no_file
    assert store.state == NEW
    update_store(store, [("Hello, world", "Hello, world UPDATED")],
                 submission_type=SubmissionTypes.UPLOAD,
                 store_revision=Revision.get() + 1)
    store = Store.objects.get(pk=store.pk)
    assert store.state == PARSED
    assert store.units[0].target == "Hello, world UPDATED"

    update_store(store, [("Hello, world", "Hello, world UPDATED AGAIN")],
                 submission_type=SubmissionTypes.UPLOAD,
                 store_revision=Revision.get() + 1)
    store = Store.objects.get(pk=store.pk)
    assert store.state == PARSED
    assert store.units[0].target == "Hello, world UPDATED AGAIN"
Example #18
0
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
Example #19
0
 def _sync_to_pootle(self, merge=False, user=None, pootle_wins=None):
     """
     Update Pootle ``Store`` with the parsed FS file.
     """
     User = get_user_model()
     if pootle_wins is None:
         resolve_conflict = (self.store_fs.resolve_conflict or SOURCE_WINS)
     elif pootle_wins:
         resolve_conflict = POOTLE_WINS
     else:
         resolve_conflict = SOURCE_WINS
     if merge:
         revision = self.store_fs.last_sync_revision or 0
     else:
         # We set the revision to *anything* higher than the Store's
         # This is analogous to the `overwrite` option in
         # Store.update_from_disk
         revision = Revision.get() + 1
     tmp_store = self.deserialize()
     self.store.update(tmp_store,
                       submission_type=SubmissionTypes.SYSTEM,
                       user=user or User.objects.get_system_user(),
                       store_revision=revision,
                       resolve_conflict=resolve_conflict)
     logger.debug("Pulled file: %s", self.path)
Example #20
0
def test_update_upload_submission_type(store0):
    store0.state = PARSED
    unit_source = store0.units.first().source
    update_store(store0, [(unit_source, "%s UPDATED" % unit_source)],
                 submission_type=SubmissionTypes.UPLOAD,
                 store_revision=Revision.get() + 1)
    assert (
        store0.units[0].submission_set.last().type == SubmissionTypes.UPLOAD)
Example #21
0
def test_update_upload_submission_type(en_tutorial_po):
    update_store(
        en_tutorial_po,
        [("Hello, world", "Hello, world UPDATED")],
        submission_type=SubmissionTypes.UPLOAD,
        store_revision=Revision.get() + 1)
    assert (en_tutorial_po.units[0].submission_set.first().type
            == SubmissionTypes.UPLOAD)
Example #22
0
def test_update_upload_member_user(store0, member):
    store0.state = PARSED
    unit_source = store0.units.first().source
    update_store(
        store0,
        [(unit_source, "%s UPDATED" % unit_source)],
        user=member,
        store_revision=Revision.get() + 1)
    assert store0.units[0].submitted_by == member
Example #23
0
def test_changed_languages_noargs(capfd):
    """Get changed languages since last sync."""
    revision = Revision.get()
    call_command('changed_languages')
    out, err = capfd.readouterr()
    assert out == u'language0,language1\n'
    assert ((
        "Will show languages changed between revisions -1 (exclusive) and "
        "%d (inclusive)" % (revision)) in err)
Example #24
0
def test_update_upload_defaults(en_tutorial_po, system):
    update_store(
        en_tutorial_po,
        [("Hello, world", "Hello, world UPDATED")],
        user=system,
        store_revision=Revision.get() + 1)
    assert en_tutorial_po.units[0].submitted_by == system
    assert (en_tutorial_po.units[0].submission_set.first().type
            == SubmissionTypes.SYSTEM)
Example #25
0
def test_update_upload_defaults(store0, system):
    store0.state = PARSED
    unit_source = store0.units.first().source
    update_store(store0, [(unit_source, "%s UPDATED" % unit_source)],
                 user=system,
                 store_revision=Revision.get() + 1)
    assert store0.units[0].submitted_by == system
    assert (
        store0.units[0].submission_set.last().type == SubmissionTypes.SYSTEM)
def test_changed_languages_noargs(capfd, afrikaans_tutorial, french_tutorial):
    """Get changed languages since last sync."""
    call_command('changed_languages')
    out, err = capfd.readouterr()
    assert "(no known changes)" in err
    revision = Revision.get()
    assert ((
        "Will show languages changed between revisions %d (exclusive) and "
        "%d (inclusive)" % (revision, revision)) in err)
Example #27
0
def __test_update_set_last_sync_revision(ru_update_set_last_sync_revision_po):
    """Tests setting last_sync_revision after store creation.
    """
    store = ru_update_set_last_sync_revision_po

    # Parse a store during first update
    # store.last_sync_revision is set to the next global revision
    next_revision = Revision.get() + 1
    store.update(store.file.store)
    assert store.last_sync_revision == next_revision
    assert store.get_max_unit_revision() == next_revision

    # store.last_sync_revision is not changed after empty update
    store.update(store.file.store)
    assert store.last_sync_revision == next_revision

    # any non-empty update sets last_sync_revision to next global revision
    store.file = 'tutorial/ru/update_set_last_sync_revision_updated.po'
    next_revision = Revision.get() + 1
    store.update(store.file.store)
    assert store.last_sync_revision == next_revision

    # store.last_sync_revision is not changed after empty update
    # (even if it has unsynced units)
    item_index = 0
    next_unit_revision = Revision.get() + 1
    dbunit = _update_translation(store, item_index, {'target': u'first'},
                                 sync=False)
    assert dbunit.revision == next_unit_revision
    store.update(store.file.store, store_revision=0)
    assert store.last_sync_revision == next_revision

    # Non-empty update sets store.last_sync_revision to next global revision
    # (even the store has unsynced units)
    # There is only one unsynced unit in this case so its revision should be set
    # next to store.last_sync_revision
    next_revision = Revision.get() + 1
    store.file = 'tutorial/ru/update_set_last_sync_revision.po'
    store.update(store.file.store,
                 store_revision=store.get_max_unit_revision())
    assert store.last_sync_revision == next_revision
    unit = store.getitem(item_index)
    # not sure why this was store.last_sync_revision + 1 - but no longer works
    assert unit.revision == store.last_sync_revision
Example #28
0
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
Example #29
0
def test_update_upload_again_new_revision(en_tutorial_po_no_file):
    store = en_tutorial_po_no_file
    assert store.state == NEW
    update_store(
        store,
        [("Hello, world", "Hello, world UPDATED")],
        submission_type=SubmissionTypes.UPLOAD,
        store_revision=Revision.get() + 1)
    store = Store.objects.get(pk=store.pk)
    assert store.state == PARSED
    assert store.units[0].target == "Hello, world UPDATED"

    update_store(
        store,
        [("Hello, world", "Hello, world UPDATED AGAIN")],
        submission_type=SubmissionTypes.UPLOAD,
        store_revision=Revision.get() + 1)
    store = Store.objects.get(pk=store.pk)
    assert store.state == PARSED
    assert store.units[0].target == "Hello, world UPDATED AGAIN"
Example #30
0
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
Example #31
0
def test_changed_languages_noargs(capfd):
    """Get changed languages since last sync."""
    revision = Revision.get()
    call_command('changed_languages')
    out, err = capfd.readouterr()
    assert out == u'language0,language1,templates\n'
    assert (
        ("Will show languages changed between revisions -1 (exclusive) and "
         "%d (inclusive)"
         % (revision))
        in err)
Example #32
0
def test_update_upload_submission_type(store0):
    store0.state = PARSED
    unit_source = store0.units.first().source
    update_store(
        store0,
        [(unit_source, "%s UPDATED" % unit_source)],
        submission_type=SubmissionTypes.UPLOAD,
        store_revision=Revision.get() + 1)
    assert (
        store0.units[0].submission_set.last().type
        == SubmissionTypes.UPLOAD)
Example #33
0
def test_changed_languages_noargs(capfd, afrikaans_tutorial, french_tutorial):
    """Get changed languages since last sync."""
    call_command('changed_languages')
    out, err = capfd.readouterr()
    assert "(no known changes)" in err
    revision = Revision.get()
    assert (
        ("Will show languages changed between revisions %d (exclusive) and "
         "%d (inclusive)"
         % (revision, revision))
        in err)
Example #34
0
def test_update_upload_defaults(store0, system):
    store0.state = PARSED
    unit_source = store0.units.first().source
    update_store(
        store0,
        [(unit_source, "%s UPDATED" % unit_source)],
        user=system,
        store_revision=Revision.get() + 1)
    assert store0.units[0].submitted_by == system
    assert (
        store0.units[0].submission_set.last().type
        == SubmissionTypes.SYSTEM)
Example #35
0
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
Example #36
0
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
Example #37
0
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
Example #38
0
def test_changed_languages_noargs_nochanges(capfd, project0_disk, store0):
    """Get changed languages since last sync."""
    unit = store0.units.first()
    unit.target = "CHANGED"
    unit.save()
    store0.sync()
    revision = Revision.get()
    out, err = capfd.readouterr()
    call_command('changed_languages')
    out, err = capfd.readouterr()
    assert "(no known changes)" in err
    assert ((
        "Will show languages changed between revisions %d (exclusive) and "
        "%d (inclusive)" % (revision, revision)) in err)
Example #39
0
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
Example #40
0
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
Example #41
0
def _create_submission_and_suggestion(store,
                                      user,
                                      units=None,
                                      suggestion="SUGGESTION"):

    from pootle.core.models import Revision

    # Update store as user
    if units is None:
        units = [("Hello, world", "Hello, world UPDATED")]
    update_store(store, units, user=user, store_revision=Revision.get() + 1)

    # Add a suggestion
    unit = store.units[0]
    unit.add_suggestion(suggestion, user=user)
    return unit
Example #42
0
def test_changed_languages_noargs_nochanges(capfd, project0_nongnu, store0):
    """Get changed languages since last sync."""
    unit = store0.units.first()
    unit.target = "CHANGED"
    unit.save()
    store0.sync()
    revision = Revision.get()
    out, err = capfd.readouterr()
    call_command('changed_languages')
    out, err = capfd.readouterr()
    assert "(no known changes)" in err
    assert (
        ("Will show languages changed between revisions %d (exclusive) and "
         "%d (inclusive)"
         % (revision, revision))
        in err)
Example #43
0
def test_update_upload_old_revision_unit_conflict(en_tutorial_po):
    original_revision = Revision.get()
    update_store(en_tutorial_po, [("Hello, world", "Hello, world UPDATED")],
                 submission_type=SubmissionTypes.UPLOAD,
                 store_revision=original_revision + 1)

    # load update with expired revision and conflicting unit
    update_store(en_tutorial_po, [("Hello, world", "Hello, world CONFLICT")],
                 submission_type=SubmissionTypes.UPLOAD,
                 store_revision=original_revision)

    # unit target is not updated
    assert en_tutorial_po.units[0].target == "Hello, world UPDATED"

    # but suggestion is added
    suggestion = en_tutorial_po.units[0].get_suggestions()[0].target
    assert suggestion == "Hello, world CONFLICT"
Example #44
0
def _create_submission_and_suggestion(store,
                                      user,
                                      units=None,
                                      suggestion="SUGGESTION"):
    from pootle.core.delegate import review
    from pootle.core.models import Revision
    from pootle_store.models import Suggestion

    # Update store as user
    if units is None:
        units = [("Hello, world", "Hello, world UPDATED", False)]
    update_store(store, units, user=user, store_revision=Revision.get() + 1)

    # Add a suggestion
    unit = store.units[0]
    review.get(Suggestion)().add(unit, suggestion, user)
    return unit
Example #45
0
def test_changed_languages_since_revision(capfd, project0_nongnu, tp0):
    """Changed languages since a given revision"""
    # Everything
    for store in tp0.stores.all():
        store.sync()
    rev = tp0.stores.aggregate(rev=Min('last_sync_revision'))['rev'] - 1
    call_command('changed_languages', '--after-revision=%s' % rev)
    out, err = capfd.readouterr()
    assert out == u'language0,language1\n'

    # End revisions
    revision = Revision.get()
    unit = tp0.stores.first().units.first()
    unit.target = "NEW TARGET"
    unit.save()
    call_command('changed_languages', '--after-revision=%s' % revision)
    out, err = capfd.readouterr()
    assert out == u'language0\n'
Example #46
0
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
Example #47
0
def test_changed_languages_since_revision(capfd, project0_nongnu, tp0):
    """Changed languages since a given revision"""
    # Everything
    for store in tp0.stores.all():
        store.sync()
    rev = tp0.stores.aggregate(
        rev=Min('last_sync_revision'))['rev'] - 1
    call_command('changed_languages', '--after-revision=%s' % rev)
    out, err = capfd.readouterr()
    assert out == u'language0,language1,templates\n'

    # End revisions
    revision = Revision.get()
    unit = tp0.stores.first().units.first()
    unit.target = "NEW TARGET"
    unit.save()
    call_command('changed_languages', '--after-revision=%s' % revision)
    out, err = capfd.readouterr()
    assert out == u'language0\n'
Example #48
0
def test_changed_languages_noargs(capfd, po_directory):
    """Get changed languages since last sync."""
    revision = Revision.get()
    call_command('changed_languages')
    out, err = capfd.readouterr()
    assert out == u'language0,language1\n'
    assert ((
        "Will show languages changed between revisions -1 (exclusive) and "
        "%d (inclusive)" % (revision)) in err)
    # sync the last changed store - this seems arbitrary - but is how the
    # command works
    Unit.objects.filter(revision=revision)[0].store.sync()
    out, err = capfd.readouterr()
    call_command('changed_languages')
    out, err = capfd.readouterr()
    assert "(no known changes)" in err
    assert ((
        "Will show languages changed between revisions %d (exclusive) and "
        "%d (inclusive)" % (revision, revision)) in err)
Example #49
0
def _create_submission_and_suggestion(store, user,
                                      units=None,
                                      suggestion="SUGGESTION"):

    from pootle.core.models import Revision

    # Update store as user
    if units is None:
        units = [("Hello, world", "Hello, world UPDATED")]
    update_store(
        store,
        units,
        user=user,
        store_revision=Revision.get() + 1)

    # Add a suggestion
    unit = store.units[0]
    unit.add_suggestion(suggestion, user=user)
    return unit
Example #50
0
File: store.py Project: arky/pootle
def _create_submission_and_suggestion(store, user,
                                      units=None,
                                      suggestion="SUGGESTION"):
    from pootle.core.delegate import review
    from pootle.core.models import Revision
    from pootle_store.models import Suggestion

    # Update store as user
    if units is None:
        units = [("Hello, world", "Hello, world UPDATED", False)]
    update_store(
        store,
        units,
        user=user,
        store_revision=Revision.get() + 1)

    # Add a suggestion
    unit = store.units[0]
    review.get(Suggestion)().add(unit, suggestion, user)
    return unit
Example #51
0
def test_update_upload_old_revision_unit_conflict(en_tutorial_po):
    original_revision = Revision.get()
    update_store(
        en_tutorial_po,
        [("Hello, world", "Hello, world UPDATED")],
        submission_type=SubmissionTypes.UPLOAD,
        store_revision=original_revision + 1)

    # load update with expired revision and conflicting unit
    update_store(
        en_tutorial_po,
        [("Hello, world", "Hello, world CONFLICT")],
        submission_type=SubmissionTypes.UPLOAD,
        store_revision=original_revision)

    # unit target is not updated
    assert en_tutorial_po.units[0].target == "Hello, world UPDATED"

    # but suggestion is added
    suggestion = en_tutorial_po.units[0].get_suggestions()[0].target
    assert suggestion == "Hello, world CONFLICT"
Example #52
0
def test_revision_incr(af_tutorial_po):
    """Tests revision is incremented when units change."""
    previous_revision = Revision.get()
    db_unit = _update_translation(af_tutorial_po, 0, {"target": [u"Fleisch"]}, sync=False)

    assert db_unit.revision != previous_revision
    assert Revision.get() != previous_revision
    assert db_unit.revision == Revision.get()

    previous_revision = Revision.get()

    db_unit = _update_translation(af_tutorial_po, 0, {"target": u"Lachs"}, sync=False)

    assert db_unit.revision != previous_revision
    assert Revision.get() != previous_revision
    assert db_unit.revision == Revision.get()
Example #53
0
def test_revision_incr(store0):
    """Tests revision is incremented when units change."""
    previous_revision = Revision.get()
    db_unit = store0.units.exclude(target_f="").first()
    db_unit.target = "CHANGED"
    db_unit.save()
    assert db_unit.revision != previous_revision
    assert Revision.get() != previous_revision
    assert db_unit.revision == Revision.get()

    db_unit.refresh_from_db()
    previous_revision = Revision.get()
    db_unit.target = ""
    db_unit.save()
    assert db_unit.revision != previous_revision
    assert Revision.get() != previous_revision
    assert db_unit.revision == Revision.get()
Example #54
0
def test_revision_incr(af_tutorial_po):
    """Tests revision is incremented when units change."""
    previous_revision = Revision.get()
    db_unit = _update_translation(af_tutorial_po, 0, {'target': [u'Fleisch']},
                                  sync=False)

    assert db_unit.revision != previous_revision
    assert Revision.get() != previous_revision
    assert db_unit.revision == Revision.get()

    previous_revision = Revision.get()

    db_unit = _update_translation(af_tutorial_po, 0, {'target': u'Lachs'},
                                  sync=False)

    assert db_unit.revision != previous_revision
    assert Revision.get() != previous_revision
    assert db_unit.revision == Revision.get()
Example #55
0
def test_revision_incr(store0):
    """Tests revision is incremented when units change."""
    previous_revision = Revision.get()
    db_unit = _update_translation(store0,
                                  0, {"target": [u"Fleisch"]},
                                  sync=False)

    assert db_unit.revision != previous_revision
    assert Revision.get() != previous_revision
    assert db_unit.revision == Revision.get()

    previous_revision = Revision.get()

    db_unit = _update_translation(store0, 0, {"target": u"Lachs"}, sync=False)

    assert db_unit.revision != previous_revision
    assert Revision.get() != previous_revision
    assert db_unit.revision == Revision.get()
Example #56
0
def test_update_upload_new_revision(en_tutorial_po):
    update_store(en_tutorial_po, [("Hello, world", "Hello, world UPDATED")],
                 submission_type=SubmissionTypes.UPLOAD,
                 store_revision=Revision.get() + 1)
    assert en_tutorial_po.units[0].target == "Hello, world UPDATED"