Exemplo n.º 1
0
def test_create_board_create_homepage_call(mocker):
    test_board = models.Homepage(title="taco", description="burrito", id=42)
    mocker.patch.object(sdk, "search_homepages")
    mocker.patch.object(sdk, "create_homepage")
    sdk.search_homepages.return_value = []
    deploy_boards.create_or_update_board(test_board, sdk)
    sdk.create_homepage.assert_called_with(
        models.Homepage(title="taco", description="burrito"))
Exemplo n.º 2
0
def create_or_update_board(source_board_object, target_sdk, title_override=None):

    # Determine if board already exists in target environment
    search_title = title_override or source_board_object.title
    search_res = target_sdk.search_homepages(title=search_title)
    assert len(search_res) < 2, "More than one board found! Refine your search or remove duplicate names."

    try:
        assert len(search_res) == 1

    # If board does not exist then create
    except AssertionError:
        logger.info(
            "No pre-existing board found. Creating new board in target environment",
            extra={"title": search_title}
        )

        new_board = models.Homepage(
            title=source_board_object.title,
            description=source_board_object.description
        )

        resp = target_sdk.create_homepage(new_board)
        logger.info("Board created", extra={"id": resp.id})
        return resp.id

    # If board already exists, clear out sections and update
    logger.info(
        "Found board in target instance. Updating and rebuilding content",
        extra={"title": search_title}
    )

    target_board = search_res[0]

    # Clear out existing sections
    section_list = [i.id for i in target_board.homepage_sections]
    logger.debug("Found sections to clear", extra={"section_list": section_list})

    for section in section_list:
        logger.debug("Clearing section for refresh", extra={"section_id": section})
        target_sdk.delete_homepage_section(section)

    # Update
    update_board = models.Homepage(
        title=source_board_object.title,
        description=source_board_object.description
    )

    resp = target_sdk.update_homepage(target_board.id, update_board)
    logger.info("Board updated", extra={"id": resp.id})
    return resp.id
Exemplo n.º 3
0
def test_create_or_update_board_update_delete_call(mocker):
    test_board = models.Homepage(title="taco", description="burrito", id=42)
    mocker.patch.object(sdk, "search_homepages")
    mocker.patch.object(sdk, "update_homepage")
    mocker.patch.object(sdk, "delete_homepage_section")
    sdk.search_homepages.return_value = [MockHomepage()]
    deploy_boards.create_or_update_board(test_board, sdk)
    sdk.delete_homepage_section.assert_called()
Exemplo n.º 4
0
def test_create_or_update_board_create(mocker):
    test_board = models.Homepage(title="taco", description="burrito")
    test_board_resp = MockHomepage()
    mocker.patch.object(sdk, "search_homepages")
    mocker.patch.object(sdk, "create_homepage")
    sdk.search_homepages.return_value = []
    sdk.create_homepage.return_value = test_board_resp
    board_id = deploy_boards.create_or_update_board(test_board, sdk)
    assert board_id == 3