def test_fetch_www_struct_generic(monkeypatch, fake_request): monkeypatch.setattr(request, 'urlopen', fake_request) for asy in [True, False]: assert fetch_www_struct('', as_yaml=asy) is None assert fetch_www_struct('""', as_yaml=asy) == '' assert fetch_www_struct('"test"', as_yaml=asy) == 'test'
def _nodelist_fetch(ff): ''' Determines if ``--nodelist`` was a file or a url, and tries to fetch it. Validates nodelist to be json and to have the *version*, *nodes* and *updated_at* keys. :param ff: running :class:`ffflash.main.FFFlash` instance :return: the unpickled nodelist or ``False``/``None`` on error ''' if not ff.access_for('nodelist'): return False ff.log('fetching nodelist {}'.format(ff.args.nodelist)) nodelist = (load_file(ff.args.nodelist, fallback=None, as_yaml=False) if check_file_location(ff.args.nodelist, must_exist=True) else fetch_www_struct( ff.args.nodelist, fallback=None, as_yaml=False)) if not nodelist or not isinstance(nodelist, dict): return ff.log('could not fetch nodelist {}'.format(ff.args.nodelist), level=False) if not all([(a in nodelist) for a in ['version', 'nodes', 'updated_at']]): return ff.log('this is no nodelist {}'.format(ff.args.nodelist), level=False) ff.log('successfully fetched nodelist from {}'.format(ff.args.nodelist)) return nodelist
def _nodelist_fetch(ff): ''' Determines if ``--nodelist`` was a file or a url, and tries to fetch it. Validates nodelist to be json and to have the *version*, *nodes* and *updated_at* keys. :param ff: running :class:`ffflash.main.FFFlash` instance :return: the unpickled nodelist or ``False``/``None`` on error ''' if not ff.access_for('nodelist'): return False ff.log('fetching nodelist {}'.format(ff.args.nodelist)) nodelist = ( load_file(ff.args.nodelist, fallback=None, as_yaml=False) if check_file_location(ff.args.nodelist, must_exist=True) else fetch_www_struct(ff.args.nodelist, fallback=None, as_yaml=False) ) if not nodelist or not isinstance(nodelist, dict): return ff.log( 'could not fetch nodelist {}'.format(ff.args.nodelist), level=False ) if not all([(a in nodelist) for a in ['version', 'nodes', 'updated_at']]): return ff.log( 'this is no nodelist {}'.format(ff.args.nodelist), level=False ) ff.log('successfully fetched nodelist from {}'.format(ff.args.nodelist)) return nodelist
def test_fetch_www_struct_load(monkeypatch, fake_request): monkeypatch.setattr(request, 'urlopen', fake_request) for dt in [ 'test', 23, [42, None], True, {"a": "b"}, {"c": {"d": 0}} ]: for asy, df in [(True, y_dump), (False, j_dump)]: assert fetch_www_struct(df(dt), as_yaml=asy) == dt
def test_fetch_www_struct_fallback(): for wu in ['', '2342', '/']: for fb in [None, True, False, 'wrong', {}, [], [1, 2, 3]]: assert fetch_www_struct(wu, fallback=fb) == fb