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)
Exemplo n.º 2
0
def test_is_buffer_valid_for_bucket():
    """
    def is_buffer_valid_for_bucket(self, collection_id, buffermode)
    """
    def set_revision_dict(helper, revision_dict, diff_dict):
        helper._get_revision_dict = lambda: revision_dict
        helper.deckhand.get_diff = lambda: diff_dict

    helper = ConfigdocsHelper(CTX)
    helper._get_revision_dict = lambda: REV_BUFFER_DICT
    helper.deckhand.get_diff = (
        lambda old_revision_id, new_revision_id: DIFF_BUFFER_DICT)
    helper.deckhand.rollback = lambda target_revision_id: (set_revision_dict(
        helper, REV_BUFF_EMPTY_DICT, DIFF_BUFF_EMPTY_DICT))
    # patch the deckhand client method to set to empty if reset_to_empty
    # is invoked.
    helper.deckhand.reset_to_empty = lambda: (set_revision_dict(
        helper, REV_EMPTY_DICT, DIFF_EMPTY_DICT))

    # can add 'mop' on append, it was unmodified in buffer
    # can add 'water' on append, it was not anywhere before
    # can't add 'slop' on append, it was deleted (modified in buffer)
    # can't add 'chum' on append, it is already in buffer
    # can't add anything on rejectoncontents
    # can add anything on replace
    assert helper.is_buffer_valid_for_bucket('mop', BufferMode.APPEND)
    assert helper.is_buffer_valid_for_bucket('water', BufferMode.APPEND)
    assert not helper.is_buffer_valid_for_bucket('slop', BufferMode.APPEND)
    assert not helper.is_buffer_valid_for_bucket('chum', BufferMode.APPEND)
    assert not helper.is_buffer_valid_for_bucket('new',
                                                 BufferMode.REJECTONCONTENTS)

    # because of the patched methods above, replace mode will set the
    # buffer/diff to values as if it were rolled back.
    assert helper.is_buffer_valid_for_bucket('mop', BufferMode.REPLACE)
    # should be able to replace mode even if no buffer contents.
    assert helper.is_buffer_valid_for_bucket('mop', BufferMode.REPLACE)
    # in rolled back state as per last two commands, should be ok
    # to use rejectoncontents to add.
    assert helper.is_buffer_valid_for_bucket('mop',
                                             BufferMode.REJECTONCONTENTS)

    # set up as if there is no committed revision yet
    helper._get_revision_dict = lambda: REV_NO_COMMIT_DICT
    helper.deckhand.get_diff = (
        lambda old_revision_id, new_revision_id: DIFF_NO_COMMIT_DICT)

    assert helper.is_buffer_valid_for_bucket('slop', BufferMode.APPEND)
    assert helper.is_buffer_valid_for_bucket('chum', BufferMode.APPEND)
    # buffer is not empty, reject on contents.
    assert not helper.is_buffer_valid_for_bucket('new',
                                                 BufferMode.REJECTONCONTENTS)

    # This should rollback to "nothing" using reset to empty.
    assert helper.is_buffer_valid_for_bucket('mop', BufferMode.REPLACE)
    assert helper.is_buffer_empty()

    # set up as if there is nothing in deckhand.
    helper._get_revision_dict = lambda: REV_EMPTY_DICT
    helper.deckhand.get_diff = (
        lambda old_revision_id, new_revision_id: DIFF_EMPTY_DICT)
    # should be able to add in any mode.
    assert helper.is_buffer_valid_for_bucket('slop', BufferMode.APPEND)
    assert helper.is_buffer_valid_for_bucket('chum', BufferMode.APPEND)
    assert helper.is_buffer_valid_for_bucket('new',
                                             BufferMode.REJECTONCONTENTS)
    assert helper.is_buffer_valid_for_bucket('mop', BufferMode.REPLACE)