Пример #1
0
def provider(statedir, app, contract):
    if os.path.exists(PROVIDER_TEST_RESULT):
        os.remove(PROVIDER_TEST_RESULT)
    if not os.path.exists(contract):
        logger.error('Contract file %s does not exist', contract)
        sys.exit(1)
    contracts = []
    if os.path.isdir(contract):
        for dirpath, dirnames, filenames in os.walk(contract):
            for filename in filenames:
                with open(os.path.join(dirpath, filename)) as f:
                    contract = Contract.from_dict(json.loads(f.read(), object_pairs_hook=datetime_decoder))
                    contracts.append(contract)
    else:
        with open(contract) as f:
            contract = Contract.from_dict(json.loads(f.read(), object_pairs_hook=datetime_decoder))
            contracts.append(contract)
    if not contracts:
        logger.info('No contract found')
        sys.exit()

    states = load_states(statedir)
    # It's important to provide all test cases in a list so that nosetests can
    # generate a proper xunit result summary file.
    test_cases = _render_http_testsuite(app, contracts, states)
    successful = nose.run(
        argv=[__file__, '-sv', '--logging-level=INFO', '--with-xunit', '--xunit-file=' + PROVIDER_TEST_RESULT],
        suite=test_cases,
    )
    _exit(successful)
Пример #2
0
 def test_from_dict(self):
     contract = Contract.from_dict({
         'provider': {
             'name': 'provider'
         },
         'consumer': {
             'name': 'consumer'
         },
         "metadata": {
             "pacte": {
                 "version": VERSION
             }
         },
         "interactions": [{
             "providerState": "Test",
             "description": "a request",
             "request": {
                 "method": "GET",
                 "path": "/path",
                 "headers": {
                     "Custom-Header": "value"
                 },
             },
             "response": {
                 "status": 200,
                 "headers": {
                     "Content-Type": "text/html"
                 },
                 "body": "Test String Response"
             }
         }, {
             "providerState": "Test2",
             "description": "a request2",
             "request": {
                 "method": "POST",
                 "path": "/path",
                 "query": "name=ron&status=good",
                 "headers": {
                     "Custom-Header": "value"
                 },
             },
             "response": {
                 "status": 200,
                 "headers": {
                     "Content-Type": "text/html"
                 },
                 "body": {
                     "key": "value"
                 }
             }
         }],
     })
     self.assertEqual('consumer', contract.consumer)
     self.assertEqual('provider', contract.provider)
     self.assertEqual(2, len(contract.interactions))