def test_missing_test_directory(): config = Config() config.provider_tests_path = os.path.join(os.getcwd(), 'spam') t = ServiceProviderTestSuiteRunner(config) result = t.verify() assert type(result) is Left assert result.value.startswith("[Errno 2] No such file or directory:")
def verify(verify_consumers=False, verify_providers=False): config = Config() if verify_consumers: run_consumer_tests(config) if verify_providers: run_provider_tests(config)
def test_verify(monkeypatch): config = Config() config.consumer_tests_path = os.path.join(os.getcwd(), 'tests', 'resources', 'service_consumers') sct = ServiceConsumerTestSuiteRunner(config) class Response(object): status_code = 200 headers = {'Content-Type': 'application/json', 'Date': '12-06-2017'} def json(self): return {'spam': 'eggs'} def connect(_, **kwargs): return Response() monkeypatch.setattr(requests, 'request', connect) actual_response = sct.verify().value assert len(actual_response) == 1 assert actual_response[0].value['test'] == 'TestRestaurantCustomer' assert len(actual_response[0].value['results']) == 1 test_outcome = actual_response[0].value['results'][0].value assert test_outcome['state'] == 'the breakfast is available' assert test_outcome['status'] == 'FAILED' assert len(test_outcome['errors']) == 1 assert test_outcome['errors'][0]['message'] == 'Headers is incorrect'
def test_verify_bad_pact(): config = Config() config.consumer_tests_path = os.path.join(os.getcwd(), 'tests', 'resources', 'service_consumers_bad_pact') sct = ServiceConsumerTestSuiteRunner(config) actual_response = sct.verify().value assert type(actual_response[0]) is Left
def test_collect_tests(): config = Config() config.provider_tests_path = os.path.join(os.getcwd(), 'tests', 'resources', 'service_providers') t = ServiceProviderTestSuiteRunner(config) tests = t.collect_tests().value assert len(tests) == 2
def test_missing_tear_down_method(): remove_pact_helper() config = Config() test_pact_helper_path = os.path.join(os.getcwd(), 'tests', 'resources', 'pact_helper_no_tear_down') config.consumer_tests_path = test_pact_helper_path t = ServiceConsumerTestSuiteRunner(config) msg = 'Missing "tear_down" method in "pact_helper.py".' assert t.verify().value == msg
def test_empty_tests_list(monkeypatch): config = Config() test_pact_helper_path = os.path.join(os.getcwd(), 'tests', 'resources', 'service_consumers') config.consumer_tests_path = test_pact_helper_path def empty_list(_): return [] monkeypatch.setattr(os, 'listdir', empty_list) t = ServiceConsumerTestSuiteRunner(config) msg = 'There are no consumer tests to verify.' assert t.collect_tests().value == msg
def test_collect_tests(): config = Config() test_pact_helper_path = os.path.join(os.getcwd(), 'tests', 'resources', 'service_consumers') config.consumer_tests_path = test_pact_helper_path t = ServiceConsumerTestSuiteRunner(config) tests = t.collect_tests().value assert len(tests) == 1 test = tests[0] assert test.pact_uri == 'tests/resources/pact_files/simple.json' assert test.honours_pact_with == 'Restaurant' state = next(test.states) assert state.state == 'the breakfast is available' assert state() == 'Spam & Eggs'
def test_missing_pact_helper(): config = Config() t = ServiceConsumerTestSuiteRunner(config) msg = 'Missing "pact_helper.py" at "tests/service_consumers".' assert t.verify().value == msg