Example #1
0
def test_deserialisation():
    in_progress_sections = [
        {
            "section_id": "s1",
            "list_item_id": None,
            "status": CompletionStatus.IN_PROGRESS,
            "block_ids": ["one", "two"],
        },
        {
            "section_id": "s2",
            "list_item_id": "abc123",
            "status": CompletionStatus.COMPLETED,
            "block_ids": ["three", "four"],
        },
    ]
    store = ProgressStore(in_progress_sections)

    assert store.get_section_status(section_id="s1") == CompletionStatus.IN_PROGRESS
    assert store.get_completed_block_ids("s1") == ["one", "two"]

    assert (
        store.get_section_status(section_id="s2", list_item_id="abc123")
        == CompletionStatus.COMPLETED
    )
    assert store.get_completed_block_ids(section_id="s2", list_item_id="abc123") == [
        "three",
        "four",
    ]
Example #2
0
def test_update_section_status():
    completed = [
        {
            "section_id": "s1",
            "list_item_id": None,
            "status": CompletionStatus.COMPLETED,
            "block_ids": ["one"],
        },
        {
            "section_id": "s2",
            "list_item_id": "abc123",
            "status": CompletionStatus.COMPLETED,
            "block_ids": ["three"],
        },
    ]
    store = ProgressStore(completed)

    store.update_section_status(
        section_status=CompletionStatus.IN_PROGRESS, section_id="s1"
    )
    store.update_section_status(
        section_status=CompletionStatus.IN_PROGRESS,
        section_id="s2",
        list_item_id="abc123",
    )

    assert store.get_section_status(section_id="s1") == CompletionStatus.IN_PROGRESS
    assert (
        store.get_section_status(section_id="s2", list_item_id="abc123")
        == CompletionStatus.IN_PROGRESS
    )
    assert store.is_dirty
Example #3
0
def test_get_section_status():
    existing_progress = [
        {
            "section_id": "s1",
            "list_item_id": None,
            "status": CompletionStatus.COMPLETED,
            "block_ids": ["one"],
        },
        {
            "section_id": "s2",
            "list_item_id": "abc123",
            "status": CompletionStatus.IN_PROGRESS,
            "block_ids": ["three"],
        },
    ]
    store = ProgressStore(existing_progress)

    assert store.get_section_status(section_id="s1") == CompletionStatus.COMPLETED
    assert (
        store.get_section_status(section_id="s2", list_item_id="abc123")
        == CompletionStatus.IN_PROGRESS
    )
Example #4
0
def test_add_completed_location_new():
    completed = [
        {
            "section_id": "s1",
            "list_item_id": None,
            "status": CompletionStatus.COMPLETED,
            "block_ids": ["one"],
        },
        {
            "section_id": "s2",
            "list_item_id": "abc123",
            "status": CompletionStatus.COMPLETED,
            "block_ids": ["three", "four"],
        },
    ]
    store = ProgressStore(completed)

    non_repeating_location = Location(section_id="s1", block_id="two")
    repeating_location = Location(
        section_id="s2", block_id="five", list_name="people", list_item_id="abc123"
    )

    store.add_completed_location(non_repeating_location)
    store.add_completed_location(repeating_location)

    assert store.get_section_status(section_id="s1") == CompletionStatus.COMPLETED
    assert (
        store.get_section_status(section_id="s2", list_item_id="abc123")
        == CompletionStatus.COMPLETED
    )

    assert len(store.get_completed_block_ids(section_id="s1")) == 2
    assert (
        len(store.get_completed_block_ids(section_id="s2", list_item_id="abc123")) == 3
    )

    assert store.is_dirty
Example #5
0
def test_update_non_existing_section_status():
    completed = [
        {
            "section_id": "s1",
            "list_item_id": None,
            "status": CompletionStatus.COMPLETED,
            "block_ids": ["one"],
        }
    ]
    store = ProgressStore(completed)

    store.update_section_status("s2", CompletionStatus.IN_PROGRESS)

    assert store.get_section_status("s1") == CompletionStatus.COMPLETED

    assert "s2" not in store
    assert store.get_completed_block_ids(section_id="s2") == []

    assert not store.is_dirty