Beispiel #1
0
    def assert_storage_size(cls, size):
        """Compare content count stored in database."""

        try:
            assert size == len(Database.get_collection())
        except AssertionError:
            print('database contains {} contents when expected size was {}'.
                  format(len(Database.get_collection()), size))
            raise AssertionError
Beispiel #2
0
def _import_content_mkdn(snippy, mocker, contents, timestamps):
    """Import requested Markdown content."""

    mocker.patch.object(Config, 'utcnow', side_effect=timestamps)
    start = len(Database.get_collection()) + 1
    with mock.patch('snippy.content.migrate.os.path.isfile',
                    return_value=True):
        for idx, content in enumerate(contents, start=start):
            file_content = mocker.mock_open(
                read_data=_get_template_mkdn(content))
            mocker.patch('snippy.content.migrate.open',
                         file_content,
                         create=True)
            cause = snippy.run(['snippy', 'import', '-f', 'content.mkdn'])
            assert cause == Cause.ALL_OK
            assert len(Database.get_collection()) == idx
Beispiel #3
0
    def assert_storage(cls, content):
        """Compare content stored in database.

        The assert comparisons use equality implemented for collection data
        class. This quarantees that the count and content of resources are
        the same in database and expected content.

        If the result and expected content are compared only as collections,
        there are cases that are not noticed. A content fields in collection
        are for example sorted and trimmed in some cases. The given content
        dictionary format from test cases must be set correctly in order to
        keep the content definitions in test correct. Because of this, the
        content must be compared also in dictionary format.

        The original content must not be changed because it is in most cases
        default content shared between all tests.

        Args:
            content (dict): Excepted content compared against database.
        """

        if not content:
            assert not Database.get_collection()

            return

        result_collection = Database.get_collection()
        result_dictionary = cls._get_db_dictionary(result_collection)
        expect_collection = cls._get_expect_collection(content)
        expect_dictionary = content
        try:
            assert result_collection == expect_collection
            assert result_dictionary == expect_dictionary
        except AssertionError:
            Content._print_assert(result_collection, expect_collection)
            Content._print_assert(result_dictionary, expect_dictionary)
            raise AssertionError