示例#1
0
    def test_when_fetch_then_performs_auth(self):
        auth = Spy().auth

        session = Session(Stub(), auth=auth)

        session.fetch("/users", callback=CALLBACK)

        assert_that(auth, called().with_args(instance_of(httpclient.HTTPRequest)))
示例#2
0
    def test_when_fetch_then_performs_auth(self):
        auth = Spy().auth

        session = Session(Stub(), auth=auth)

        session.fetch('/users', callback=CALLBACK)

        assert_that(auth,
                    called().with_args(instance_of(httpclient.HTTPRequest)))
示例#3
0
    def test_when_fetch_with_params_then_calls_http_client_fetch_with_params_added_to_url(self):
        with Spy(httpclient.HTTPClient()) as http_client:
            session = Session(http_client)

        session.fetch("/users?type=json", callback=CALLBACK, params={"is_admin": "true"})

        assert_that(
            http_client.fetch,
            called().with_args(has_properties(url="/users?type=json&is_admin=true"), callback=CALLBACK),
        )
示例#4
0
    def test_when_base_url_set_then_calls_http_client_fetch_with_base_url(self):
        with Spy(httpclient.HTTPClient()) as http_client:
            session = Session(http_client, base_url="https://example.com:12345")

        session.fetch("/users?type=json", callback=CALLBACK, params={"is_admin": "true"})

        assert_that(
            http_client.fetch,
            called().with_args(
                has_properties(url="https://example.com:12345/users?type=json&is_admin=true"), callback=CALLBACK
            ),
        )
示例#5
0
    def test_when_fetch_then_calls_http_client_fetch_with_the_same_args(self):
        with Spy(httpclient.HTTPClient()) as http_client:
            session = Session(http_client)

        session.fetch("/users", method="POST", callback=CALLBACK, headers={"Content-Type": "application/json"})

        assert_that(
            http_client.fetch,
            called().with_args(
                has_properties(url="/users", method="POST", headers={"Content-Type": "application/json"}),
                callback=CALLBACK,
            ),
        )
示例#6
0
    def test_when_fetch_with_params_then_calls_http_client_fetch_with_params_added_to_url(
            self):
        with Spy(httpclient.HTTPClient()) as http_client:
            session = Session(http_client)

        session.fetch('/users?type=json',
                      callback=CALLBACK,
                      params={'is_admin': 'true'})

        assert_that(
            http_client.fetch,
            called().with_args(
                has_properties(url='/users?type=json&is_admin=true'),
                callback=CALLBACK))
示例#7
0
    def test_when_fetch_then_calls_http_client_fetch_with_the_same_args(self):
        with Spy(httpclient.HTTPClient()) as http_client:
            session = Session(http_client)

        session.fetch('/users', method='POST', callback=CALLBACK,
            headers={'Content-Type': 'application/json'})

        assert_that(http_client.fetch, called().with_args(
            has_properties(
                url='/users',
                method='POST',
                headers={'Content-Type': 'application/json'}
            ),
            callback=CALLBACK
        ))
示例#8
0
    def test_when_base_url_set_then_calls_http_client_fetch_with_base_url(
            self):
        with Spy(httpclient.HTTPClient()) as http_client:
            session = Session(http_client,
                              base_url='https://example.com:12345')

        session.fetch('/users?type=json',
                      callback=CALLBACK,
                      params={'is_admin': 'true'})

        assert_that(
            http_client.fetch,
            called().with_args(has_properties(
                url='https://example.com:12345/users?type=json&is_admin=true'),
                               callback=CALLBACK))
示例#9
0
    def test_when_auth_is_username_and_password_tuple_then_session_uses_basic_auth(
            self):
        session = Session(Stub(), auth=(u'root', u'toor'))

        assert_that(session.auth, instance_of(auth.HTTPBasicAuth))
        assert_that(session.auth,
                    has_properties(username=u'root', password=u'toor'))
示例#10
0
    def test_when_fetch_then_calls_http_client_fetch_with_the_same_args(self):
        with Spy(httpclient.HTTPClient()) as http_client:
            session = Session(http_client)

        session.fetch('/users',
                      method='POST',
                      callback=CALLBACK,
                      headers={'Content-Type': 'application/json'})

        assert_that(
            http_client.fetch,
            called().with_args(has_properties(
                url='/users',
                method='POST',
                headers={'Content-Type': 'application/json'}),
                               callback=CALLBACK))
示例#11
0
def before_all(context):
    context.session = Session(httpclient.AsyncHTTPClient())
    context.authenticated = False
示例#12
0
文件: common.py 项目: srinatar/finch
def impl(context):
    context.session = Session(httpclient.AsyncHTTPClient(),
        auth=('admin', 'admin'))