Esempio n. 1
0
def test_move_remotes(tmpdir, settings, monkeypatch):
    remote_catalog_file = tmpdir.mkdir('source').join('catalog.yml')
    remote_catalog_file.write('all:\n  foovideos:\n    name: Videos from Foo')
    remote = {
        'id': 'foo',
        'name': 'Content from Foo',
        'url': 'file://{}'.format(remote_catalog_file.strpath),
    }

    call_command('catalog', 'remotes', 'add', remote['id'], remote['name'],
                 remote['url'])

    # Now move the remotes to the old location
    catalog_cache_dir = Path(settings.CATALOG_CACHE_ROOT)
    catalog_storage_dir = Path(settings.CATALOG_STORAGE_ROOT)

    catalog_storage_dir.join('remotes').move(catalog_cache_dir.join('remotes'))
    assert catalog_cache_dir.join('remotes', 'foo.yml').check(file=True)
    assert catalog_storage_dir.join('remotes').check(exists=False)

    # And check that it migrates properly
    call_command('catalog', 'cache', 'update')

    assert catalog_cache_dir.join('remotes').check(exists=False)
    assert catalog_storage_dir.join('remotes', 'foo.yml').check(file=True)
Esempio n. 2
0
def test_remove_remote(tmpdir, settings, capsys, monkeypatch):
    remote_catalog_file = tmpdir.mkdir('source').join('catalog.yml')
    remote_catalog_file.write('all:\n  foovideos:\n    name: Videos from Foo')

    remote = {
        'id': 'foo',
        'name': 'Content from Foo',
        'url': 'file://{}'.format(remote_catalog_file.strpath),
    }

    call_command('catalog', 'remotes', 'add', remote['id'], remote['name'],
                 remote['url'])
    call_command('catalog', 'remotes', 'remove', remote['id'])

    # Ensure the remote has been removed
    catalog_cache_dir = Path(settings.CATALOG_CACHE_ROOT)
    remotes_dir = Path(settings.CATALOG_STORAGE_ROOT).join('remotes')

    assert remotes_dir.check(dir=True)
    assert remotes_dir.listdir() == []

    # Ensure the cache has been updated
    assert catalog_cache_dir.join('catalog.yml').check(file=True)

    expected = {}

    with catalog_cache_dir.join('catalog.yml').open('r') as f:
        assert yaml.safe_load(f.read()) == expected

    out, err = capsys.readouterr()
    assert out.strip() == ''
    assert err.strip() == ''
Esempio n. 3
0
def test_update_cache_with_remote(tmpdir, settings, capsys, monkeypatch):
    remote_catalog_file = tmpdir.mkdir('source').join('catalog.yml')
    remote_catalog_file.write('all:\n  foovideos:\n    name: Videos from Foo')

    remote = {
        'id': 'foo',
        'name': 'Content from Foo',
        'url': 'file://{}'.format(remote_catalog_file.strpath),
    }

    call_command('catalog', 'remotes', 'add', remote['id'], remote['name'],
                 remote['url'])

    # Now let's say the remote published an update to their catalog
    remote_catalog_file = tmpdir.join('source', 'catalog.yml')
    remote_catalog_file.write(
        'all:\n  foovideos:\n    name: Great videos from Foo')

    call_command('catalog', 'cache', 'update')

    catalog_cache_dir = Path(settings.CATALOG_CACHE_ROOT)
    assert catalog_cache_dir.join('catalog.yml').check(file=True)

    expected = {'foovideos': {'name': 'Great videos from Foo'}}

    with catalog_cache_dir.join('catalog.yml').open('r') as f:
        assert yaml.safe_load(f.read()) == expected

    out, err = capsys.readouterr()
    assert out.strip() == ''
    assert err.strip() == ''
Esempio n. 4
0
def test_clear_cache(tmpdir, settings, capsys, monkeypatch):
    monkeypatch.setattr('ideascube.serveradmin.catalog.urlretrieve',
                        fake_urlretrieve)

    remote_catalog_file = tmpdir.mkdir('source').join('catalog.yml')
    remote_catalog_file.write('all:\n  foovideos:\n    name: Videos from Foo')

    remote = {
        'id': 'foo',
        'name': 'Content from Foo',
        'url': 'file://{}'.format(remote_catalog_file.strpath),
    }
    expected = {}

    call_command('catalog', 'remotes', 'add', remote['id'], remote['name'],
                 remote['url'])
    call_command('catalog', 'cache', 'update')

    call_command('catalog', 'cache', 'clear')

    catalog_cache_dir = Path(settings.CATALOG_CACHE_ROOT)
    assert catalog_cache_dir.join('catalog.yml').check(file=True)

    with catalog_cache_dir.join('catalog.yml').open('r') as f:
        assert yaml.safe_load(f.read()) == expected

    out, err = capsys.readouterr()
    assert out.strip() == ''
    assert err.strip() == ''
Esempio n. 5
0
def test_split_cache(tmpdir, settings, monkeypatch):
    monkeypatch.setattr('ideascube.serveradmin.catalog.urlretrieve',
                        fake_urlretrieve)

    remote_catalog_file = tmpdir.mkdir('source').join('catalog.yml')
    remote_catalog_file.write('all:\n  foovideos:\n    name: Videos from Foo')
    remote = {
        'id': 'foo',
        'name': 'Content from Foo',
        'url': 'file://{}'.format(remote_catalog_file.strpath),
    }

    call_command('catalog', 'remotes', 'add', remote['id'], remote['name'],
                 remote['url'])
    call_command('catalog', 'cache', 'update')

    # Now write the catalog cache in the old format
    old_cache = yaml.dump({
        'installed': {},
        'available': {
            'foovideos': {
                'name': 'Videos from Foo'
            }
        }
    })

    catalog_cache_dir = Path(settings.CATALOG_CACHE_ROOT)
    catalog_storage_dir = Path(settings.CATALOG_STORAGE_ROOT)

    catalog_cache_dir.join('catalog.yml').write(old_cache)
    catalog_storage_dir.join('installed.yml').remove()

    # And check that it migrates properly
    call_command('catalog', 'cache', 'update')

    expected = {
        'foovideos': {
            'name': 'Videos from Foo'
        },
    }
    assert yaml.safe_load(
        catalog_cache_dir.join('catalog.yml').read()) == expected
    assert yaml.safe_load(
        catalog_storage_dir.join('installed.yml').read()) == {}
Esempio n. 6
0
def test_update_cache_without_remote(tmpdir, settings, capsys):
    expected = {}

    call_command('catalog', 'cache', 'update')

    catalog_cache_dir = Path(settings.CATALOG_CACHE_ROOT)
    assert catalog_cache_dir.join('catalog.yml').check(file=True)

    with catalog_cache_dir.join('catalog.yml').open('r') as f:
        assert yaml.safe_load(f.read()) == expected

    out, err = capsys.readouterr()
    assert out.strip() == ''
    assert err.strip() == ''
Esempio n. 7
0
def test_cannot_add_duplicate_remote(tmpdir, settings, monkeypatch, capsys):
    monkeypatch.setattr('ideascube.serveradmin.catalog.urlretrieve',
                        fake_urlretrieve)

    remote_catalog_file = tmpdir.mkdir('source').join('catalog.yml')
    remote_catalog_file.write('all:\n  foovideos:\n    name: Videos from Foo')

    remote = {
        'id': 'foo',
        'name': 'Content from Foo',
        'url': 'file://{}'.format(remote_catalog_file.strpath),
    }

    call_command('catalog', 'remotes', 'add', remote['id'], remote['name'],
                 remote['url'])

    remotes_dir = Path(settings.CATALOG_STORAGE_ROOT).join('remotes')

    assert remotes_dir.check(dir=True)
    assert remotes_dir.join('foo.yml').check(file=True)

    old_mtime = remotes_dir.join('foo.yml').mtime()

    capsys.readouterr()

    # Adding the same remote with the same url should not fail.
    call_command('catalog', 'remotes', 'add', remote['id'], remote['name'],
                 remote['url'])

    out, _ = capsys.readouterr()
    assert out == 'Not adding already existing remote: "{}"\n'.format(
        remote['id'])

    # But should fail with different urls.
    with pytest.raises(CommandError):
        call_command('catalog', 'remotes', 'add', remote['id'], remote['name'],
                     remote['url'] + "bad")

    assert remotes_dir.join('foo.yml').mtime() == old_mtime