view tests/test_sources_posts.py @ 853:f070a4fc033c

core: Continue PieCrust3 refactor, simplify pages. The asset pipeline is still the only function pipeline at this point. * No more `QualifiedPage`, and several other pieces of code deleted. * Data providers are simpler and more focused. For instance, the page iterator doesn't try to support other types of items. * Route parameters are proper known source metadata to remove the confusion between the two. * Make the baker and pipeline more correctly manage records and record histories. * Add support for record collapsing and deleting stale outputs in the asset pipeline.
author Ludovic Chabant <ludovic@chabant.com>
date Sun, 21 May 2017 00:06:59 -0700
parents e7b865f8f335
children 45ad976712ec
line wrap: on
line source

import pytest
from .mockutil import mock_fs, mock_fs_scope


@pytest.mark.parametrize('fs_fac, src_type, expected_paths, expected_metadata', [
        (lambda: mock_fs(), 'flat', [], []),
        (lambda: mock_fs().withPage('test/2014-01-01_foo.md'),
            'flat',
            ['2014-01-01_foo.md'],
            [(2014, 1, 1, 'foo')]),
        (lambda: mock_fs(), 'shallow', [], []),
        (lambda: mock_fs().withPage('test/2014/01-01_foo.md'),
            'shallow',
            ['2014/01-01_foo.md'],
            [(2014, 1, 1, 'foo')]),
        (lambda: mock_fs(), 'hierarchy', [], []),
        (lambda: mock_fs().withPage('test/2014/01/01_foo.md'),
            'hierarchy',
            ['2014/01/01_foo.md'],
            [(2014, 1, 1, 'foo')]),
        ])
def test_post_source_factories(fs_fac, src_type, expected_paths,
                               expected_metadata):
    fs = fs_fac()
    fs.withConfig({
        'site': {
            'sources': {
                'test': {'type': 'posts/%s' % src_type}},
            'routes': [
                {'url': '/%slug%', 'source': 'test'}]
            }
        })
    fs.withDir('kitchen/test')
    with mock_fs_scope(fs):
        app = fs.getApp(cache=False)
        s = app.getSource('test')
        facs = list(s.buildPageFactories())
        paths = [f.rel_path for f in facs]
        assert paths == expected_paths
        metadata = [
                (f.metadata['year'], f.metadata['month'],
                    f.metadata['day'], f.metadata['slug'])
                for f in facs]
        assert metadata == expected_metadata