def test_create(): user = MockUser().mock_user() store = Store(user) store.rootpath = os.path.expanduser(tempdir + "/.autodl/") store.path = posixpath.join(store.rootpath, store.user.get("username")) test_path = store.path + "/test_project_dir" project_path = store.create(project="test_project_dir") assert test_path == project_path path_none = store.create() assert store.path == path_none
def test_enlist(): user = MockUser().mock_user() store = Store(user) store.rootpath = os.path.expanduser(tempdir + "/.autodl/") store.path = posixpath.join(store.rootpath, store.user.get("username")) project_path_1 = store.create(project="test_project_dir_0") project_path_2 = store.create(project="test_project_dir_1") project_path_3 = store.create(project="test_project_dir_2") test_projects = store.enlist() if ( "test_project_dir_0" in test_projects and "test_project_dir_1" in test_projects and "test_project_dir_2" in test_projects ): assert True
def test_exists(): user = MockUser().mock_user() store = Store(user) store.rootpath = os.path.expanduser(tempdir + "/.autodl/") store.path = posixpath.join(store.rootpath, store.user.get("username")) project_path = store.create(project="test_project_dir") project_path_exists = store.exist(project="test_project_dir") assert project_path_exists == True project_path_none = store.exist() assert project_path_none == True
def test_delete(): user = MockUser().mock_user() store = Store(user) store.rootpath = os.path.expanduser(tempdir + "/.autodl/") store.path = posixpath.join(store.rootpath, store.user.get("username")) project_path = store.create(project="test_project_dir") state, result = store.delete(project="test_project_dir") assert os.path.exists(project_path) == False shared_with_user = MockUser().mock_user() shared_with = shared_with_user.get("username") test_path = store.rootpath + shared_with + "/shared_test_project.json" file = "shared_test_project.json" with open(posixpath.join(store.path, file), "w") as fp: pass state, result = store.delete(project="shared_test_project.json") assert os.path.exists(test_path) == False project_path_none = store.create(project=None) state, result = store.delete(project=None) assert os.path.exists(project_path_none) == False
def create_project(request): try: username = request.data.get("username") user = User(username=username, password=None) user = user.find() project_id = generate_uid() project_name = request.data.get("project_name") lang = request.data.get("language") lib = request.data.get("library") task = request.data.get("task") data_dir = request.data.get("path") output_file_name = request.data.get("output_file_name") store_obj = Store(user) if store_obj.exist(project_id): raise Exception("Project Already Exists!") project_dir = store_obj.create(project_id) metadata = { "project_id": project_id, "project_name": project_name, "lib": lib, "lang": lang, "task": task, "data_dir": data_dir, "output_file_name": output_file_name, "username": username, } with open(project_dir + os.sep + "meta.json", "w") as f: json.dump(metadata, f) status, success, message = 200, True, "Project Created Successfully" except Exception as e: status, success, message = 500, False, str(e) return JsonResponse({ "success": success, "message": message }, status=status)