コード例 #1
0
    def test_all_constraints(self):
        """A PUT request containing all parameter constraint combinations."""
        # Handle all the basic endpoints.
        respond_to_get('/schema')
        respond_to_put(r'/example/-?\d+', status=204)

        # Now just kick off the validation process.
        swaggerconformance.api_conformance_test(ALL_CONSTRAINTS_SCHEMA_PATH,
                                                cont_on_err=False)
コード例 #2
0
    def test_full_put(self):
        """A PUT request containing all different parameter types."""
        # Handle all the basic endpoints.
        respond_to_get('/example')
        respond_to_delete('/example', status=204)
        respond_to_put(r'/example/-?\d+', status=204)

        # Now just kick off the validation process.
        swaggerconformance.api_conformance_test(FULL_PUT_SCHEMA_PATH,
                                                cont_on_err=False)
コード例 #3
0
def main(raw_args):
    """Run a basic API conformance test with the supplied command line args."""
    parser = argparse.ArgumentParser(
        prog='python -m swaggerconformance',
        description='Basic Swagger-defined API conformance test.')
    parser.add_argument('schema_path', help='URL or path to Swagger schema')
    parser.add_argument('-n',
                        dest='num_tests_per_op',
                        metavar='N',
                        type=int,
                        default=20,
                        help="number of tests to run per API operation")
    parsed_args = parser.parse_args(raw_args)
    api_conformance_test(parsed_args.schema_path,
                         num_tests_per_op=parsed_args.num_tests_per_op)
コード例 #4
0
    def test_openapi_uber(self):
        """An example Uber API spec from the OpenAPI examples is handled."""
        profile = {
            "first_name": "steve",
            "last_name": "stevenson",
            "email": "*****@*****.**",
            "picture": "http://steve.com/stevepic.png",
            "promo_code": "12341234"
        }
        activities = {
            "offset": 123,
            "limit": 99,
            "count": 432,
            "history": [{
                "uuid": 9876543210
            }]
        }
        product = {
            "product_id": "example",
            "description": "it's a product",
            "display_name": "bestproductno1",
            "capacity": "4 hippos",
            "image": "http://hippotransports.com/hippocar.png"
        }
        products = [product]
        price_estimate = {
            "product_id": "example",
            "currency_code": "gbp",
            "display_name": "it's a product",
            "estimate": "123.50",
            "low_estimate": 123,
            "high_estimate": 124,
            "surge_multiplier": 22.2
        }
        price_estimates = [price_estimate]

        # Handle all the basic endpoints.
        respond_to_get(r'/estimates/price\?.*', response_json=price_estimates)
        respond_to_get(r'/estimates/time\?.*', response_json=products)
        respond_to_get(r'/history\?.*', response_json=activities)
        respond_to_get('/me', response_json=profile)
        respond_to_get(r'/products\?.*', response_json=products)

        # Now just kick off the validation process.
        swaggerconformance.api_conformance_test(UBER_SCHEMA_PATH,
                                                cont_on_err=False)
コード例 #5
0
    def test_content_type_header_with_parameters(self):
        """Content type header parameters should be allowed."""
        content_type_extra = 'application/json; charset=utf-8'
        respond_to_get('/schema')
        respond_to_get('/apps',
                       response_json=[{
                           'name': 'test'
                       }],
                       content_type=content_type_extra)
        respond_to_get(r'/apps/.+',
                       status=404,
                       content_type=content_type_extra)
        respond_to_put(r'/apps/.+',
                       status=204,
                       content_type=content_type_extra)
        respond_to_delete(r'/apps/.+',
                          status=204,
                          content_type=content_type_extra)

        swaggerconformance.api_conformance_test(TEST_SCHEMA_PATH,
                                                cont_on_err=False)
コード例 #6
0
    def test_swaggerio_petstore(self):
        """The petstore API spec from the swagger.io site is handled."""
        # Example responses matching the required models.
        pet = {
            "id": 0,
            "category": {
                "id": 0,
                "name": "string"
            },
            "name": "doggie",
            "photoUrls": ["string"],
            "tags": [{
                "id": 0,
                "name": "string"
            }],
            "status": "available"
        }
        pets = [pet]
        inventory = {"additionalProp1": 0, "additionalProp2": 0}
        order = {
            "id": 0,
            "petId": 0,
            "quantity": 0,
            "shipDate": "2017-03-21T23:13:44.949Z",
            "status": "placed",
            "complete": True
        }
        api_response = {"code": 0, "type": "string", "message": "string"}
        user = {
            "id": 0,
            "username": "******",
            "firstName": "string",
            "lastName": "string",
            "email": "string",
            "password": "******",
            "phone": "string",
            "userStatus": 0
        }

        # Handle all the basic endpoints.
        respond_to_get('/pet')
        respond_to_post('/pet')
        respond_to_put('/pet')
        respond_to_get(r'/pet/-?\d+', response_json=pet)
        respond_to_delete(r'/pet/-?\d+')
        respond_to_post(r'/pet/-?\d+', response_json=api_response)
        respond_to_post(r'/pet/-?\d+/uploadImage', response_json=api_response)
        respond_to_get('/pet/findByStatus', response_json=pets)
        respond_to_get(r'/pet/findByStatus\?status=.*', response_json=pets)
        respond_to_get('/pet/findByTags', response_json=pets)
        respond_to_get(r'/pet/findByTags\?tags=.*', response_json=pets)
        respond_to_get('/store')
        respond_to_get('/store/inventory', response_json=inventory)
        respond_to_post('/store/order', response_json=order)
        respond_to_get(r'/store/order/-?\d+', response_json=order)
        respond_to_delete(r'/store/order/-?\d+')
        respond_to_get('/user')
        respond_to_post('/user')
        respond_to_delete('/user')
        respond_to_get(r'/user/(?!login).+', response_json=user)
        respond_to_put(r'/user/(?!login).+')
        respond_to_delete(r'/user/(?!login).+')
        respond_to_get(r'/user/login\?username=.*&password=.*',
                       response_json="example")
        respond_to_get('/user/logout')
        respond_to_post('/user/createWithArray')
        respond_to_post('/user/createWithList')
        respond_to_put(r'/example/-?\d+')

        # Now just kick off the validation process.
        swaggerconformance.api_conformance_test(PETSTORE_SCHEMA_PATH,
                                                cont_on_err=False)