Skip to content

Instantly share code, notes, and snippets.

@kwatch
Last active August 29, 2015 14:03
Show Gist options
  • Select an option

  • Save kwatch/537dd70c4c863747b331 to your computer and use it in GitHub Desktop.

Select an option

Save kwatch/537dd70c4c863747b331 to your computer and use it in GitHub Desktop.
Oktest 0.15.0 変更点
  • [enhance] oktest.web.WSGITestクラスが、マルチパート形式をサポート ex:

    ## マルチパート形式のデータを作成
    from oktest.web import MultiPart
    mp = MultiPart()    # or boundary='abcdef'; mp = MutliPart(boundary)
    mp.add("name1", "value1")          # add string value
    with open("logo.png", 'wb') as f:  # add file value
        mp.add("file1", f.read(), "logo.png", "image/png")
    ## マルチパートデータを指定してリクエストを投げる
    from oktest.web import WSGITest
    http = WSGITest(wsgi_app)
    resp = http.POST('/upload', multipart=mp)  # or params=mp
    ok (resp).is_response(200)
    
  • [enhance] oktest.web.WSGITestクラスが、CookieヘッダとSet-Cookieヘッダをサポート ex:

    from oktest.web import WSGITest
    http = WSGITest(wsgi_app)
    ## リクエスト: Cookieヘッダ
    resp = http.GET('/', cookies='name=value')  # or cookies={'name':'value'}
    ## レスポンス: Set-Cookieヘッダ
    ok (resp).is_response(200).cookie('name', 'value')
    ok (resp).is_response(200).cookie('name', re.compile(r'^value$'),
                                      domain='www.example.com',
                                      path='/cgi'
                                      expires='Wed, 01-Jan-2020 12:34:56 GMT',
                                      max_age='1200',
                                      secure=True,
                                      httponly=True)
    
  • [enhance] アサーションメソッドを新規に追加 ex:

    ok (xs).all(lambda x: x is None)       # ok when all items in xs are None
    ok (xs).any(lambda x: x is None)       # ok when there is None in xs
    ok (x).between(minval, maxval)         # ok when minval <= x <= maxval
    ok (xs).length([minlen, maxlen])       # ok when minlen <= len(xs) <= maxlen
    ok (dictionary).has_key('key')         # ok when dictinary has key
    ok (dictionary).has_item('key','val')  # ok when dictionary has key an val
    
  • [enhance] @test() に指定したユーザ定義オプションを取得する options_of() 関数を追加 ex:

    import unittest
    from oktest import ok, test, options_of
    
    class FooTest(unittest.TestCase):
    
        def setUp(self):
            ## たとえば、タグ名によって setUp() の振舞いを変える
            dictionary = options_of(self)
            if dictionary.get('tag') == "experimental":
                ....
    
        @test("example", tag="experimental", num=123)
        def _(self):
            assert options_of(self) == {'tag': "experimental", 'num': 123}
    
  • [bugfix] oktest.web.WSGITestがPython3.4でも警告なしで動作するように修正

  • [bugfix] fix oktest.web.WSGITestが日本語URLパスを受け付けるよう修正

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment