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",
                                         ]
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
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)
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
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
Example #6
0
    def test_remove_answer_and_block_if_routing_backwards(self):
        schema = load_schema_from_name("test_confirmation_question")
        section_id = schema.get_section_id_for_block_id(
            "confirm-zero-employees-block")

        # All blocks completed
        progress_store = ProgressStore([{
            "section_id":
            "default-section",
            "list_item_id":
            None,
            "status":
            CompletionStatus.COMPLETED,
            "block_ids": [
                "number-of-employees-total-block",
                "confirm-zero-employees-block",
            ],
        }])

        answer_store = AnswerStore()
        number_of_employees_answer = Answer(
            answer_id="number-of-employees-total", value=0)
        confirm_zero_answer = Answer(answer_id="confirm-zero-employees-answer",
                                     value="No I need to change this")
        answer_store.add_or_update(number_of_employees_answer)
        answer_store.add_or_update(confirm_zero_answer)

        path_finder = PathFinder(
            schema,
            answer_store,
            self.list_store,
            progress_store,
            self.metadata,
            self.response_metadata,
        )

        self.assertEqual(
            len(
                path_finder.progress_store.get_completed_block_ids(
                    section_id="default-section")),
            2,
        )
        self.assertEqual(len(path_finder.answer_store), 2)

        routing_path = path_finder.routing_path(section_id=section_id)

        expected_path = RoutingPath(
            [
                "number-of-employees-total-block",
                "confirm-zero-employees-block",
                "number-of-employees-total-block",
            ],
            section_id="default-section",
        )
        self.assertEqual(routing_path, expected_path)

        self.assertEqual(
            path_finder.progress_store.get_completed_block_ids(
                section_id="default-section"),
            [
                progress_store.get_completed_block_ids(
                    section_id="default-section")[0]
            ],
        )
        self.assertEqual(len(path_finder.answer_store), 1)
        self.assertFalse(
            path_finder.answer_store.get_answer(
                "confirm-zero-employees-answer"))
        self.assertEqual(
            progress_store.get_section_status(section_id="default-section"),
            CompletionStatus.IN_PROGRESS,
        )