コード例 #1
0
def test_index_block_value(home_page):
    indexer.index_page(home_page)
    assert IndexEntry.objects.filter(block_name="heading")[0].block_value == "This is a test homepage"
    assert IndexEntry.objects.filter(block_name="number")[0].block_value == "123"
    assert IndexEntry.objects.filter(block_name="author")[0].block_value == ""
    assert IndexEntry.objects.filter(block_name="body")[0].block_value == ""
    assert IndexEntry.objects.filter(block_name="image")[0].block_value == "1"
コード例 #2
0
def test_index_image_bound_block(home_page):
    """
    For some complex block types like images or other choosers, the block value is a string
    but the BoundBlock value is an object (in this case, an Image object).
    """
    indexer.index_page(home_page)
    index_entry = IndexEntry.objects.filter(block_name="image")[0]
    bound_block = index_entry.get_bound_block()

    assert isinstance(index_entry.block_value, str)
    assert isinstance(bound_block.value, get_image_model())
コード例 #3
0
def test_none_value(root_page):
    """
    Sometimes get_prep_value can return None. We need to make sure we're handling this case
    """
    body_data = [{"type": "image", "value": None}]
    stream_block = HomePage.body.field.stream_block
    home_page = HomePage(
        body=StreamValue(stream_block, [], is_lazy=True, raw_text=json.dumps(body_data)),
        title="Home Page",
        slug="homepage",
    )
    root_page.add_child(instance=home_page)
    home_page.refresh_from_db()

    indexer.index_page(home_page)

    assert IndexEntry.objects.count() == 1
コード例 #4
0
def test_index_one_page(many_pages):
    assert IndexEntry.objects.count() == 0
    indexer.index_page(many_pages[1].specific)

    # many_pages[1] contains only one block, so we expect one index
    assert IndexEntry.objects.count() == 1
コード例 #5
0
def test_list_block(home_page):
    indexer.index_page(home_page)
    assert IndexEntry.objects.filter(block_name="numbers").count() == 1
    assert IndexEntry.objects.filter(block_name="numbers:item").count() == 3
    assert IndexEntry.objects.filter(block_name="numbers:item")[0].block_value == "1"
コード例 #6
0
def test_index_block_field_name(home_page):
    indexer.index_page(home_page)
    assert IndexEntry.objects.all()[0].field_name == "body"
コード例 #7
0
def test_index_block_path(home_page):
    indexer.index_page(home_page)
    assert IndexEntry.objects.all()[0].block_path == "0/heading"
    assert IndexEntry.objects.all()[6].block_path == "5/author/name"
    assert IndexEntry.objects.all()[10].block_path == "5/author/body/1/paragraph"
コード例 #8
0
def test_index_block_type(home_page):
    indexer.index_page(home_page)
    assert IndexEntry.objects.filter(block_name="heading")[0].block_type == BlockTypes.OTHER
    assert IndexEntry.objects.filter(block_name="author")[0].block_type == BlockTypes.STRUCT
    assert IndexEntry.objects.filter(block_name="body")[0].block_type == BlockTypes.STREAM
コード例 #9
0
def test_index_block_name(home_page):
    indexer.index_page(home_page)
    assert IndexEntry.objects.all()[0].block_name == "heading"
    assert IndexEntry.objects.all()[1].block_name == "description"
    assert IndexEntry.objects.all()[2].block_name == "email"