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() == ''
def test_cannot_add_duplicate_remote(tmpdir, settings, capsys): 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.json').check(file=True) old_mtime = remotes_dir.join('foo.json').mtime() capsys.readouterr() # Adding a remote with the same id and url should be ignored call_command( 'catalog', 'remotes', 'add', remote['id'], remote['name'], remote['url']) out, err = capsys.readouterr() assert out.strip() == '' assert err.strip() == 'This remote already exists, ignoring' # Adding a remote with a different id but the same url should fail with pytest.raises(CommandError) as excinfo: call_command( 'catalog', 'remotes', 'add', remote['id'] + '2', remote['name'], remote['url']) excinfo.match('A remote with this url already exists') assert remotes_dir.join('foo2.json').check(exists=False) # Adding a remote with the same id but a different url should fail with pytest.raises(CommandError) as excinfo: call_command( 'catalog', 'remotes', 'add', remote['id'], remote['name'], remote['url'] + "bad") excinfo.match('A remote with this id already exists') assert remotes_dir.join('foo.json').mtime() == old_mtime
def test_remove_remote(tmpdir, settings, capsys): 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 remotes_dir = Path(settings.CATALOG_STORAGE_ROOT).join('remotes') assert remotes_dir.check(dir=True) assert remotes_dir.listdir() == []
def test_add_remote(tmpdir, settings, capsys): remote_catalog_file = tmpdir.mkdir('source').join('catalog.yml') remote_catalog_file.write( 'all:\n foovideos:\n name: Videos from Foo') expected = { 'id': 'foo', 'name': 'Content from Foo', 'url': 'file://{}'.format(remote_catalog_file.strpath), } call_command( 'catalog', 'remotes', 'add', expected['id'], expected['name'], expected['url']) # Ensure the remote has been added remotes_dir = Path(settings.CATALOG_STORAGE_ROOT).join('remotes') assert remotes_dir.check(dir=True) assert remotes_dir.join('foo.json').check(file=True) with remotes_dir.join('foo.json').open('r') as f: assert json.load(f) == expected
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