Example #1
0
    def _test_symlink(self):
        if os.name == 'nt':
            return

        # create a new test.txt file
        file_path = "./symlink.txt"
        file = open(file_path, 'w')
        file.write("symlink test")
        file.close()

        file_path2 = "./symlink_append.txt"
        file = open(file_path2, 'w')
        file.write("append test")
        file.close()


        checkin = FileCheckin(self.person, file_path, context="sym_test", checkin_type='auto')
        checkin.execute()
        snap = checkin.get_snapshot()
        versionless_snap = Snapshot.get_versionless(self.person.get_search_type(), self.person.get_id(), "sym_test", mode='latest', create=False)
        self.assertEquals(True, isinstance(versionless_snap, Snapshot))

        main_lib_path = snap.get_lib_path_by_type('main')
        self.assertEquals(main_lib_path.endswith('/sym_test/.versions/symlink_sym_test_v001.txt'), True)
        if versionless_snap:
            lib_path =versionless_snap.get_lib_path_by_type('main')
            self.assertEquals(True, os.path.exists(lib_path)) 
            rel_path = os.readlink(lib_path)
            lib_dir = os.path.dirname(lib_path)

            # this is essentially handle_link() in FileUndo class
            wd = os.getcwd()
            os.chdir(lib_dir)
            real_path = os.path.join(lib_dir, os.path.abspath(rel_path))
            # lib_path points to real_path

            expected_rel_path  = Common.relative_path(lib_path, real_path)
            self.assertEquals(True, os.path.exists(real_path))
            self.assertEquals(expected_rel_path, rel_path)
            os.chdir(wd)

        # if not inplace or preallocate mode, keep_file_name should be False
        checkin = FileAppendCheckin(snap.get_code(), [file_path2], file_types=['add'], keep_file_name=False, checkin_type='auto')
        checkin.execute()
        snap = checkin.get_snapshot()
        main_lib_path = snap.get_lib_path_by_type('add')
        self.assertEquals(snap.get_value('is_current'), True)
        self.assertEquals(snap.get_value('is_latest'), True)
        self.assertEquals(main_lib_path.endswith('/sym_test/.versions/symlink_append_sym_test_v001.txt'), True)
        versionless_snap = Snapshot.get_versionless(self.person.get_search_type(), self.person.get_id(), "sym_test", mode='latest', create=False)
        if versionless_snap:
            lib_path = versionless_snap.get_lib_path_by_type('add')
            self.assertEquals(lib_path.endswith('/sym_test/symlink_append_sym_test.txt'), True)
            self.assertEquals(os.path.exists(lib_path), True)
Example #2
0
    def _test_symlink(my):
        if os.name == 'nt':
            return

        # create a new test.txt file
        file_path = "./symlink.txt"
        file = open(file_path, 'w')
        file.write("symlink test")
        file.close()

        checkin = FileCheckin(my.person, file_path, context="sym_test", checkin_type='auto')
        checkin.execute()

        snap = Snapshot.get_versionless(my.person.get_search_type(), my.person.get_id(), "sym_test", mode='latest', create=False)
        my.assertEquals(True, isinstance(snap, Snapshot))
        if snap:
            lib_path =snap.get_lib_path_by_type('main')
            my.assertEquals(True, os.path.exists(lib_path)) 
            rel_path = os.readlink(lib_path)
            lib_dir = os.path.dirname(lib_path)

            # this is essentially handle_link() in FileUndo class
            wd = os.getcwd()
            os.chdir(lib_dir)
            real_path = os.path.join(lib_dir, os.path.abspath(rel_path))
            # lib_path points to real_path

            expected_rel_path  = Common.relative_path(lib_path, real_path)
            my.assertEquals(True, os.path.exists(real_path))
            my.assertEquals(expected_rel_path, rel_path)
            os.chdir(wd)
Example #3
0
    def _test_strict_checkin(my):

        server = Config.get_value("install", "server")
        process = "process"
        person_code = my.person.get_code()

        filename = "filename.jpg"

        process = "strict"

        subcontexts = [
            '', '', # do 2 checkins
            'hi', 'hi',
            'medium',
            'low',
        ]

        for i, subcontext in enumerate(subcontexts):

            if subcontext:
                context = "%s/%s" % (process, subcontext)
            else:
                context = process

            # create a new test.txt file
            file_path = "./%s" % filename
            file = open(file_path, 'w')
            file.write("test")
            file.close()


            #import time
            #start = time.time()

            checkin = FileCheckin(my.person, file_path, context=context, checkin_type='strict')
            checkin.execute()
            snapshot = checkin.get_snapshot()

            #print "time: ", time.time() - start
            #print "---"

            # make sure there is no versionless
            versionless = Snapshot.get_versionless(my.person.get_search_type(), my.person.get_id(), context, mode='latest', create=False)
            my.assertEquals(None, versionless)

            
            path = snapshot.get_path_by_type("main")

            asset_dir = Config.get_value("checkin", "asset_base_dir")

            file_objects = snapshot.get_all_file_objects()
            my.assertEquals(1, len(file_objects))

            file_object = file_objects[0]
            relative_dir = file_object.get_value("relative_dir")
            file_name = file_object.get_value("file_name")

            test_path = "%s/%s/%s" % (asset_dir, relative_dir, file_name)
            my.assertEquals(test_path, path)
Example #4
0
    def _test_strict_checkin(self):

        server = Config.get_value("install", "server")
        #process = "process"
        person_code = self.person.get_code()

        filename = "filename.jpg"

        process = "strict"

        subcontexts = [
            '',
            '',  # do 2 checkins
            'hi',
            'hi',
            'medium',
            'low',
        ]

        for i, subcontext in enumerate(subcontexts):

            if subcontext:
                context = "%s/%s" % (process, subcontext)
            else:
                context = process

            # create a new test.txt file
            file_path = "./%s" % filename
            file = open(file_path, 'w')
            file.write("test")
            file.close()

            #import time
            #start = time.time()

            checkin = FileCheckin(self.person,
                                  file_path,
                                  context=context,
                                  checkin_type='strict')
            checkin.execute()
            snapshot = checkin.get_snapshot()
            #print "time: ", time.time() - start
            #print "---"

            # make sure there is no latest versionless except for process/low
            versionless = Snapshot.get_versionless(
                self.person.get_search_type(),
                self.person.get_id(),
                context,
                mode='latest',
                create=False)

            versionless_current = Snapshot.get_versionless(
                self.person.get_search_type(),
                self.person.get_id(),
                context,
                mode='current',
                create=False)

            if context == 'strict/low':
                self.assertNotEquals(None, versionless)
                file_objects = versionless.get_all_file_objects()
                self.assertEquals(1, len(file_objects))

                file_object = file_objects[0]
                relative_dir = file_object.get_value("relative_dir")
                file_name = file_object.get_value("file_name")
                self.assertEquals(file_name, 'filename_latest.jpg')
            else:
                self.assertEquals(None, versionless)

            # make sure there is no current versionless except for process/hi
            if context == 'strict/hi':
                self.assertNotEquals(None, versionless_current)
                file_objects = versionless_current.get_all_file_objects()
                self.assertEquals(1, len(file_objects))

                file_object = file_objects[0]
                relative_dir = file_object.get_value("relative_dir")
                file_name = file_object.get_value("file_name")
                self.assertEquals(file_name, 'filename_current.jpg')

            else:
                self.assertEquals(None, versionless_current)

            path = snapshot.get_path_by_type("main")

            asset_dir = Config.get_value("checkin",
                                         "asset_base_dir",
                                         sub_key="default")

            file_objects = snapshot.get_all_file_objects()
            self.assertEquals(1, len(file_objects))

            file_object = file_objects[0]
            relative_dir = file_object.get_value("relative_dir")
            file_name = file_object.get_value("file_name")

            test_path = "%s/%s/%s" % (asset_dir, relative_dir, file_name)
            self.assertEquals(test_path, path)
Example #5
0
    def _test_auto_checkin(self):
        server = Config.get_value("install", "server")
        process = "process"
        person_code = self.person.get_code()

        filename = "filename.jpg"

        process = "process"

        subdirs = [
            '',
            '',  # do 2 checkins
            'subdir',
            'subdir/subsubdir'
        ]

        for i, subdir in enumerate(subdirs):

            if subdir:
                context = "%s/%s/%s" % (process, subdir, filename)
            else:
                context = "%s/%s" % (process, filename)

            # create a new test.txt file
            file_path = "./%s" % filename
            file = open(file_path, 'w')
            file.write("test")
            file.close()

            #import time
            #start = time.time()

            checkin = FileCheckin(self.person,
                                  file_path,
                                  context=context,
                                  checkin_type='auto')
            checkin.execute()

            #print "time: ", time.time() - start
            #print "---"

            # check the returned snapshot
            snapshot = checkin.get_snapshot()
            self.assertEquals(context, snapshot.get_value("context"))
            if i != 1:  # the second checkin is version 2
                version = 1
                self.assertEquals(1, snapshot.get_value("version"))
            else:
                version = 2
            self.assertEquals(version, snapshot.get_value("version"))

            # check the file object data
            file_objects = snapshot.get_all_file_objects()
            self.assertEquals(1, len(file_objects))
            file_object = file_objects[0]
            repo_filename = file_object.get_value("file_name")

            if server:
                expected = "filename_process_%s_v%0.3d.jpg" % (server, version)
            else:
                expected = "filename_process_v%0.3d.jpg" % (version)
            self.assertEquals(expected, repo_filename)

            relative_dir = file_object.get_value("relative_dir")
            if subdir:
                expected = "unittest/person/%s/process/.versions/%s" % (
                    person_code, subdir)
            else:
                expected = "unittest/person/%s/process/.versions" % person_code
            self.assertEquals(expected, relative_dir)

            asset_dir = Config.get_value("checkin",
                                         "asset_base_dir",
                                         sub_key="default")
            path = "%s/%s/%s" % (asset_dir, relative_dir, repo_filename)

            # make sure the path from the snapshot is correct
            snapshot_path = snapshot.get_path_by_type("main")
            self.assertEquals(path, snapshot_path)

            exists = os.path.exists(path)
            self.assertEquals(True, exists)

            # check that a versionless has been created
            versionless = Snapshot.get_versionless(
                self.person.get_search_type(),
                self.person.get_id(),
                context,
                mode='latest',
                create=False)

            self.assertNotEquals(None, versionless)

            self.assertEquals(-1, versionless.get_value("version"))

            versionless_path = versionless.get_path_by_type("main", "lib")
            versionless_dir = os.path.dirname(versionless_path)

            # test that it is a link
            lexists = os.path.lexists(versionless_path)
            self.assertEquals(True, lexists)

            # check the real path links to the versioned path
            real_path = os.path.realpath(versionless_path)
            self.assertEquals(real_path, path)

            # check that it actually points to a valid path
            exists = os.path.exists(versionless_path)
            self.assertEquals(True, exists)
Example #6
0
    def _test_symlink(self):
        if os.name == 'nt':
            return

        # create a new test.txt file
        file_path = "./symlink.txt"
        file = open(file_path, 'w')
        file.write("symlink test")
        file.close()

        file_path2 = "./symlink_append.txt"
        file = open(file_path2, 'w')
        file.write("append test")
        file.close()

        checkin = FileCheckin(self.person,
                              file_path,
                              context="sym_test",
                              checkin_type='auto')
        checkin.execute()
        snap = checkin.get_snapshot()
        versionless_snap = Snapshot.get_versionless(
            self.person.get_search_type(),
            self.person.get_id(),
            "sym_test",
            mode='latest',
            create=False)
        self.assertEquals(True, isinstance(versionless_snap, Snapshot))

        main_lib_path = snap.get_lib_path_by_type('main')
        self.assertEquals(
            main_lib_path.endswith(
                '/sym_test/.versions/symlink_sym_test_v001.txt'), True)
        if versionless_snap:
            lib_path = versionless_snap.get_lib_path_by_type('main')
            self.assertEquals(True, os.path.exists(lib_path))
            rel_path = os.readlink(lib_path)
            lib_dir = os.path.dirname(lib_path)

            # this is essentially handle_link() in FileUndo class
            wd = os.getcwd()
            os.chdir(lib_dir)
            real_path = os.path.join(lib_dir, os.path.abspath(rel_path))
            # lib_path points to real_path

            expected_rel_path = Common.relative_path(lib_path, real_path)
            self.assertEquals(True, os.path.exists(real_path))
            self.assertEquals(expected_rel_path, rel_path)
            os.chdir(wd)

        # if not inplace or preallocate mode, keep_file_name should be False
        checkin = FileAppendCheckin(snap.get_code(), [file_path2],
                                    file_types=['add'],
                                    keep_file_name=False,
                                    checkin_type='auto')
        checkin.execute()
        snap = checkin.get_snapshot()
        main_lib_path = snap.get_lib_path_by_type('add')
        self.assertEquals(snap.get_value('is_current'), True)
        self.assertEquals(snap.get_value('is_latest'), True)
        self.assertEquals(
            main_lib_path.endswith(
                '/sym_test/.versions/symlink_append_sym_test_v001.txt'), True)
        versionless_snap = Snapshot.get_versionless(
            self.person.get_search_type(),
            self.person.get_id(),
            "sym_test",
            mode='latest',
            create=False)
        if versionless_snap:
            lib_path = versionless_snap.get_lib_path_by_type('add')
            self.assertEquals(
                lib_path.endswith('/sym_test/symlink_append_sym_test.txt'),
                True)
            self.assertEquals(os.path.exists(lib_path), True)
Example #7
0
    def _test_strict_checkin(self):

        server = Config.get_value("install", "server")
        #process = "process"
        person_code = self.person.get_code()

        filename = "filename.jpg"

        process = "strict"

        subcontexts = [
            '', '', # do 2 checkins
            'hi', 'hi',
            'medium',
            'low',
        ]

        for i, subcontext in enumerate(subcontexts):

            if subcontext:
                context = "%s/%s" % (process, subcontext)
            else:
                context = process

            # create a new test.txt file
            file_path = "./%s" % filename
            file = open(file_path, 'w')
            file.write("test")
            file.close()


            #import time
            #start = time.time()

            checkin = FileCheckin(self.person, file_path, context=context, checkin_type='strict')
            checkin.execute()
            snapshot = checkin.get_snapshot()
            #print "time: ", time.time() - start
            #print "---"

            # make sure there is no latest versionless except for process/low
            versionless = Snapshot.get_versionless(self.person.get_search_type(), self.person.get_id(), context, mode='latest', create=False)

            versionless_current = Snapshot.get_versionless(self.person.get_search_type(), self.person.get_id(), context, mode='current', create=False)

            if context == 'strict/low':
                self.assertNotEquals(None, versionless)
                file_objects = versionless.get_all_file_objects()
                self.assertEquals(1, len(file_objects))

                file_object = file_objects[0]
                relative_dir = file_object.get_value("relative_dir")
                file_name = file_object.get_value("file_name")
                self.assertEquals(file_name ,'filename_latest.jpg')
            else:
                self.assertEquals(None, versionless)

            # make sure there is no current versionless except for process/hi
            if context == 'strict/hi':
                self.assertNotEquals(None, versionless_current)
                file_objects = versionless_current.get_all_file_objects()
                self.assertEquals(1, len(file_objects))

                file_object = file_objects[0]
                relative_dir = file_object.get_value("relative_dir")
                file_name = file_object.get_value("file_name")
                self.assertEquals(file_name, 'filename_current.jpg')
                
            else:
                self.assertEquals(None, versionless_current)

            
            path = snapshot.get_path_by_type("main")

            asset_dir = Config.get_value("checkin", "asset_base_dir", sub_key="default")

            file_objects = snapshot.get_all_file_objects()
            self.assertEquals(1, len(file_objects))

            file_object = file_objects[0]
            relative_dir = file_object.get_value("relative_dir")
            file_name = file_object.get_value("file_name")

            test_path = "%s/%s/%s" % (asset_dir, relative_dir, file_name)
            self.assertEquals(test_path, path)
Example #8
0
    def _test_auto_checkin(self):
        server = Config.get_value("install", "server")
        process = "process"
        person_code = self.person.get_code()

        filename = "filename.jpg"

        process = "process"

        subdirs = [
            '', '', # do 2 checkins
            'subdir',
            'subdir/subsubdir'
        ]

        for i, subdir in enumerate(subdirs):

            if subdir:
                context = "%s/%s/%s" % (process, subdir, filename)
            else:
                context = "%s/%s" % (process, filename)

            # create a new test.txt file
            file_path = "./%s" % filename
            file = open(file_path, 'w')
            file.write("test")
            file.close()


            #import time
            #start = time.time()

            checkin = FileCheckin(self.person, file_path, context=context, checkin_type='auto')
            checkin.execute()

            #print "time: ", time.time() - start
            #print "---"


            # check the returned snapshot
            snapshot = checkin.get_snapshot()
            self.assertEquals(context, snapshot.get_value("context") )
            if i != 1: # the second checkin is version 2
                version = 1
                self.assertEquals(1, snapshot.get_value("version") )
            else:
                version = 2
            self.assertEquals(version, snapshot.get_value("version") )

            # check the file object data
            file_objects = snapshot.get_all_file_objects()
            self.assertEquals(1, len(file_objects))
            file_object = file_objects[0]
            repo_filename = file_object.get_value("file_name")

            if server:
                expected = "filename_process_%s_v%0.3d.jpg" % (server, version)
            else:
                expected = "filename_process_v%0.3d.jpg" % (version)
            self.assertEquals(expected, repo_filename)

            relative_dir = file_object.get_value("relative_dir")
            if subdir:
                expected = "unittest/person/%s/process/.versions/%s" % (person_code, subdir)
            else:
                expected = "unittest/person/%s/process/.versions" % person_code
            self.assertEquals(expected, relative_dir)

            asset_dir = Config.get_value("checkin", "asset_base_dir", sub_key="default")
            path = "%s/%s/%s" % (asset_dir, relative_dir, repo_filename)


            # make sure the path from the snapshot is correct
            snapshot_path = snapshot.get_path_by_type("main")
            self.assertEquals(path, snapshot_path)


            exists = os.path.exists(path)
            self.assertEquals(True, exists)


            # check that a versionless has been created
            versionless = Snapshot.get_versionless(self.person.get_search_type(), self.person.get_id(), context, mode='latest', create=False)

            self.assertNotEquals( None, versionless)

            self.assertEquals(-1, versionless.get_value("version") )

            versionless_path = versionless.get_path_by_type("main", "lib")
            versionless_dir = os.path.dirname(versionless_path)

            # test that it is a link
            lexists = os.path.lexists(versionless_path)
            self.assertEquals(True, lexists)

            # check the real path links to the versioned path
            real_path = os.path.realpath(versionless_path)
            self.assertEquals(real_path, path)

            # check that it actually points to a valid path
            exists = os.path.exists(versionless_path)
            self.assertEquals(True, exists)