def test_manage_other_branch_with_import_projects(mock_time_hash, looker_client: LookerClient): """User is on branch A, checkout branch B and test. The manager should checkout branch B, test, then checkout branch A. We are setting import projects to True. The manager should create a temp branch in the dependent project, and clean it up at the end. """ # Set up starting branch and workspace looker_client.update_workspace("dev") starting_branch = "pytest" looker_client.checkout_branch(LOOKER_PROJECT, starting_branch) dependent_project = "welcome_to_looker" new_branch = "pytest-additional" assert new_branch != starting_branch manager = LookerBranchManager(looker_client, LOOKER_PROJECT) assert manager.init_state.branch == starting_branch manager(branch=new_branch).__enter__() assert not manager.is_temp_branch dependent_project_manager = manager.import_managers[0] assert dependent_project_manager.is_temp_branch temp_branch = dependent_project_manager.branch assert looker_client.get_active_branch_name(LOOKER_PROJECT) == new_branch assert looker_client.get_active_branch_name( dependent_project) == temp_branch manager.__exit__() assert looker_client.get_active_branch_name( LOOKER_PROJECT) == starting_branch assert (looker_client.get_active_branch_name(dependent_project) == dependent_project_manager.init_state.branch) assert temp_branch not in looker_client.get_all_branches(dependent_project)
def test_manage_current_branch_with_ref(mock_time_hash, mock_get_imports, looker_client: LookerClient): """User is on branch A, checkout branch A with a commit ref and test. The manager should create a new temp branch based on branch A, checkout the temp branch, test, checkout branch A, and delete the temp branch. """ # Set up starting branch and workspace looker_client.update_workspace("dev") starting_branch = "pytest" looker_client.checkout_branch(LOOKER_PROJECT, starting_branch) commit = "e2d21d" manager = LookerBranchManager(looker_client, LOOKER_PROJECT) assert manager.init_state.branch == starting_branch manager(commit=commit).__enter__() assert manager.is_temp_branch temp_branch = manager.branch branch_info = looker_client.get_active_branch(LOOKER_PROJECT) assert branch_info["name"] == temp_branch assert branch_info["ref"][:6] == commit manager.__exit__() branch_info = looker_client.get_active_branch(LOOKER_PROJECT) assert branch_info["name"] == starting_branch assert branch_info["ref"][:6] != commit assert temp_branch not in looker_client.get_all_branches(LOOKER_PROJECT)
def test_manage_current_branch(mock_get_imports, looker_client: LookerClient): """User is on branch A, checkout branch A and test. The manager should not perform any branch checkouts, just test. """ # Set up starting branch and workspace looker_client.update_workspace("dev") branch = "pytest" looker_client.checkout_branch(LOOKER_PROJECT, branch) manager = LookerBranchManager(looker_client, LOOKER_PROJECT) assert manager.init_state.branch == branch manager(branch=branch).__enter__() assert looker_client.get_active_branch_name(LOOKER_PROJECT) == branch manager.__exit__() assert looker_client.get_active_branch_name(LOOKER_PROJECT) == branch
def test_manage_other_branch(mock_get_imports, looker_client: LookerClient): """User is on branch A, checkout branch B and test. The manager should checkout branch B, test, then checkout branch A. """ # Set up starting branch and workspace looker_client.update_workspace("dev") starting_branch = "pytest" looker_client.checkout_branch(LOOKER_PROJECT, starting_branch) new_branch = "pytest-additional" assert new_branch != starting_branch manager = LookerBranchManager(looker_client, LOOKER_PROJECT) assert manager.init_state.branch == starting_branch manager(branch=new_branch).__enter__() assert looker_client.get_active_branch_name(LOOKER_PROJECT) == new_branch manager.__exit__() assert looker_client.get_active_branch_name( LOOKER_PROJECT) == starting_branch