def test_questionnaire_store_removes_completed_location(self):
     # Given
     expected = get_basic_input()
     store = QuestionnaireStore(self.storage)
     location = Location.from_dict(expected['COMPLETED_BLOCKS'][0])
     store.completed_blocks = [location]
     # When
     store.remove_completed_blocks(location=location)
     # Then
     self.assertEqual(store.completed_blocks, [])
 def test_questionnaire_store_raises_on_invalid_group_remove_completed_blocks_call(
         self):
     store = QuestionnaireStore(self.storage)
     location = Location('first-test-group', 0, 'a-test-block')
     location2 = Location('second-test-group', 0, 'a-test-block')
     store.completed_blocks = [
         location,
         location2,
     ]
     # When / Then
     with self.assertRaises(KeyError):
         store.remove_completed_blocks(block_id='a-test-block')
 def test_questionnaire_store_removes_completed_location_from_many(self):
     store = QuestionnaireStore(self.storage)
     location = Location('first-test-group', 0, 'a-test-block')
     location2 = Location('second-test-group', 0, 'a-test-block')
     store.completed_blocks = [
         location,
         location2,
     ]
     # When
     store.remove_completed_blocks(location=location)
     # Then
     self.assertEqual(store.completed_blocks, [location2])
    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 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_raises_on_invalid_location_remove_completed_blocks_call(
         self):
     store = QuestionnaireStore(self.storage)
     location = Location('first-test-group', 0, 'a-test-block')
     location2 = Location('second-test-group', 0, 'a-test-block')
     store.completed_blocks = [
         location,
         location2,
     ]
     # When / Then
     with self.assertRaises(TypeError):
         store.remove_completed_blocks(
             location={
                 'group_id': 'a-group',
                 'group_instance': 0,
                 'block-id': 'a-block-id'
             })
    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.completed_blocks = [
            Location.from_dict(expected['COMPLETED_BLOCKS'][0])
        ]

        # When / Then
        self.assertRaises(TypeError, store.add_or_update)
    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.answers = expected['ANSWERS']
        store.completed_blocks = [
            Location.from_dict(expected['COMPLETED_BLOCKS'][0])
        ]

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

        # Then
        self.assertEqual(store.completed_blocks, [])
        self.assertEqual(store.metadata.copy(), {})
        self.assertEqual(store.answer_store.count(), 0)
        self.assertEqual(store.collection_metadata, {})