swaggerconformance.strategies.primitivestrategies module

Strategies for values of various data types.

class swaggerconformance.strategies.primitivestrategies.PrimitiveStrategy(swagger_definition, factory)[source]

Bases: object

Strategy for a single value of any specified type.

Parameters:
strategy()[source]

Return a hypothesis strategy defining this value.

class swaggerconformance.strategies.primitivestrategies.BooleanStrategy(swagger_definition, factory)[source]

Bases: swaggerconformance.strategies.primitivestrategies.PrimitiveStrategy

Strategy for a Boolean value.

strategy()[source]

Return a hypothesis strategy defining this value.

class swaggerconformance.strategies.primitivestrategies.NumericStrategy(swagger_definition, factory)[source]

Bases: swaggerconformance.strategies.primitivestrategies.PrimitiveStrategy

Abstract template for a numeric value.

strategy()[source]

Return a hypothesis strategy defining this value.

class swaggerconformance.strategies.primitivestrategies.IntegerStrategy(swagger_definition, factory)[source]

Bases: swaggerconformance.strategies.primitivestrategies.NumericStrategy

Strategy for an integer value.

strategy()[source]

Return a hypothesis strategy defining this value.

class swaggerconformance.strategies.primitivestrategies.FloatStrategy(swagger_definition, factory)[source]

Bases: swaggerconformance.strategies.primitivestrategies.NumericStrategy

Strategy for a floating point value.

strategy()[source]

Return a hypothesis strategy defining this value.

class swaggerconformance.strategies.primitivestrategies.StringStrategy(swagger_definition, factory, blacklist_chars=None)[source]

Bases: swaggerconformance.strategies.primitivestrategies.PrimitiveStrategy

Strategy for a string value.

strategy()[source]

Return a hypothesis strategy defining this value.

class swaggerconformance.strategies.primitivestrategies.URLPathStringStrategy(swagger_definition, factory)[source]

Bases: swaggerconformance.strategies.primitivestrategies.StringStrategy

Strategy for a string value which must be valid in a URL path.

class swaggerconformance.strategies.primitivestrategies.HTTPHeaderStringStrategy(swagger_definition, factory)[source]

Bases: swaggerconformance.strategies.primitivestrategies.StringStrategy

Strategy for a string value which must be valid in a HTTP header.

strategy()[source]

Return a hypothesis strategy defining this value.

class swaggerconformance.strategies.primitivestrategies.XFieldsHeaderStringStrategy(swagger_definition, factory)[source]

Bases: swaggerconformance.strategies.primitivestrategies.PrimitiveStrategy

Strategy for a string value which must be valid in the X-Fields header.

The X-Fields parameter lets you specify a mask of fields to be returned by the application. The format is a comma-separated list of fields to return, enclosed by curly-brackets, which can be nested. So for example: {name, age, pets{name}}. There is also a special value of * meaning ‘all remaining fields’, and it can be provided alone as * or inserted into a mask of the above format instead of a field name.

We could generate random values for this header that match the allowed syntax, but:

  • as far as I can see, this field is a Flast-RESTPlus special,
  • this is implemented by the Swagger API framework, so not exciting to exercise,
  • there’s a risk of just generating values which are rejected continually and so reducing the effectiveness of the testing of other fields.

Therefore, we just return either '' or * for this parameter as they are safe values that shouldn’t interfere with other testing.

strategy()[source]

Return a hypothesis strategy defining this value.

class swaggerconformance.strategies.primitivestrategies.DateStrategy(swagger_definition, factory)[source]

Bases: swaggerconformance.strategies.primitivestrategies.PrimitiveStrategy

Strategy for a Date value.

strategy()[source]

Return a hypothesis strategy defining this value.

class swaggerconformance.strategies.primitivestrategies.DateTimeStrategy(swagger_definition, factory)[source]

Bases: swaggerconformance.strategies.primitivestrategies.PrimitiveStrategy

Strategy for a Date-Time value.

strategy()[source]

Return a hypothesis strategy defining this value.

class swaggerconformance.strategies.primitivestrategies.UUIDStrategy(swagger_definition, factory)[source]

Bases: swaggerconformance.strategies.primitivestrategies.PrimitiveStrategy

Strategy for a UUID value.

strategy()[source]

Return a hypothesis strategy defining this value.

class swaggerconformance.strategies.primitivestrategies.FileStrategy(swagger_definition, factory)[source]

Bases: swaggerconformance.strategies.primitivestrategies.PrimitiveStrategy

Strategy for a File value.

strategy()[source]

Return a hypothesis strategy defining this value.

class swaggerconformance.strategies.primitivestrategies.ArrayStrategy(swagger_definition, factory)[source]

Bases: swaggerconformance.strategies.primitivestrategies.PrimitiveStrategy

Strategy for an array collection.

strategy()[source]

Return a hypothesis strategy defining this collection.

class swaggerconformance.strategies.primitivestrategies.ObjectStrategy(swagger_definition, factory)[source]

Bases: swaggerconformance.strategies.primitivestrategies.PrimitiveStrategy

Strategy for a JSON object collection.

MAX_ADDITIONAL_PROPERTIES is a limit on the number of additional properties to add to objects. Setting this too high might cause data generation to time out.

MAX_ADDITIONAL_PROPERTIES = 5
strategy()[source]

Return a hypothesis strategy defining this collection, including random additional properties if the object supports them.

Will add only up to MAX_ADDITIONAL_PROPERTIES extra values to prevent data generation taking too long and timing out.

Parameters:
  • required_properties (dict) – The required fields in the generated dict.
  • optional_properties (dict) – The optional fields in the generated dict.