예제 #1
0
def test_questionnaire_store_updates_storage(questionnaire_store, basic_input):
    # Given
    store = QuestionnaireStore(questionnaire_store.storage)
    store.set_metadata(basic_input["METADATA"])
    store.answer_store = AnswerStore(basic_input["ANSWERS"])
    store.response_metadata = basic_input["RESPONSE_METADATA"]
    store.progress_store = ProgressStore(basic_input["PROGRESS"])

    # When
    store.save()

    # Then
    assert basic_input == json_loads(questionnaire_store.output_data)
    def test_questionnaire_store_updates_storage(self):
        # Given
        expected = get_basic_input()
        store = QuestionnaireStore(self.storage)
        store.set_metadata(expected["METADATA"])
        store.answer_store = AnswerStore(expected["ANSWERS"])
        store.collection_metadata = expected["COLLECTION_METADATA"]
        store.progress_store = ProgressStore(expected["PROGRESS"])

        # When
        store.save()  # See setUp - populates self.output_data

        # Then
        self.assertEqual(expected, json.loads(self.output_data))
예제 #3
0
def test_questionnaire_store_errors_on_invalid_object(questionnaire_store,
                                                      basic_input):
    # Given
    class NotSerializable:
        pass

    non_serializable_metadata = {"test": NotSerializable()}

    store = QuestionnaireStore(questionnaire_store.storage)
    store.set_metadata(non_serializable_metadata)
    store.response_metadata = basic_input["RESPONSE_METADATA"]
    store.answer_store = AnswerStore(basic_input["ANSWERS"])
    store.progress_store = ProgressStore(basic_input["PROGRESS"])

    # When / Then
    with pytest.raises(TypeError):
        store.save()