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"})
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": "!@#$"})
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'})
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"}, )
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'})
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': '!@#$'})