Exemple #1
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"
Exemple #2
0
    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))
Exemple #3
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
    assert POST_request_id_cmddiff(ctx, 11) == ("POST", "{}/request/11?cmd=diff".format(apiurl), None)