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))
def test_questionnaire_store_errors_on_invalid_object(self): # Given class NotSerializable: pass non_serializable_metadata = {"test": NotSerializable()} expected = get_basic_input() store = QuestionnaireStore(self.storage) store.set_metadata(non_serializable_metadata) store.collection_metadata = expected["COLLECTION_METADATA"] store.answer_store = AnswerStore(expected["ANSWERS"]) store.progress_store = ProgressStore(expected["PROGRESS"]) # When / Then self.assertRaises(TypeError, store.save)
def test_questionnaire_store_deletes(self): # Given expected = get_basic_input() store = QuestionnaireStore(self.storage) store.set_metadata(expected["METADATA"]) store.collection_metadata = expected["COLLECTION_METADATA"] store.answer_store = AnswerStore(expected["ANSWERS"]) store.progress_store = ProgressStore(expected["PROGRESS"]) # When store.delete() # See setUp - populates self.output_data # Then self.assertNotIn("a-test-section", store.progress_store) self.assertEqual(store.metadata.copy(), {}) self.assertEqual(len(store.answer_store), 0) self.assertEqual(store.collection_metadata, {})