Ejemplo n.º 1
0
    def block_children(self, block_id):
        block = self.client().get_block(block_id)

        return {
            "parent": BlockPresenter(block),
            "children": [BlockPresenter(child) for child in block.children]
        }
Ejemplo n.º 2
0
    def collection_view_content(self, collection_id, view_id):
        collection_view = self.__collection_view(collection_id, view_id)
        results = collection_view.default_query().execute()

        return {
            "collection": BlockPresenter(collection_view),
            "rows": [BlockPresenter(row) for row in results]
        }
Ejemplo n.º 3
0
def test_block_presentation(notion_token):
    test_page = get_test_page()

    block = test_page.children.add_new(TextBlock, title="textblock")

    assert BlockPresenter(block).block == block
    assert BlockPresenter(block) == {"id": block.id, "title": "textblock"}
    assert json.dumps(BlockPresenter(
        block)) == '{"id": "%s", "title": "textblock"}' % block.id
Ejemplo n.º 4
0
def test_divider_block_presentation(notion_token):
    test_page = get_test_page()

    block = test_page.children.add_new(DividerBlock)
    assert BlockPresenter(block).block == block
    assert BlockPresenter(block) == {
        "id": clean_id(block.id),
        "block_type": "divider"
    }
    assert json.dumps(BlockPresenter(
        block)) == '{"id": "%s", "block_type": "divider"}' % clean_id(block.id)
Ejemplo n.º 5
0
def test_collection_view_presentation(notion_token):
    collection_view = create_collection_view()
    collection_view.name = "Test view"

    assert BlockPresenter(collection_view).block == collection_view
    assert BlockPresenter(collection_view) == {
        "collection_id": clean_id(collection_view.parent.id),
        "collection_title": "Test collection",
        "view_id": clean_id(collection_view.id),
        "view_title": "Test view"
    }

    json_string_template = '{"collection_id": "%s", "view_id": "%s", "collection_title": "Test collection", "view_title": "Test view"}'
    assert json.dumps(
        BlockPresenter(collection_view)) == json_string_template % (clean_id(
            collection_view.parent.id), clean_id(collection_view.id))
Ejemplo n.º 6
0
    def block_delete(self, block_id):
        block = self.client().get_block(block_id)

        if block.alive:
            block.remove()
            return BlockPresenter(block)
        else:
            raise AlreadyDeletedError(block_id)
Ejemplo n.º 7
0
    def block_update(self, block_id, data):
        block = self.client().get_block(block_id)

        with self.client().as_atomic_transaction():
            for key, val in data.items():
                setattr(block, key, val)

        return BlockPresenter(block)
Ejemplo n.º 8
0
def test_collection_row_block_presentation(notion_token):
    collection_view = create_collection_view()
    block = collection_view.collection.add_row(name="test row",
                                               value=10,
                                               enabled=True)

    assert BlockPresenter(block).block == block
    assert BlockPresenter(block) == {
        "id": block.id,
        "enabled": True,
        "tags": [],
        "category": None,
        "value": 10,
        "name": "test row"
    }
    assert json.dumps(
        BlockPresenter(block)
    ) == '{"id": "%s", "enabled": true, "tags": [], "category": null, "value": 10, "name": "test row"}' % block.id
Ejemplo n.º 9
0
    def collection_append(self, collection_id, view_id, data):
        collection_view = self.__collection_view(collection_id, view_id)

        row = collection_view.collection.add_row(**data)

        return BlockPresenter(row)
Ejemplo n.º 10
0
    def block_append(self, block_id, data):
        block = self.client().get_block(block_id)

        new_block = block.children.add_new(TextBlock, title=data["title"])

        return BlockPresenter(new_block)
Ejemplo n.º 11
0
    def block_content(self, block_id):
        block = self.client().get_block(block_id)

        return BlockPresenter(block)
Ejemplo n.º 12
0
    def block_delete(self, block_id):
        block = self.client().get_block(block_id)

        block.remove()

        return BlockPresenter(block)
Ejemplo n.º 13
0
    def block_children(self, block_id):
        block = self.client().get_block(block_id)

        return [BlockPresenter(child) for child in block.children]