当前位置: 首页>>代码示例>>Python>>正文


Python client.TestClient类代码示例

本文整理汇总了Python中gittip.testing.client.TestClient的典型用法代码示例。如果您正苦于以下问题:Python TestClient类的具体用法?Python TestClient怎么用?Python TestClient使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了TestClient类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_post_bad_platform

    def test_post_bad_platform(self):
        client = TestClient()

        now = datetime.datetime.now(pytz.utc)
        self.make_participant("test_tippee1", claimed_time=now)
        self.make_participant("test_tipper", claimed_time=now)

        api_key = json.loads(client.get('/test_tipper/api-key.json', 'test_tipper').body)['api_key']

        response = client.post( '/test_tipper/tips.json'
                              , json.dumps([{ 'username': 'test_tippee1'
                                            , 'platform': 'badname'
                                            , 'amount': '1.00'
                                             }])
                              , user='test_tipper'
                              , content_type='application/json'
                              , HTTP_AUTHORIZATION='Basic ' + base64.b64encode(api_key + ':')
                               )

        assert response.code == 200

        resp = json.loads(response.body)

        for tip in resp:
            assert 'error' in tip
开发者ID:abnor,项目名称:www.gittip.com,代码行数:25,代码来源:test_tips_json.py

示例2: test_get_amount_and_total_back_from_api

    def test_get_amount_and_total_back_from_api(self):
        "Test that we get correct amounts and totals back on POSTs to tip.json"
        client = TestClient()

        # First, create some test data
        # We need accounts
        now = datetime.datetime.now(pytz.utc)
        self.make_participant("test_tippee1", claimed_time=now)
        self.make_participant("test_tippee2", claimed_time=now)
        self.make_participant("test_tipper")

        # We need to get ourselves a token!
        response = client.get('/')
        csrf_token = response.request.context['csrf_token']

        # Then, add a $1.50 and $3.00 tip
        response1 = client.post("/test_tippee1/tip.json",
                                {'amount': "1.00", 'csrf_token': csrf_token},
                                user='test_tipper')

        response2 = client.post("/test_tippee2/tip.json",
                                {'amount': "3.00", 'csrf_token': csrf_token},
                                user='test_tipper')

        # Confirm we get back the right amounts.
        first_data = json.loads(response1.body)
        second_data = json.loads(response2.body)
        assert first_data['amount'] == "1.00"
        assert first_data['total_giving'] == "1.00"
        assert second_data['amount'] == "3.00"
        assert second_data['total_giving'] == "4.00"
开发者ID:abnor,项目名称:www.gittip.com,代码行数:31,代码来源:test_tip_json.py

示例3: test_get_amount_and_total_back_from_api

def test_get_amount_and_total_back_from_api():
    "Test that we get correct amounts and totals back on POSTs to tip.json"
    client = TestClient()

    # First, create some test data
    # We need accounts
    db.execute(CREATE_ACCOUNT, ("test_tippee1",))
    db.execute(CREATE_ACCOUNT, ("test_tippee2",))
    db.execute(CREATE_ACCOUNT, ("test_tipper",))

    # We need to get ourselves a token!
    response = client.get('/')
    csrf_token = response.request.context['csrf_token']

    # Then, add a $1.50 and $3.00 tip
    response1 = client.post("/test_tippee1/tip.json",
                            {'amount': "1.00", 'csrf_token': csrf_token},
                            user='test_tipper')

    response2 = client.post("/test_tippee2/tip.json",
                            {'amount': "3.00", 'csrf_token': csrf_token},
                            user='test_tipper')

    # Confirm we get back the right amounts.
    first_data = json.loads(response1.body)
    second_data = json.loads(response2.body)
    assert_equal(first_data['amount'], "1.00")
    assert_equal(first_data['total_giving'], "1.00")
    assert_equal(second_data['amount'], "3.00")
    assert_equal(second_data['total_giving'], "4.00")
开发者ID:imathis,项目名称:www.gittip.com,代码行数:30,代码来源:test_tip_json.py

示例4: test_get_response

    def test_get_response(self):
        client = TestClient()

        now = datetime.datetime.now(pytz.utc)
        self.make_participant("test_tipper", claimed_time=now)

        response = client.get('/test_tipper/tips.json', 'test_tipper')

        assert response.code == 200
        assert len(json.loads(response.body)) == 0 # empty array
开发者ID:abnor,项目名称:www.gittip.com,代码行数:10,代码来源:test_tips_json.py

示例5: test_github_user_info_status_handling

    def test_github_user_info_status_handling(self, requests):
        client = TestClient()
        # Check that different possible github statuses are handled correctly
        for (github_status, github_content), expected_gittip_response in [
                ((200, DUMMY_GITHUB_JSON), 200),
                ((404, ""), 404),
                ((500, ""), 502),
                ((777, ""), 502)]:

            requests.get().status_code = github_status
            requests.get().text = github_content
            response = client.get('/on/github/not-in-the-db/')
            assert_equal(response.code, expected_gittip_response)
开发者ID:angleman,项目名称:www.gittip.com,代码行数:13,代码来源:test_elsewhere_github.py

示例6: change_username

    def change_username(self, new_username, user='alice'):
        self.make_participant('alice')

        client = TestClient()
        response = client.get('/')
        csrf_token = response.request.context['csrf_token']

        response = client.post( "/alice/username.json"
                              , { 'username': new_username
                                , 'csrf_token': csrf_token
                                 }
                              , user=user
                               )
        return response
开发者ID:angleman,项目名称:www.gittip.com,代码行数:14,代码来源:test_username_json.py

示例7: Tests

class Tests(Harness):

    def setUp(self):
        Harness.setUp(self)
        self.website = test_website
        self.client = TestClient()

    def tearDown(self):
        self.website.oauth_cache = {}


    @mock.patch('requests.post')
    @mock.patch('requests.get')
    @mock.patch('gittip.utils.mixpanel.track')
    def test_associate_opts_in(self, track, get, post):
        self.website.oauth_cache = {"deadbeef": ("deadbeef", "opt-in", "")}

        post.return_value.status_code = 200
        post.return_value.text = "oauth_token=foo&oauth_token_secret=foo&user_id=foo"

        get.return_value.status_code = 200
        get.return_value.text = '{"id": 1234, "screen_name": "alice"}'

        response = self.client.get("/on/twitter/associate?oauth_token=deadbeef&"
                                   "oauth_verifier=donald_trump")
        assert response.code == 302, response.body
        assert response.headers['Location'] == "/alice/", response.headers


    @mock.patch('requests.post')
    @mock.patch('requests.get')
    @mock.patch('gittip.utils.mixpanel.track')
    def test_associate_connects(self, track, get, post):
        self.make_participant('alice')
        self.website.oauth_cache = {"deadbeef": ("deadbeef", "connect", "")}

        post.return_value.status_code = 200
        post.return_value.text = "oauth_token=foo&oauth_token_secret=foo&user_id=foo"

        get.return_value.status_code = 200
        get.return_value.text = '{"id": 1234, "screen_name": "alice"}'

        response = self.client.get("/on/twitter/associate?oauth_token=deadbeef&"
                                   "oauth_verifier=donald_trump", user="alice")
        assert response.code == 302, response.body
        assert response.headers['Location'] == "/alice/", response.headers

        rec = self.db.one("SELECT * FROM elsewhere")
        assert rec.participant == 'alice', rec
        assert rec.platform == 'twitter', rec
开发者ID:angleman,项目名称:www.gittip.com,代码行数:50,代码来源:test_associate.py

示例8: change_bitcoin_address

    def change_bitcoin_address(self, address, user='alice'):
        self.make_participant('alice')

        client = TestClient()
        response = client.get('/')
        csrf_token = response.request.context['csrf_token']

        response = client.post( "/alice/bitcoin.json"
                              , { 'bitcoin_address': address
                                , 'csrf_token': csrf_token
                                 }
                              , user=user
                               )
        return response
开发者ID:reedlaw,项目名称:www.gittip.com,代码行数:14,代码来源:test_bitcoin_json.py

示例9: change_statement

    def change_statement(self, statement, number='singular', user='alice'):
        self.make_participant('alice')

        client = TestClient()
        response = client.get('/')
        csrf_token = response.request.context['csrf_token']

        response = client.post( "/alice/statement.json"
                              , { 'statement': statement
                                , 'number': number
                                , 'csrf_token': csrf_token
                                 }
                              , user=user
                               )
        return response
开发者ID:angleman,项目名称:www.gittip.com,代码行数:15,代码来源:test_statement_json.py

示例10: change_goal

    def change_goal(self, goal, goal_custom="", user="alice"):
        if isinstance(user, Participant):
            user = user.username
        else:
            self.make_alice()

        client = TestClient()
        response = client.get('/')
        csrf_token = response.request.context['csrf_token']

        response = client.post( "/alice/goal.json"
                              , { 'goal': goal
                                , 'goal_custom': goal_custom
                                , 'csrf_token': csrf_token
                                 }
                              , user=user
                               )
        return response
开发者ID:DylanLacey,项目名称:www.gittip.com,代码行数:18,代码来源:test_goal_json.py

示例11: test_set_tip_out_of_range

    def test_set_tip_out_of_range(self):
        client = TestClient()
        now = datetime.datetime.now(pytz.utc)
        self.make_participant("alice", claimed_time=now)
        self.make_participant("bob", claimed_time=now)

        response = client.get('/')
        csrf_token = response.request.context['csrf_token']
        response = client.post("/alice/tip.json",
                                {'amount': "110.00", 'csrf_token': csrf_token},
                                user='bob')
        assert "bad amount" in response.body
        assert response.code == 400
        
        response = client.post("/alice/tip.json",
                                {'amount': "-1.00", 'csrf_token': csrf_token},
                                user='bob')
        assert "bad amount" in response.body
        assert response.code == 400
开发者ID:abnor,项目名称:www.gittip.com,代码行数:19,代码来源:test_tip_json.py

示例12: setUp

    def setUp(self):
        self.client = TestClient()
        Harness.setUp(self)

        self._blech = ( os.environ['CANONICAL_SCHEME']
                      , os.environ['CANONICAL_HOST']
                       )
        os.environ['CANONICAL_SCHEME'] = 'https'
        os.environ['CANONICAL_HOST'] = 'www.gittip.com'
        wireup.canonical()
开发者ID:abnor,项目名称:www.gittip.com,代码行数:10,代码来源:test_hooks.py

示例13: hit_anonymous

    def hit_anonymous(self, method='GET', expected_code=200):
        user, ignored = TwitterAccount('alice', {}).opt_in('alice')

        client = TestClient()
        response = client.get('/')
        csrf_token = response.request.context['csrf_token']

        if method == 'GET':
            response = client.get( "/alice/anonymous.json"
                                 , user='alice'
                                  )
        else:
            assert method == 'POST'
            response = client.post( "/alice/anonymous.json"
                                  , {'csrf_token': csrf_token}
                                  , user='alice'
                                   )
        if response.code != expected_code:
            print(response.body)
        return response
开发者ID:angleman,项目名称:www.gittip.com,代码行数:20,代码来源:test_anonymous_json.py

示例14: also_prune_variant

    def also_prune_variant(self, also_prune, tippees=1):
        client = TestClient()

        now = datetime.datetime.now(pytz.utc)
        self.make_participant("test_tippee1", claimed_time=now)
        self.make_participant("test_tippee2", claimed_time=now)
        self.make_participant("test_tipper", claimed_time=now)

        api_key = json.loads(client.get('/test_tipper/api-key.json', 'test_tipper').body)['api_key']

        data = [
            {'username': 'test_tippee1', 'platform': 'gittip', 'amount': '1.00'},
            {'username': 'test_tippee2', 'platform': 'gittip', 'amount': '2.00'}
        ]

        response = client.post( '/test_tipper/tips.json'
                              , json.dumps(data)
                              , user='test_tipper'
                              , content_type='application/json'
                              , HTTP_AUTHORIZATION='Basic ' + base64.b64encode(api_key + ':')
                               )

        assert response.code == 200
        assert len(json.loads(response.body)) == 2

        response = client.post( '/test_tipper/tips.json?also_prune=' + also_prune
                              , json.dumps([{ 'username': 'test_tippee2'
                                            , 'platform': 'gittip'
                                            , 'amount': '1.00'
                                             }])
                              , user='test_tipper'
                              , content_type='application/json'
                              , HTTP_AUTHORIZATION='Basic ' + base64.b64encode(api_key + ':')
                               )

        assert response.code == 200

        response = client.get('/test_tipper/tips.json', 'test_tipper')
        assert response.code == 200
        assert len(json.loads(response.body)) == tippees
开发者ID:abnor,项目名称:www.gittip.com,代码行数:40,代码来源:test_tips_json.py

示例15: test_get_response_with_tips

    def test_get_response_with_tips(self):
        client = TestClient()

        now = datetime.datetime.now(pytz.utc)
        self.make_participant("test_tippee1", claimed_time=now)
        self.make_participant("test_tipper", claimed_time=now)

        response = client.get('/')
        csrf_token = response.request.context['csrf_token']

        response1 = client.post('/test_tippee1/tip.json',
            {'amount': '1.00', 'csrf_token': csrf_token},
            user='test_tipper')

        response = client.get('/test_tipper/tips.json', 'test_tipper')

        assert response1.code == 200
        assert json.loads(response1.body)['amount'] == '1.00'

        data = json.loads(response.body)[0]

        assert response.code == 200
        assert data['username'] == 'test_tippee1'
        assert data['amount'] == '1.00'
开发者ID:abnor,项目名称:www.gittip.com,代码行数:24,代码来源:test_tips_json.py


注:本文中的gittip.testing.client.TestClient类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。