Exemple #1
0
async def test_nimp():

    conf = """
BEGIN:
    - GET: /check
      tests:
        - status: 200

proc1: return x*"a"

val_bb: bb
v: 2

dua:
    root: http://machinedua.com

"""
    r = reqman.Reqman(conf)

    assert r.switchs == [("dua", "http://machinedua.com")]

    r.add("""
- call: BEGIN
- GET: /<<i>>
  tests:
    - status: 200
  foreach:
    - i: 1
    - i: 2
""")

    r.add("""
- GET: /<<v|proc1>>
  tests:
    - status: 200
- POST: /<<v|proc2>>
  tests:
    - status: 200
  params:
    proc2: return x*"a"
- PUT: /<<val_bb>>
  tests:
    - status: 200
""")
    mock = {
        "/": (200, "ok"),
        "/bb": (200, "ok"),
        "/aa": (200, "ok"),
        "/check": (200, "ok"),
        "/1": (200, "ok"),
        "/2": (200, "ok")
    }
    rr = await r.asyncExecute(paralleliz=True, http=mock)
    assert rr.code == 0

    ll = await r.asyncExecute(paralleliz=False, http=mock)
    assert rr.code == 0
Exemple #2
0
async def test_hermetic_env():

    r = reqman.Reqman(CONF)
    r.outputConsole = reqman.OutputConsole.FULL

    r.add("""
- GET: /<<token>>/a
  tests:
    - status: 200

- GET: /<<suite>>
  tests:
    - status: 404

- proc:
    - proc2:
        - GET: /value
          tests:
            - status: 200
          save: suite
        
        - GET: /<<suite>>
          tests:
            - status: 200
    - call: proc2

- call: proc

- GET: /<<suite>>
  tests:
    - status: 200

""")

    rr = await r.asyncExecute(paralleliz=False, http=MOCK)
    assert rr.code == 1  #1 error coz the 404 test is non playable
async def test_hermetic_env():
    MOCK = {"/pingpong": lambda m, p, b, h: (200, b)}

    r = reqman.Reqman()
    r.env["bytes"] = bytes(range(0, 255))

    r.outputConsole = reqman.OutputConsole.FULL
    r.add("""
- POST: /pingpong
  body: Hello World
  tests:
    - status: 200
    - content: Hello

- POST: /pingpong
  body:
    a:
        - 1
        - 2
    b: "hello"
  tests:
    - status: 200
    - content: hello
    - json.a.0: 1
    - json.a.1: 2
    - json.b: "hello"


- POST: /pingpong
  body: 42
  tests:
    - status: 200
    - content: 42




- POST: /pingpong
  tests:
    - status: 200
    - content: ""

- POST: /pingpong
  body: null
  tests:
    - status: 200
    - content: ""




- POST: /pingpong
  body: <<bytes>>
  tests:
    - status: 200
    - content: ABCDEF       # test repr

- POST: /pingpong
  body: <<bytes>>
  tests:
    - status: 200
    - content: <<bytes>>    # test real bytes




- POST: /pingpong
  body: <<|giveBytes>>
  tests:
    - status: 200
    - content: ABCDEF       # test repr
  params:
    giveBytes: return b"ABCDEF"

- POST: /pingpong
  body: <<|giveBytes>>
  tests:
    - status: 200
    - content: <<|giveBytes>>   # test real bytes
  params:
    giveBytes: return b"ABCDEF"    

""")

    rr = await r.asyncExecute(paralleliz=False, http=MOCK)
    assert rr.code == 0
    rr = await r.asyncExecute(paralleliz=True, http=MOCK)
    assert rr.code == 0