<commit_before>import time

from nxdrive.tests.common import TEST_WORKSPACE_PATH
from nxdrive.tests.common import OS_STAT_MTIME_RESOLUTION
from nxdrive.tests.common_unit_test import UnitTestCase


class TestVersioning(UnitTestCase):

    def test_versioning(self):
        # Call the Nuxeo operation to set the versioning delay to 30 seconds
        self.versioning_delay = OS_STAT_MTIME_RESOLUTION * 30
        self.root_remote_client.execute(
            "NuxeoDrive.SetVersioningOptions",
            delay=str(self.versioning_delay))

        local = self.local_client_1
        self.engine_1.start()

        # Create a file as user 2
        self.remote_document_client_2.make_file('/', 'Test versioning.txt', "This is version 0")
        self.assertTrue(self.remote_document_client_2.exists('/Test versioning.txt'))
        doc = self.root_remote_client.fetch(TEST_WORKSPACE_PATH + '/Test versioning.txt')
        self._assert_version(doc, 0, 0)

        # Synchronize it for user 1
        self.wait_sync(wait_for_async=True)
        self.assertTrue(local.exists('/Test versioning.txt'))

        # Update it as user 1 => should be versioned
        time.sleep(OS_STAT_MTIME_RESOLUTION)
        local.update_content('/Test versioning.txt', "Modified content")
        self.wait_sync()
        doc = self.root_remote_client.fetch(
            TEST_WORKSPACE_PATH + '/Test versioning.txt')
        self._assert_version(doc, 0, 1)

        # Update it as user 1 => should NOT be versioned
        # since the versioning delay is not passed by
        time.sleep(OS_STAT_MTIME_RESOLUTION)
        local.update_content('/Test versioning.txt', "Content twice modified")
        self.wait_sync()
        doc = self.root_remote_client.fetch(
            TEST_WORKSPACE_PATH + '/Test versioning.txt')
        self._assert_version(doc, 0, 1)

        # Wait for versioning delay expiration then update it as user 1 after
        # => should be versioned since the versioning delay is passed by
        time.sleep(self.versioning_delay + 2.0)
        local.update_content('/Test versioning.txt', "Updated again!!")
        self.wait_sync()
        doc = self.root_remote_client.fetch(
            TEST_WORKSPACE_PATH + '/Test versioning.txt')
        self._assert_version(doc, 0, 2)

    def test_version_restore(self):
        remote_client = self.remote_document_client_1
        local_client = self.local_client_1

        self.engine_1.start()

        # Create a remote doc
        doc = remote_client.make_file(self.workspace, 'Document to restore.txt', content="Initial content.")
        self.wait_sync(wait_for_async=True)
        self.assertTrue(local_client.exists('/Document to restore.txt'))
        self.assertEquals(local_client.get_content('/Document to restore.txt'),
                          "Initial content.")

        # Create version 1.0, update content, then restore version 1.0
        remote_client.create_version(doc, 'Major')
        remote_client.update_content(doc, "Updated content.")
        self.wait_sync(wait_for_async=True)
        self.assertEquals(local_client.get_content('/Document to restore.txt'),
                          "Updated content.")
        version_uid = remote_client.get_versions(doc)[0][0]
        remote_client.restore_version(version_uid)
        self.wait_sync(wait_for_async=True)
        self.assertEquals(local_client.get_content('/Document to restore.txt'),
                          "Initial content.")

    def _assert_version(self, doc, major, minor):
        self.assertEquals(doc['properties']['uid:major_version'], major)
        self.assertEquals(doc['properties']['uid:minor_version'], minor)
<commit_msg>NXDRIVE-632: Add more log on test_versioning<commit_after>import time

from nxdrive.tests.common import TEST_WORKSPACE_PATH
from nxdrive.tests.common import OS_STAT_MTIME_RESOLUTION
from nxdrive.tests.common_unit_test import UnitTestCase
from nxdrive.logging_config import get_logger

log = get_logger(__name__)


class TestVersioning(UnitTestCase):

    def test_versioning(self):
        # Call the Nuxeo operation to set the versioning delay to 30 seconds
        self.versioning_delay = OS_STAT_MTIME_RESOLUTION * 30
        self.root_remote_client.execute(
            "NuxeoDrive.SetVersioningOptions",
            delay=str(self.versioning_delay))

        local = self.local_client_1
        self.engine_1.start()

        # Create a file as user 2
        self.remote_document_client_2.make_file('/', 'Test versioning.txt', "This is version 0")
        self.assertTrue(self.remote_document_client_2.exists('/Test versioning.txt'))
        doc = self.root_remote_client.fetch(TEST_WORKSPACE_PATH + '/Test versioning.txt')
        self._assert_version(doc, 0, 0)

        # Synchronize it for user 1
        self.wait_sync(wait_for_async=True)
        self.assertTrue(local.exists('/Test versioning.txt'))

        # Update it as user 1 => should be versioned
        time.sleep(OS_STAT_MTIME_RESOLUTION)
        local.update_content('/Test versioning.txt', "Modified content")
        self.wait_sync()
        doc = self.root_remote_client.fetch(
            TEST_WORKSPACE_PATH + '/Test versioning.txt')
        self._assert_version(doc, 0, 1)

        # Update it as user 1 => should NOT be versioned
        # since the versioning delay is not passed by
        time.sleep(OS_STAT_MTIME_RESOLUTION)
        local.update_content('/Test versioning.txt', "Content twice modified")
        self.wait_sync()
        doc = self.root_remote_client.fetch(
            TEST_WORKSPACE_PATH + '/Test versioning.txt')
        self._assert_version(doc, 0, 1)

        # Wait for versioning delay expiration then update it as user 1 after
        # => should be versioned since the versioning delay is passed by
        log.debug("wait for %d to end the versioning grace", (self.versioning_delay + 2.0))
        time.sleep(self.versioning_delay + 2.0)
        log.debug("will now update content of Test versioning.txt")
        local.update_content('/Test versioning.txt', "Updated again!!")
        self.wait_sync()
        doc = self.root_remote_client.fetch(
            TEST_WORKSPACE_PATH + '/Test versioning.txt')
        self._assert_version(doc, 0, 2)

    def test_version_restore(self):
        remote_client = self.remote_document_client_1
        local_client = self.local_client_1

        self.engine_1.start()

        # Create a remote doc
        doc = remote_client.make_file(self.workspace, 'Document to restore.txt', content="Initial content.")
        self.wait_sync(wait_for_async=True)
        self.assertTrue(local_client.exists('/Document to restore.txt'))
        self.assertEquals(local_client.get_content('/Document to restore.txt'),
                          "Initial content.")

        # Create version 1.0, update content, then restore version 1.0
        remote_client.create_version(doc, 'Major')
        remote_client.update_content(doc, "Updated content.")
        self.wait_sync(wait_for_async=True)
        self.assertEquals(local_client.get_content('/Document to restore.txt'),
                          "Updated content.")
        version_uid = remote_client.get_versions(doc)[0][0]
        remote_client.restore_version(version_uid)
        self.wait_sync(wait_for_async=True)
        self.assertEquals(local_client.get_content('/Document to restore.txt'),
                          "Initial content.")

    def _assert_version(self, doc, major, minor):
        self.assertEquals(doc['properties']['uid:major_version'], major)
        self.assertEquals(doc['properties']['uid:minor_version'], minor)

{'fraction_non_alphanumeric': 0.09591380896071476, 'fraction_numerical': 0.009328603337274997, 'mean_word_length': 2.9379203310915676, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6737898', 'n_tokens_mistral': 2235, 'n_tokens_neox': 2161, 'n_words': 478}