示例#1
0
 def test_work_trash(self):
     product = self.anna_mdl_work.create_product("abc")
     utils.add_file_to_directory(product.directory, "product_file.txt")
     # test trash work and its wip product
     self.anna_mdl_work.trash()
     self.assertFalse(os.path.exists(product.directory))
     self.assertFalse(os.path.exists(self.anna_mdl_work.directory))
示例#2
0
 def test_work_status(self):
     # test new work file is reported, even in subdirectory
     utils.add_file_to_directory(self.anna_mdl_work.directory,
                                 "new_file.txt")
     # test new product files are reported, even in subdirectory
     subdir_path = os.path.join(self.anna_mdl_work.directory, "subdir")
     os.makedirs(subdir_path)
     utils.add_file_to_directory(subdir_path, "subfile.txt")
     # test work file edit are reported
     with open(os.path.join(self.anna_mdl_work.directory, "work.blend"),
               'a') as f:
         f.write("another_line")
     self.assertEqual(
         self.anna_mdl_work.status(), {
             '/new_file.txt': 'added',
             '/subdir/subfile.txt': 'added',
             '/work.blend': 'edited'
         })
     # test work file deletion is reported
     os.remove(os.path.join(self.anna_mdl_work.directory, "work.blend"))
     self.assertEqual(
         self.anna_mdl_work.status(), {
             '/new_file.txt': 'added',
             '/subdir/subfile.txt': 'added',
             '/work.blend': 'removed'
         })
示例#3
0
 def _initResource(self):
     self.anna_mdl = self.prj.create_resource("anna", "mdl")
     self.anna_mdl_work = self.anna_mdl.checkout()
     utils.add_file_to_directory(self.anna_mdl_work.directory, "work.blend")
     self.anna_abc_product = self.anna_mdl_work.create_product("abc")
     utils.add_file_to_directory(self.anna_abc_product.directory,
                                 "anna.abc")
     self.anna_mdl_commit = self.anna_mdl_work.commit()
示例#4
0
 def test_happy_path(self):
     add_file_to_directory(self.directory_a["path"])
     transfer_files(self.directory_a["path"], self.directory_b["path"])
     
     a_files = [f for f in listdir(self.a_path) if isfile(join(self.a_path, f))]
     b_files = [f for f in listdir(self.b_path) if isfile(join(self.b_path, f))]
     
     self.assertEqual(len(a_files), 0)
     self.assertEqual(len(b_files), 1)
示例#5
0
 def test_work_revert(self):
     # make some change in the work folder
     utils.add_file_to_directory(self.anna_mdl_work.directory)
     with open(os.path.join(self.anna_mdl_work.directory, "work.blend"),
               "a") as work_file:
         work_file.write("something")
     # test there's changes
     self.assertTrue(len(self.anna_mdl_work.status()) == 2)
     self.anna_mdl_work.revert()
     # test there's no more changes
     self.assertTrue(len(self.anna_mdl_work.status()) == 0)
示例#6
0
 def test_template_resource(self):
     template_mdl = self.prj.create_template("mdl")
     template_mdl_work = template_mdl.checkout()
     template_mdl_work.create_product("abc")
     utils.add_file_to_directory(template_mdl_work.directory)
     template_mdl_work.commit()
     template_mdl_work.trash()
     froga_mdl = self.prj.create_resource("froga", "mdl")
     froga_mdl_work = froga_mdl.checkout()
     self.assertTrue(
         os.path.exists(
             os.path.join(froga_mdl_work.get_products_directory(), "abc")))
示例#7
0
def listen_for_device(neut):
    while neut.state == ProgramState.ready_for_device:
        # for testing:
        if not os.path.isdir(PATH_TO_DEVICE):
            os.mkdir(PATH_TO_DEVICE)
        add_file_to_directory(PATH_TO_DEVICE)
        # end for testing
        if os.path.isdir(PATH_TO_DEVICE):
            op_1_key = neut.get_key_by_name("op-1")
            op_1_key.file_path = PATH_TO_DEVICE
            print("ready for commands!")
            neut.state = ProgramState.ready_for_commands
            return neut
示例#8
0
    def test_multiple_repository_types(self):
        local_repo_name = "local_test_storage"
        self.cnx.add_repository(name=local_repo_name,
                                adapter="file_storage",
                                path=os.path.join(utils.file_storage_path,
                                                  local_repo_name).replace(
                                                      "\\", "/"))

        template_resource = self.prj.create_resource(
            "_template", "rig", repository="local_test_storage")
        template_work = template_resource.checkout()
        utils.add_file_to_directory(template_work.directory,
                                    "template_work.txt")
        template_work.commit()
        # self.assertTrue(os.path.exists(os.path.join(user_works, "test\\rig\\_template")))
        template_work.trash()
        self.prj.purge_unused_user_products()
        self.assertFalse(
            os.path.exists(
                os.path.join(utils.sandbox_work_path, test_project_name,
                             "_template-rig")))
        template_resource.checkout()
        self.assertTrue(
            os.path.exists(
                os.path.join(utils.sandbox_work_path, test_project_name,
                             "_template-rig")))

        # test moving resource between repo
        self.assertTrue(
            os.path.exists(
                os.path.join(utils.file_storage_path, local_repo_name,
                             test_project_name, "work", "rig", "_template")))

        template_resource.set_repository(self.prj.cfg.default_repository)

        self.assertFalse(
            os.path.exists(
                os.path.join(utils.file_storage_path, local_repo_name,
                             test_project_name, "work", "rig", "_template")))

        # test commit the resource
        utils.add_file_to_directory(template_work.directory)
        template_work.commit()

        # test moving resource between repo when the resource is locked
        template_resource.set_lock(True, "another_user")
        with self.assertRaises(PulseError):
            template_resource.set_repository("serverB")
示例#9
0
文件: test_cli.py 项目: dddjef/pulse
    def test_scenario(self):
        # register to project with user login
        cli_cmd_list([
            'get_project', test_project_name, "--adapter mysql",
            '--settings "' + self.db_url + '"'
        ])

        # create a modeling resource
        cli_cmd_list(['create_resource', 'ch_anna-mdl'])

        anna_mdl_path = os.path.join(cfg.sandbox_work_path, test_project_name,
                                     'ch_anna-mdl')
        self.assertTrue(os.path.exists(anna_mdl_path))
        os.chdir(anna_mdl_path)

        cli_cmd_list(['create_output', 'abc'])
        anna_abc_path = os.path.join(cfg.sandbox_products_path,
                                     test_project_name, 'ch_anna-mdl', 'v001',
                                     'abc')
        self.assertTrue(os.path.exists(anna_abc_path))

        # commit work
        cfg.add_file_to_directory(anna_abc_path)
        cli_cmd_list(['commit'])

        # create a surface resource
        cli_cmd_list(['create_resource', 'ch_anna-surfacing'])
        anna_surfacing_path = os.path.join(cfg.sandbox_work_path,
                                           test_project_name,
                                           'ch_anna-surfacing')
        os.chdir(anna_surfacing_path)

        # add mdl as input and commit
        cli_cmd_list(['add_input', 'ch_anna-mdl.abc@1'])
        cfg.add_file_to_directory(anna_surfacing_path)
        cli_cmd_list(['commit'])

        # trash works
        # but first move out from the work directory, unless the directory won't move
        os.chdir(cli_project_path)
        cli_cmd_list(['trash', 'ch_anna-surfacing'])
        self.assertFalse(os.path.exists(anna_surfacing_path))
        cli_cmd_list(['trash', 'ch_anna-mdl'])
        self.assertFalse(os.path.exists(anna_mdl_path))

        # now try to check out the surface and check the mdl is restored too
        cli_cmd_list(['checkout', 'ch_anna-surfacing'])
        self.assertTrue(os.path.exists(anna_abc_path))
示例#10
0
 def test_environment_variables_in_project_path(self):
     # set up env var
     os.environ['PULSE_TEST'] = utils.test_data_output_path
     # create a project which use this variables in its work and product path
     prj = self.cnx.create_project("env_var",
                                   "$PULSE_TEST/works",
                                   product_user_root="$PULSE_TEST/products",
                                   default_repository="local_test_storage")
     # create a resource
     resource = prj.create_resource("ch_anna", "model")
     # check out the resource
     work = resource.checkout()
     # test its location
     self.assertTrue(
         os.path.exists(
             os.path.join(utils.test_data_output_path,
                          "works/env_var/ch_anna-model")))
     # add an output product
     abc_product = work.create_product("abc")
     # test the product folder location
     self.assertTrue(
         os.path.exists(
             os.path.join(utils.test_data_output_path,
                          "products/env_var/ch_anna-model/V001/abc")))
     # commit
     utils.add_file_to_directory(work.directory)
     work.commit()
     # trash
     work.trash(no_backup=True)
     prj.purge_unused_user_products()
     self.assertFalse(
         os.path.exists(
             os.path.join(utils.test_data_output_path,
                          "works/env_var/ch_anna/model/V001/abc")))
     # create another resource
     surf_resource = prj.create_resource("ch_anna", "surfacing")
     surf_work = surf_resource.checkout()
     # require this product
     surf_work.add_input(abc_product)
     # test the product location
     self.assertTrue(
         os.path.exists(
             os.path.join(utils.test_data_output_path,
                          "products/env_var/ch_anna-model/V001/abc")))
示例#11
0
 def test_recursive_dependencies_download(self):
     anna_surf_resource = self.prj.create_resource("ch_anna", "surfacing")
     anna_surf_work = anna_surf_resource.checkout()
     anna_surf_textures = anna_surf_work.create_product("textures")
     utils.add_file_to_directory(anna_surf_textures.directory,
                                 "product_file.txt")
     anna_surf_work.commit(comment="test generated product")
     anna_rig_resource = self.prj.create_resource("ch_anna", "rigging")
     anna_rig_work = anna_rig_resource.checkout()
     anna_rig_actor = anna_rig_work.create_product("actor_anim")
     anna_rig_actor.add_input(anna_surf_textures)
     anna_rig_work.commit()
     anna_rig_work.trash()
     anna_surf_work.trash()
     self.prj.purge_unused_user_products()
     self.assertFalse(os.path.exists(anna_surf_textures.directory))
     anim_resource = self.prj.create_resource("sh003", "anim")
     anim_work = anim_resource.checkout()
     anim_work.add_input(anna_rig_actor)
     self.assertTrue(os.path.exists(anna_surf_textures.directory))
示例#12
0
 def test_same_user_work_and_product_directory(self):
     prj = self.cnx.create_project(project_name=test_project_name,
                                   work_user_root=utils.sandbox_work_path,
                                   default_repository="local_test_storage")
     resource = prj.create_resource("ch_anna", "model")
     work = resource.checkout()
     abc_product = work.create_product("abc")
     utils.add_file_to_directory(abc_product.directory,
                                 filename="model.abc")
     # check the work status don't list the product twice
     self.assertTrue(len(work.status()) == 1)
     # check when the work is trashed and there's a commit product, the commit product stay
     work.commit()
     utils.add_file_to_directory(work.directory, filename="change.blend")
     work_subfolder = os.path.join(work.directory, "subfolder")
     os.makedirs(work_subfolder)
     work.commit()
     work.trash()
     self.assertTrue(os.path.exists(abc_product.directory))
     self.assertFalse(os.path.exists(work_subfolder))
     # check the purge_unused_product delete the work directory
     prj.purge_unused_user_products()
     self.assertFalse(os.path.exists(work.directory))
     # check the previous commit product are not uploaded again when the work is commit
     work = resource.checkout()
     utils.add_file_to_directory(work.directory,
                                 filename="change_two.blend")
     self.assertTrue(len(work.status()) == 1)
示例#13
0
 def test_work_update(self):
     # commit a new version (2), and trash it
     utils.add_file_to_directory(self.anna_mdl_work.directory,
                                 "new_file.txt")
     self.anna_mdl_work.commit()
     self.anna_mdl_work.trash()
     # checkout to version 1, and test the new file is not there
     work = self.anna_mdl.checkout(index=1)
     self.assertFalse(
         os.path.exists(
             os.path.join(self.anna_mdl_work.directory, "new_file.txt")))
     # update the work, check the new file is there
     time.sleep(1)
     work.update()
     self.assertTrue(
         os.path.exists(
             os.path.join(self.anna_mdl_work.directory, "new_file.txt")))
     # change the work file, test the update will raise an error
     utils.add_file_to_directory(self.anna_mdl_work.directory,
                                 "new_file2.txt")
     with self.assertRaises(PulseError):
         work.update()
示例#14
0
    def test_check_out_from_another_resource(self):
        shader_work_file = "shader_work_file.ma"
        shader_product_file = "shader_product_file.ma"
        source_resource = self.prj.create_resource("source", "surface")
        source_work = source_resource.checkout()
        utils.add_file_to_directory(source_work.directory, shader_work_file)
        source_product = source_work.create_product("shader")
        utils.add_file_to_directory(source_product.directory,
                                    shader_product_file)
        source_work.commit()

        anna_shd_resource = self.prj.create_resource(
            "ch_anna", "surface", source_resource=source_resource)
        anna_shd_work = anna_shd_resource.checkout()
        self.assertTrue(
            os.path.exists(
                os.path.join(anna_shd_work.directory, shader_work_file)))
        self.assertTrue(
            os.path.exists(
                os.path.join(
                    anna_shd_work.get_product("shader").directory,
                    shader_product_file)))
示例#15
0
文件: test_cli.py 项目: dddjef/pulse
    def test_scenario(self):
        # register to project with user login
        cli_cmd_list([
            'get_project', test_project_name, "--adapter json_db",
            '--settings "' + cfg.json_db_path + '"'
        ])

        # create a modeling resource
        cli_cmd_list(['create_resource', 'ch_anna-mdl'])

        anna_mdl_path = os.path.join(cfg.sandbox_work_path, test_project_name,
                                     'ch_anna-mdl')
        self.assertTrue(os.path.exists(anna_mdl_path))
        os.chdir(anna_mdl_path)

        cli_cmd_list(['create_output', 'abc'])
        anna_abc_path = os.path.join(cfg.sandbox_products_path,
                                     test_project_name, 'ch_anna-mdl', 'v001',
                                     'abc')
        self.assertTrue(os.path.exists(anna_abc_path))

        # commit work
        cfg.add_file_to_directory(anna_mdl_path)
        cli_cmd_list(['commit'])

        # create a surface resource
        cli_cmd_list(['create_resource', 'ch_anna-surfacing'])
        anna_surfacing_path = os.path.join(cfg.sandbox_work_path,
                                           test_project_name,
                                           'ch_anna-surfacing')
        os.chdir(anna_surfacing_path)

        # add mdl as input and commit
        cli_cmd_list(['add_input', 'ch_anna-mdl.abc@1'])
        cfg.add_file_to_directory(anna_surfacing_path)
        cli_cmd_list(['commit'])

        # trash works
        # but first move out from the work directory, unless the directory won't move
        os.chdir(cli_project_path)
        cli_cmd_list(['trash', 'ch_anna-surfacing'])
        self.assertFalse(os.path.exists(anna_surfacing_path))
        cli_cmd_list(['trash', 'ch_anna-mdl'])
        self.assertFalse(os.path.exists(anna_mdl_path))

        # now try to check out the surface and check the mdl is restored too
        cli_cmd_list(['checkout', 'ch_anna-surfacing'])
        self.assertTrue(os.path.exists(anna_abc_path))

        # lock surfacing by another user (easier to simulate with with API)
        anna_surfacing_resource = self.prj.get_resource("ch_anna", "surfacing")
        anna_surfacing_resource.set_lock(True, user="******")

        # try to commit changes, and ensure there's a dedicated message for this error
        cfg.add_file_to_directory(anna_surfacing_path, "a_work_file.txt")
        os.chdir(anna_surfacing_path)
        cli_cmd_list(['commit'])
示例#16
0
    def test_complete_scenario(self):
        # create a resource based on this template
        anna_mdl_resource = self.prj.create_resource("ch_anna", "modeling")
        self.assertEqual(anna_mdl_resource.last_version, 0)

        # checkout, and check directories are created
        anna_mdl_work = anna_mdl_resource.checkout()
        self.assertTrue(os.path.exists(anna_mdl_work.directory))
        # by default products should not exists
        self.assertFalse(os.path.exists(
            anna_mdl_work.get_products_directory()))

        # commit should fail if nothing is change in work
        with self.assertRaises(PulseError):
            anna_mdl_work.commit("very first time")

        # create a new file in work directory and try to commit again
        new_file = "test_complete.txt"
        utils.add_file_to_directory(anna_mdl_work.directory, new_file)
        self.assertEqual(anna_mdl_work.status(), {"/" + new_file: 'added'})

        anna_mdl_work.commit("add a file")
        self.assertEqual(anna_mdl_resource.last_version, 1)

        # create a product
        anna_mdl_v2_abc = anna_mdl_work.create_product("ABC")
        # now products directory should exists
        self.assertTrue(os.path.exists(anna_mdl_work.get_products_directory()))
        utils.add_file_to_directory(anna_mdl_v2_abc.directory, "test.abc")
        # create a new commit
        anna_mdl_work.commit("some abc produced")
        self.assertEqual(anna_mdl_resource.last_version, 2)
        # create a new resource
        hat_mdl_resource = self.prj.create_resource("hat", "modeling")
        self.assertEqual(hat_mdl_resource.last_version, 0)
        hat_mdl_work = hat_mdl_resource.checkout()

        hat_mdl_work.add_input(anna_mdl_v2_abc)
        # test the product registration
        self.assertEqual(hat_mdl_work.get_inputs()[0].uri,
                         "ch_anna-modeling.ABC@2")
        # check the work registration to product

        self.assertTrue(
            hat_mdl_work.directory in anna_mdl_v2_abc.get_product_users())
        # check you can't remove a product if it's used by a work
        with self.assertRaises(Exception):
            anna_mdl_v2_abc.remove_from_user_products()

        hat_mdl_work.commit("with input")
        self.assertEqual(hat_mdl_resource.last_version, 1)
        # trash the hat

        hat_mdl_work.trash()
        self.assertTrue(
            hat_mdl_work.directory not in anna_mdl_v2_abc.get_product_users())
        # check the unused time for the product
        self.assertTrue(anna_mdl_v2_abc.get_unused_time() > 0)
        # remove the product
        self.prj.purge_unused_user_products()
        # checkout the work
        hat_mdl_work = hat_mdl_resource.checkout()
        hat_mdl_work.remove_input(anna_mdl_v2_abc)
        anna_mdl_work.trash()