コード例 #1
0
def test_regex_passes():
    pact = (Pact("Consumer", "Provider",
                 file_write_mode="never").given("spam").with_request(
                     "GET", "/", headers={
                         "Spam": Term(r"\w+", "spam")
                     }).will_respond_with(200))
    with pact:
        requests.get(pact.uri, headers={"Spam": "ham"})
コード例 #2
0
def test_regex_fails():
    pact = (Pact("Consumer", "Provider",
                 file_write_mode="never").given("spam").with_request(
                     "GET", "/", headers={
                         "Spam": Term(r"\w+", "spam")
                     }).will_respond_with(200))
    with pact:
        with pytest.raises(AssertionError):
            requests.get(pact.uri, headers={"Spam": "!@#$"})
コード例 #3
0
def test_params_url_coded():
    pact = Pact('Consumer', 'Provider', file_write_mode='never').given('everything is ideal') \
        .upon_receiving('a request').with_request(
            method='POST',
            path="/",
            headers={'Content-Type': 'application/x-www-form-urlencoded'},
            query={
                 "client_id": ["test1"],
                 "secret": ["test1-secret-key"],
                 "scope": ['openid', 'profile', 'phone', 'offline_access']
            }
        ).will_respond_with(200, body='some data')
    with pact:
        requests.post(
            pact.uri,
            params=dict(client_id='test1',
                        secret='test1-secret-key',
                        scope='openid profile phone offline_access'.split()),
            headers={'Content-Type': 'application/x-www-form-urlencoded'})
コード例 #4
0
def test_params_url_coded():
    pact = (Pact("Consumer", "Provider", file_write_mode="never").given(
        "everything is ideal").upon_receiving("a request").with_request(
            method="POST",
            path="/",
            headers={
                "Content-Type": "application/x-www-form-urlencoded"
            },
            query={
                "client_id": ["test1"],
                "secret": ["test1-secret-key"],
                "scope": ["openid", "profile", "phone", "offline_access"],
            },
        ).will_respond_with(200, body="some data"))
    with pact:
        requests.post(
            pact.uri,
            params=dict(
                client_id="test1",
                secret="test1-secret-key",
                scope="openid profile phone offline_access".split(),
            ),
            headers={"Content-Type": "application/x-www-form-urlencoded"},
        )
コード例 #5
0
def test_regex_passes():
    pact = Pact('Consumer', 'Provider', file_write_mode='never').given('spam'). \
        with_request('GET', '/', headers={'Spam': Term(r'\w+', 'spam')}).will_respond_with(200)
    with pact:
        requests.get(pact.uri, headers={'Spam': 'ham'})
コード例 #6
0
def test_regex_fails_v3():
    pact = Pact('Consumer', 'Provider', file_write_mode='never', version='3.0.0').given('spam'). \
        with_request('GET', '/', headers={'Spam': Term(r'\w+', 'spam')}).will_respond_with(200)
    with pact:
        with pytest.raises(AssertionError):
            requests.get(pact.uri, headers={'Spam': '!@#$'})