Example #1
0
def test_basic_build():
    fixtures = path.join(fixtures_base, 'builder')
    base = path.join(fixtures, 'base')
    output = path.join(fixtures, 'output')
    index = path.join(fixtures, 'output', 'en', 'index.html')
    expected_output = path.join(fixtures, 'output_basic')
    if path.exists(output):
        rmtree(output)

    # Build normally
    Builder(base_directory=base, output_path=output, quiet=True)

    _compare_trees(output, expected_output)
    _compare_html_parts(output, expected_output)

    # Check changes aren't updated
    # Set far future modified time
    future = 2000000000
    utime(index, (future, future))
    Builder(base_directory=base, output_path=output, quiet=True)
    # Check it hasn't been modified
    assert path.getmtime(index) == future

    # Check we can force updates
    Builder(base_directory=base, output_path=output, force=True, quiet=True)
    # Check it's been modified now
    assert path.getmtime(index) < future

    _compare_trees(output, expected_output)
    _compare_html_parts(output, expected_output)

    rmtree(output)
Example #2
0
def test_tag_manager():
    fixtures = path.join(fixtures_base, 'builder')
    base = path.join(fixtures, 'base')
    output = path.join(fixtures, 'output')
    index_filepath = path.join(fixtures, 'output', 'en', 'index.html')

    if path.exists(output):
        rmtree(output)

    Builder(base_directory=base,
            output_path=output,
            tag_manager_code='GTM_654321',
            quiet=True)

    with open(index_filepath) as index_file:
        index_content = index_file.read()
        assert 'googletagmanager.com' in index_content
        assert 'GTM_654321' in index_content

    rmtree(output)

    Builder(base_directory=base, output_path=output, quiet=True)

    with open(index_filepath) as index_file:
        index_content = index_file.read()
        assert 'googletagmanager.com' not in index_content
        assert 'GTM_654321' not in index_content

    rmtree(output)
Example #3
0
def test_search():
    base = path.join(fixtures_base, 'builder', 'base')
    output = path.join(fixtures_base, 'builder', 'output')
    expected_output = path.join(fixtures_base, 'builder', 'output_search')
    if path.exists(output):
        rmtree(output)

    Builder(base_directory=base,
            output_path=output,
            search_url='https://example.com/search',
            search_placeholder='Placeholder text',
            search_domains=['one.example.com', 'two.example.com/path'],
            quiet=True)

    # Check the output file structure is as expected
    _compare_trees(output, expected_output)

    # Compare search HTML
    output_index = path.join(output, 'en/index.html')
    expected_index = path.join(expected_output, 'en/index.html')

    with open(output_index, encoding="utf-8") as output_file:
        output_soup = BeautifulSoup(output_file.read(), 'html.parser')
    with open(expected_index, encoding="utf-8") as expected_file:
        expected_soup = BeautifulSoup(expected_file.read(), 'html.parser')

    output_search = output_soup.select('form#search')[0]
    expected_search = expected_soup.select('form#search')[0]

    assert output_search == expected_search

    rmtree(output)
Example #4
0
def test_versions():
    fixtures = path.join(fixtures_base, 'builder')
    base = path.join(fixtures, 'base-repo')
    output = path.join(fixtures, 'output')
    expected_output = path.join(fixtures, 'output_versions')

    # make sure things don't exist
    if path.exists(output):
        rmtree(output)
    if path.exists(base):
        rmtree(base)

    # Clone repository and pull down all branches
    repo = Repo.clone_from(('https://github.com/CanonicalLtd/'
                            'documentation-builder-test-builder-repo.git'),
                           base)
    origin = repo.remotes.origin
    repo.create_head('1.0', origin.refs['1.0'])
    repo.create_head('latest', origin.refs['latest'])

    Builder(base_directory=base,
            output_path=output,
            build_version_branches=True,
            quiet=True)

    _compare_trees(output, expected_output)
    _compare_html_parts(output, expected_output)

    rmtree(output)
    rmtree(base)
Example #5
0
def test_no_metadata():
    base = path.join(fixtures_base, 'builder', 'no-metadata')
    output = path.join(fixtures_base, 'builder', 'output')

    if path.exists(output):
        rmtree(output)

    with raises(SystemExit):
        Builder(base_directory=base, output_path=output, quiet=True)

    assert not path.exists(output)
Example #6
0
def test_quiet():
    fixtures = path.join(fixtures_base, 'builder')
    base = path.join(fixtures, 'base')
    output = path.join(fixtures, 'output')

    if path.exists(output):
        rmtree(output)

    mock_out = StringIO()
    mock_err = StringIO()

    Builder(
        base_directory=base,
        output_path=output,
        out=mock_out,
        err=mock_err,
    )

    assert mock_out.getvalue() > ''
    assert mock_err.getvalue() == ''

    mock_out = StringIO()
    mock_err = StringIO()

    Builder(
        base_directory=base,
        output_path=output,
        quiet=True,
        out=mock_out,
        err=mock_err,
    )

    assert mock_out.getvalue() == ''
    assert mock_err.getvalue() == ''

    rmtree(output)
Example #7
0
def test_no_media():
    fixtures = path.join(fixtures_base, 'builder')
    base = path.join(fixtures, 'base-no-media')
    output = path.join(fixtures, 'output')
    expected_output = path.join(fixtures, 'output_no_media')
    if path.exists(output):
        rmtree(output)

    # Build normally
    Builder(base_directory=base, output_path=output, quiet=True)

    _compare_trees(output, expected_output)
    _compare_html_parts(output, expected_output)

    rmtree(output)
Example #8
0
def test_media_url():
    base = path.join(fixtures_base, 'builder', 'base')
    output = path.join(fixtures_base, 'builder', 'output')
    expected_output = path.join(fixtures_base, 'builder', 'output_media_url')
    if path.exists(output):
        rmtree(output)

    Builder(base_directory=base,
            media_url='/static/media',
            output_path=output,
            quiet=True)

    _compare_trees(output, expected_output)
    _compare_html_parts(output, expected_output)

    rmtree(output)
Example #9
0
def test_source_folder():
    base = path.join(fixtures_base, 'builder', 'base-source-folder')
    output = path.join(fixtures_base, 'builder', 'output')
    expected_output = path.join(fixtures_base, 'builder', 'output_basic')
    if path.exists(output):
        rmtree(output)

    Builder(base_directory=base,
            source_folder='./src',
            output_path=output,
            quiet=True)

    _compare_trees(output, expected_output)
    _compare_html_parts(output, expected_output)

    rmtree(output)
Example #10
0
def test_output_media_path():
    base = path.join(fixtures_base, 'builder', 'base')
    output = path.join(fixtures_base, 'builder', 'output')
    output_media_path = path.join(fixtures_base, 'builder', 'output', 'files',
                                  'media')
    expected_output = path.join(fixtures_base, 'builder', 'output_media_path')
    if path.exists(output):
        rmtree(output)

    Builder(base_directory=base,
            output_path=output,
            output_media_path=output_media_path,
            quiet=True)

    _compare_trees(output, expected_output)
    _compare_html_parts(output, expected_output)

    rmtree(output)
Example #11
0
def test_custom_template():
    base = path.join(fixtures_base, 'builder', 'base')
    output = path.join(fixtures_base, 'builder', 'output')
    template_path = path.join(fixtures_base, 'builder', 'template.jinja2')
    expected_output = path.join(fixtures_base, 'builder',
                                'output_custom_template')
    if path.exists(output):
        rmtree(output)

    Builder(base_directory=base,
            output_path=output,
            template_path=template_path,
            quiet=True)

    _compare_trees(output, expected_output)
    _compare_html_parts(output, expected_output)

    rmtree(output)
Example #12
0
def test_missing_base():
    # Build normally
    with raises(FileNotFoundError):
        Builder(base_directory='/a/non/existent/base',
                output_path='doesnt/matter',
                quiet=True)