Example #1
0
    def setup_class(self):
        self.proj_id = 'gbw2t'
        self.this_dir, filename = os.path.split(__file__)
        self.files_orig = join(self.this_dir, "files_orig")
        self.tmp_folder = join(self.this_dir, "tmp")
        self.proj_file = join(self.this_dir, "tmp", "test.proj")
        self.proj_root = join(self.this_dir, "tmp", "files")

        if os.path.isfile(self.proj_file):
            os.remove(self.proj_file)  # start with no project file
        if os.path.isdir(self.proj_root):
            shutil.rmtree(self.proj_root)  # start with no project root
        # start with what we know
        shutil.copytree(self.files_orig, self.proj_root)

        # first time around we need to supply username/password
        session = remote.Session(username='******',
                                 password='******')  # to get a token
        self.osf_proj = session.open_project(self.proj_id)

        # in future we just give the proj_file and the rest can be recreated
        proj = project.Project(project_file=self.proj_file,
                               root_path=self.proj_root,
                               osf=self.osf_proj)

        # test the saving of the file
        print("Getting initial state of project")
        t0 = time.time()
        changes = proj.get_changes()
        t1 = time.time()
        print("Indexing and finding diffs took {:.3f}s".format(t1 - t0))
        print(changes)  # prints a prettified table
        print_all_changes(changes)
        t2 = time.time()
        print("Applying changes")
        changes.apply(threaded=False)  # do_sync test will be threaded
        t3 = time.time()
        print("Applying changes took {:.3f}s".format(t3 - t2))
        proj.save()

        # having saved it we can test that it reloads without user/password
        print("Re-running get_changes(). Should be None")
        proj = project.Project(project_file=self.proj_file)
        t0 = time.time()
        changes = proj.get_changes()
        t1 = time.time()
        print("\nRedoing - indexing and finding diffs took {:.3f}s".format(t1 -
                                                                           t0))
        print(changes)  # prints a prettified table
        print_all_changes(changes)
        assert len(changes) == 0
Example #2
0
 def teardown_class(self):
     self.proj = None
     # take a copy of the remote project for reference
     if os.path.isdir('EndOfLastTest'):
         shutil.rmtree('EndOfLastTest')  # start with no project root
     shutil.copytree(self.proj_root, 'EndOfLastTest')
     # revert the local project to original state
     if os.path.isdir(self.proj_root):
         shutil.rmtree(self.proj_root)  # start with no project root
     shutil.copytree(self.files_orig, self.proj_root)
     # perform a sync with remote to reset all the files there
     proj = project.Project(project_file=self.proj_file)
     do_sync(proj)
Example #3
0
    def test_add_and_remove_remote(self):
        test_path = 'newFolder/someTextFile.txt'
        # add a folder and file remotely to propogate to local
        # take an arbitrary file from local give a new path and push to remote
        asset = tools.find_by_key(self.proj.local.index, 'path', 'README.txt')
        new_asset = copy.copy(asset)
        # change 'path' for upload but 'full_path' points to orig
        new_asset['path'] = test_path
        self.proj.osf.add_file(new_asset)
        self.proj = None  # discard and recreate

        # now create proj and do sync
        self.proj = project.Project(project_file=self.proj_file)
        do_sync(self.proj)
        self.proj.save()

        print("Removing a file and folder remotely")
        # remove folder and file remotely and propogate to local
        asset = tools.find_by_key(self.proj.osf.index, 'path', test_path)
        self.proj.osf.del_file(asset)
        container, name = os.path.split(test_path)
        asset = tools.find_by_key(self.proj.osf.index, 'path', container)
        self.proj.osf.del_file(asset)
Example #4
0
 def setup(self):
     # this is done individually for every test
     self.proj = project.Project(project_file=self.proj_file)