def test(): data = load_acceptance_test(__file__) actual = PactRequest(headers=[{'ACCEPT': 'alligators'}]) expected = PactRequest(headers=[{'Accept': 'alligators'}]) test_result = match(actual, expected) assert type(test_result) is Right
def test(): data = load_acceptance_test(__file__) actual = PactRequest(**data['actual']) expected = PactRequest(**data['expected']) test_result = match(actual, expected) assert type(test_result) is Left
def test(): data = load_acceptance_test(__file__) actual = PactRequest(headers=[]) expected = PactRequest(headers=[]) test_result = match(actual, expected) assert type(test_result) is Right
def test(): data = load_acceptance_test(__file__) actual = PactRequest(**data['actual']) expected = PactRequest(**data['expected']) actual.headers = [{'Content-Type': 'text/plain'}] expected.headers = [{'Content-Type': 'text/plain'}] test_result = match(actual, expected) assert type(test_result) is Right
def verify_request(decorated_method, port=9999): mock_response = build_expected_response(decorated_method) expected_request = build_expected_request(decorated_method) mock_server = MockServer(mock_response=mock_response, port=port) mock_server.start() decorated_method() mock_server.shutdown() report = mock_server.report() if len(report) is 0: out = { 'status': 'FAILED', 'providerState': decorated_method.given, 'description': decorated_method.upon_receiving, 'message': 'Missing request(s) for "' + format_message(decorated_method) + '"', 'expected': expected_request.__dict__, 'actual': None } return Left(out) actual_request = build_actual_request(report[0]) matching_result = match(actual_request, expected_request) if type(matching_result) is Right: resp = mock_response.__dict__ resp['body'] = mock_response.__dict__['body'] out = { 'status': 'PASSED', 'providerState': decorated_method.given, 'description': decorated_method.upon_receiving, 'request': actual_request.__dict__, 'response': resp } return Right(out) else: reason = matching_result.value.copy() reason.update({ 'providerState': decorated_method.given, 'description': decorated_method.upon_receiving }) return Left(reason)