def test_post_collection_not_valid_for_buffer(self):
     """
     Tests the post collection method of the ConfigdocsResource
     """
     helper = None
     collection_id = 'trees'
     document_data = 'lots of info'
     with pytest.raises(ApiError) as apie:
         cdr = ConfigDocsResource()
         helper = ConfigdocsHelper(CTX)
         # not valid for bucket
         helper.get_deckhand_validation_status = (
             lambda a: configdocs_helper._format_validations_to_status([], 0
                                                                       ))
         cdr.post_collection(helper=helper,
                             collection_id=collection_id,
                             document_data=document_data)
     assert apie.value.status == '409 Conflict'
    def test_post_collection(self):
        """
        Tests the post collection method of the ConfigdocsResource
        """
        helper = None
        collection_id = 'trees'
        document_data = 'lots of info'
        with patch.object(ConfigdocsHelper, 'add_collection') as mock_method:
            cdr = ConfigDocsResource()
            helper = ConfigdocsHelper(CTX)
            helper.is_buffer_valid_for_bucket = lambda a, b: True
            helper.get_deckhand_validation_status = (
                lambda a: configdocs_helper._format_validations_to_status([], 0
                                                                          ))
            cdr.post_collection(helper=helper,
                                collection_id=collection_id,
                                document_data=document_data)

        mock_method.assert_called_once_with(collection_id, document_data)
    def test_post_collection_not_added(self):
        """
        Tests the post collection method of the ConfigdocsResource
        """
        helper = None
        collection_id = 'trees'
        document_data = 'lots of info'
        with patch.object(ConfigdocsHelper, 'add_collection') as mock_method:
            cdr = ConfigDocsResource()
            helper = ConfigdocsHelper(CTX)
            helper.get_deckhand_validation_status = (
                lambda a: configdocs_helper._format_validations_to_status([], 0
                                                                          ))
            with pytest.raises(ApiError) as apie:
                cdr.post_collection(helper=helper,
                                    collection_id=collection_id,
                                    document_data=document_data)

            assert apie.value.status == '400 Bad Request'
        mock_method.assert_called_once_with(collection_id, document_data)