def test_questionnaire_store_errors_on_invalid_object(self):
        # Given
        class NotSerializable():
            pass

        expected = get_basic_input()
        store = QuestionnaireStore(self.storage)
        store.metadata = NotSerializable()
        store.answer_store.answers = expected['ANSWERS']
        store.completed_blocks = [
            Location.from_dict(expected['COMPLETED_BLOCKS'][0])
        ]

        # When / Then
        self.assertRaises(TypeError, store.add_or_update)
    def test_questionnaire_store_updates_storage(self):
        # Given
        expected = get_basic_input()
        store = QuestionnaireStore(self.storage)
        store.metadata = expected['METADATA']
        store.answer_store.answers = expected['ANSWERS']
        store.completed_blocks = [
            Location.from_dict(expected['COMPLETED_BLOCKS'][0])
        ]

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

        # Then
        self.assertEqual(expected, json.loads(self.output_data))
def fake_questionnaire_store(fake_metadata, fake_collection_metadata):
    user_answer = Answer(answer_id="GHI", value=0, list_item_id=None)

    storage = MagicMock()
    storage.get_user_data = MagicMock(return_value=("{}", 1))
    storage.add_or_update = MagicMock()

    store = QuestionnaireStore(storage)

    store.answer_store = AnswerStore()
    store.answer_store.add_or_update(user_answer)
    store.metadata = fake_metadata
    store.collection_metadata = fake_collection_metadata

    return store