def test_fetch_include_missing_namespace():
    url = 'http://example.com/project.yml'
    cache = mock.create_autospec(ConfigCache)
    cache.get.return_value = {}
    with pytest.raises(ConfigError) as exc:
        includes.fetch_include(cache, url)
    expected = "Configuration %s requires a namespace" % url
    assert expected in str(exc.exconly())
def test_fetch_include_missing_namespace():
    url = 'http://example.com/project.yml'
    cache = mock.create_autospec(ConfigCache)
    cache.get.return_value = {}
    with pytest.raises(ConfigError) as exc:
        includes.fetch_include(cache, url)
    expected = "Configuration %s requires a namespace" % url
    assert expected in str(exc.exconly())
def test_fetch_include():
    url = 'http://example.com/project.yml'
    fetch_func = mock.Mock(side_effect=[
        {
            'namespace': 'a',
            'include': ['b', 'c'],
            'a.web': {'image': 'a', 'links': ['b.web', 'c.web', 'a.db']},
            'a.db': {'image': 'db'},
        },
        {
            'namespace': 'b',
            'include': ['c'],
            'b.web': {'image': 'b', 'links': ['c.web']},
        },
        {
            'namespace': 'c',
            'c.web': {'image': 'c'},
        },
    ])
    cache = ConfigCache(fetch_func)
    config = includes.fetch_include(cache, url)
    expected = {
        'a.web': {'image': 'a', 'links': ['b.web', 'c.web', 'a.db']},
        'a.db':  {'image': 'db'},
        'b.web': {'image': 'b', 'links': ['c.web']},
        'c.web': {'image': 'c'},
    }
    assert config == expected
def test_fetch_include():
    url = 'http://example.com/project.yml'
    fetch_func = mock.Mock(side_effect=[
        {
            'namespace': 'a',
            'include': ['b', 'c'],
            'a.web': {
                'image': 'a',
                'links': ['b.web', 'c.web', 'a.db']
            },
            'a.db': {
                'image': 'db'
            },
        },
        {
            'namespace': 'b',
            'include': ['c'],
            'b.web': {
                'image': 'b',
                'links': ['c.web']
            },
        },
        {
            'namespace': 'c',
            'c.web': {
                'image': 'c'
            },
        },
    ])
    cache = ConfigCache(fetch_func)
    config = includes.fetch_include(cache, url)
    expected = {
        'a.web': {
            'image': 'a',
            'links': ['b.web', 'c.web', 'a.db']
        },
        'a.db': {
            'image': 'db'
        },
        'b.web': {
            'image': 'b',
            'links': ['c.web']
        },
        'c.web': {
            'image': 'c'
        },
    }
    assert config == expected