Beispiel #1
0
def test_BSConfig_badoscrc(oscrc_nouser):

    with pytest.raises(ValueError):
        cfg = BSConfig(**{"https://api.foo.net/" : {"bar" : 42}})
    
    with pytest.raises(ValueError):
        cfg = BSConfig.fromoscrc(path=oscrc_nouser)
Beispiel #2
0
def test_BSConfig_fromoscrc(oscrc):
    cfg = BSConfig.fromoscrc(path=oscrc)
    assert 'general' in cfg

    for apiurl in cfg.apiurls():
        assert cfg[apiurl].user == "joe"
        assert cfg[apiurl].pswd == "doe"
Beispiel #3
0
def test_BSConfig_advanced():

    global CFG_DICT
    cfg = BSConfig(**CFG_DICT)
    assert "general" in cfg
    #TODO: does osc some url normalization?
    assert "https://api.suse.de/" not in cfg
    assert "https://api.suse.de" in cfg
    assert "https://api.opensuse.org/" in cfg
Beispiel #4
0
def test_BSConfig_for_apiurl():
    
    global CFG_DICT
    cfg = BSConfig(**CFG_DICT)

    with pytest.raises(ValueError):
        ocfg = cfg.for_apiurl("https://api.opensuse.org")
    
    ocfg = cfg.for_apiurl("https://api.opensuse.org/")
    assert cfg != ocfg
    assert cfg.items() != ocfg.items()
    assert set(ocfg.items()) == \
        {('pswd', "joes's passwd"), ('apiurl', 'https://api.opensuse.org/'), ('pass', 'bar'), ('passx', 'ham'), ('user', 'joe')}
    
    icfg = cfg.for_apiurl("https://api.suse.de")
    assert cfg != icfg
    assert ocfg != icfg
    assert ocfg.items() != icfg.items()
    assert icfg.apiurl == "https://api.suse.de"
Beispiel #5
0
def test_BSConfig_basic():
    foo = BSConfig(a=11)
    assert foo.a == 11
    assert hasattr(foo, "a")
    assert getattr(foo, "a") == 11
    assert foo["a"] == 11
    assert len(foo) == 1
    assert "a" in foo

    for k, v in foo.items():
        assert k == "a"
        assert v == 11

    for v in foo.values():
        assert v == 11

    for k in foo.keys():
        assert k == "a"

    assert type(foo.__iter__()) == type({}.__iter__())
Beispiel #6
0
def test_BSConfig_badperms(oscrc_badperm):

    with pytest.raises(Exception):
        cfg = BSConfig.fromoscrc(path=oscrc_badperm)
Beispiel #7
0
    #monkeys, monkeys!
    old_raw = bslib.raw.raw

    def raw(ctx, method, url, datafp=None):
        if method == "POST":
            return method, url, datafp
        return method, url

    bslib.raw.raw = raw
    yield

    bslib.raw.raw = old_raw
    del raw


cfg = BSConfig(**CFG_DICT)
ctx = BSContext(cfg.for_apiurl("https://api.opensuse.org/"))


def test_basic_requests(raw_return_string):
    """
    due the fact all basic requests, which are decorated through @api are empty,
    let test only a few of them
    """

    global ctx
    apiurl = ctx.apiurl

    assert GET_request_id(ctx, 11) == ("GET", "{}/request/11".format(apiurl))
    #it is OK to pass an incorrect argument, as functions does not do any checking
    assert GET_request_id(ctx,
Beispiel #8
0
 def fromoscrc(cls, apiurl, path=None):
     """Load context from oscrc and setup the logger properly"""
     from bslib.config import BSConfig
     #TODO: logger handling
     return cls(config=BSConfig.fromoscrc(path).for_apiurl(apiurl),
                logger=None)
Beispiel #9
0
 def fromoscrc(cls, apiurl, path=None):
     """Load context from oscrc and setup the logger properly"""
     from bslib.config import BSConfig
     #TODO: logger handling
     return cls(config=BSConfig.fromoscrc(path).for_apiurl(apiurl), logger=None)
Beispiel #10
0
@pytest.yield_fixture
def raw_return_string():
    #monkeys, monkeys!
    old_raw = bslib.raw.raw
    def raw(ctx, method, url, datafp=None):
        if method == "POST":
            return method, url, datafp
        return method, url
    bslib.raw.raw = raw
    yield

    bslib.raw.raw = old_raw
    del raw

cfg = BSConfig(**CFG_DICT)
ctx = BSContext(cfg.for_apiurl("https://api.opensuse.org/"))

def test_basic_requests(raw_return_string):
    """
    due the fact all basic requests, which are decorated through @api are empty,
    let test only a few of them
    """

    global ctx
    apiurl = ctx.apiurl

    assert GET_request_id(ctx, 11) == ("GET", "{}/request/11".format(apiurl))
    #it is OK to pass an incorrect argument, as functions does not do any checking
    assert GET_request_id(ctx, "joe") == ("GET", "{}/request/joe".format(apiurl))
    #tests POST