Exemplo n.º 1
0
def test_block_children(notion_token):
    notion_api = NotionApi(token=notion_token)
    test_page = get_test_page()

    block = test_page.children.add_new(TextBlock, title="a parent block")
    child_block_1 = block.children.add_new(TextBlock, title="child block 1")
    child_block_2 = block.children.add_new(TextBlock, title="child block 2")

    content = notion_api.block_children(block.id)

    assert content["parent"] == {
        "id": clean_id(block.id),
        "block_type": "text",
        "title": "a parent block",
    }
    assert content["children"][0] == {
        "id": clean_id(child_block_1.id),
        "block_type": "text",
        "title": "child block 1",
    }
    assert content["children"][1] == {
        "id": clean_id(child_block_2.id),
        "block_type": "text",
        "title": "child block 2",
    }
Exemplo n.º 2
0
def block_delete(notion_token, block_id):
    try:
        notion_api = NotionApi(notion_token)

        block = notion_api.block_delete(block_id)

        return jsonify(block), 200
    except Exception as error:
        return jsonify(error=str(error)), 500
Exemplo n.º 3
0
def block_children_append(notion_token, block_id):
    try:
        notion_api = NotionApi(notion_token)

        block = notion_api.block_append(block_id, request.json)

        return jsonify(block), 200
    except Exception as error:
        return jsonify(error=str(error)), 500
Exemplo n.º 4
0
def collection_view(notion_token, collection_id, view_id):
    try:
        notion_api = NotionApi(notion_token)

        content = notion_api.collection_view_content(collection_id, view_id)

        return jsonify(content), 200
    except Exception as error:
        return jsonify(error=str(error)), 500
Exemplo n.º 5
0
def block_children_view(notion_token, block_id):
    try:
        notion_api = NotionApi(notion_token)

        content = notion_api.block_children(block_id)

        return jsonify(content), 200
    except Exception as error:
        return jsonify(error=str(error)), 500
Exemplo n.º 6
0
def collection_append(notion_token, collection_id, view_id):
    try:
        notion_api = NotionApi(notion_token)

        row = notion_api.collection_append(collection_id, view_id,
                                           request.json)

        return jsonify(row), 200
    except Exception as error:
        return jsonify(error=str(error)), 500
Exemplo n.º 7
0
def test_block_delete_with_collection_block(notion_token):
    notion_api = NotionApi(token=notion_token)

    collection_view = create_collection_view()
    block = collection_view.collection.add_row(name="test row",
                                               value=10,
                                               enabled=True)

    notion_api.block_delete(block.id)

    assert block not in collection_view.collection.get_rows()
Exemplo n.º 8
0
def test_block_delete_with_text_block(notion_token):
    notion_api = NotionApi(token=notion_token)
    test_page = get_test_page()

    block = test_page.children.add_new(TextBlock, title="test block delete")
    parent_block = block.parent

    notion_api.block_delete(block.id)
    parent_block.refresh()

    assert block not in parent_block.children
Exemplo n.º 9
0
def test_block_update_with_text_block(notion_token):
    notion_api = NotionApi(token=notion_token)
    test_page = get_test_page()

    block = test_page.children.add_new(TextBlock, title="test block update")
    updated_block = notion_api.block_update(
        block.id, {"title": "test block has been updated"})

    assert updated_block == {
        "id": clean_id(block.id),
        "block_type": "text",
        "title": "test block has been updated",
    }
Exemplo n.º 10
0
def test_block_append(notion_token):
    notion_api = NotionApi(token=notion_token)
    test_page = get_test_page()

    block = test_page.children.add_new(TextBlock, title="test block append")
    new_block = notion_api.block_append(block.id, {"title": "appending text"})

    assert new_block == {
        "id": clean_id(new_block.block.id),
        "block_type": "text",
        "title": "appending text",
    }
    assert clean_id(new_block.block.parent.id) == clean_id(block.id)
Exemplo n.º 11
0
def test_block_content(notion_token):
    notion_api = NotionApi(token=notion_token)
    test_page = get_test_page()

    block = test_page.children.add_new(TextBlock,
                                       title="test get block content")
    content = notion_api.block_content(block.id)

    assert content == {
        "id": clean_id(block.id),
        "block_type": "text",
        "title": "test get block content",
    }
Exemplo n.º 12
0
def test_collection_view_append(notion_token):
    notion_api = NotionApi(token=notion_token)

    collection_view = create_collection_view()
    collection_id = collection_view.parent.id.replace("-", "")
    view_id = collection_view.id.replace("-", "")

    notion_api.collection_append(collection_id, view_id, {
        "enabled": True,
        "value": 10,
        "name": "test row"
    })
    collection_view_content = notion_api.collection_view_content(
        collection_id, view_id)

    assert collection_view_content["rows"][0]["name"] == "test row"
    assert collection_view_content["rows"][0]["enabled"] is True
    assert collection_view_content["rows"][0]["value"] == 10
Exemplo n.º 13
0
def test_collection_view_content(notion_token):
    notion_api = NotionApi(token=notion_token)

    collection_view = create_collection_view()
    collection_id = collection_view.parent.id
    view_id = collection_view.id

    collection_view.collection.add_row(name="test row")
    collection_view_content = notion_api.collection_view_content(
        collection_id.replace("-", ""), view_id.replace("-", ""))

    assert collection_view_content["collection"] == {
        "collection_id": clean_id(collection_id),
        "view_id": clean_id(view_id),
        "collection_title": "Test collection",
        "view_title": "Test view",
    }
    assert collection_view_content["rows"][0]["name"] == "test row"
Exemplo n.º 14
0
def test_block_update_with_collection_block(notion_token):
    notion_api = NotionApi(token=notion_token)

    collection_view = create_collection_view()
    block = collection_view.collection.add_row(name="test row",
                                               value=10,
                                               enabled=True)

    updated_block = notion_api.block_update(block.id, {
        "name": "test block has been updated",
        "value": 5
    })

    assert updated_block == {
        "id": clean_id(block.id),
        "block_type": "page",
        "name": "test block has been updated",
        "value": 5,
        "category": None,
        "enabled": True,
        "tags": [],
    }
Exemplo n.º 15
0
def test_block_delete_an_already_deleted_block(notion_token):
    notion_api = NotionApi(token=notion_token)
    test_page = get_test_page()

    block = test_page.children.add_new(TextBlock, title="test block delete")
    parent_block = block.parent

    notion_api.block_delete(block.id)
    parent_block.refresh()

    with pytest.raises(AlreadyDeletedError):
        notion_api.block_delete(block.id)