Testing

API

class twopi_flask_utils.testing.AppReqTestHelper

Adds convenience request methods on the testcase object.

Assumes a flask app client is defined on self.client

delete(*args, **kwargs)

Perform a delete request to the application.

get(*args, **kwargs)

Perform a get request to the application.

patch(*args, **kwargs)

Perform a patch request to the application.

post(*args, **kwargs)

Perform a post request to the application.

put(*args, **kwargs)

Perform a put request to the application.

class twopi_flask_utils.testing.CRUDTestHelper

A helper to test generic CRUD operations on an endpoint.

do_crud_test(endpoint, data_1=None, data_2=None, key='id', check_keys=[], keys_from_prev=[], create=True, delete=True, update=True, read=True, initial_count=0)

Begins the CRUD test.

Parameters:
  • endpointstring: The endpoint to test
  • data1dict: Data to create the initial entity with (POST)
  • data2dict: Data to update the entity with (PUT)
  • keystring: The key field in the response returned when performing a create.
  • check_keyslist: A list of keys to compare data_1 and data_2 to returned API responses. (To ensure expected response data)
  • keys_from_prevlist: A list of keys to check that they persisted after a create/update.
  • createbool: Should create a new object and test it’s existence
  • deletebool: Should delete the newly created object and test that it has been deleted.
  • updatebool: Should performs PUT (update)
  • readbool: Should perform a plural read
  • initial_countint: The initial number of entities in the endpoint’s dataset
class twopi_flask_utils.testing.PrivilegeTestHelper

Adds a helper to test endpoint privileges in an application.

do_test_privileges(endpoint, data, object_id, expected_codes)

Test privileges on a specific endpoint.

Parameters:
  • endpoint – The endpoint to test. e.g. /api/v1/classes
  • data – The data to use when performing a PUT/POST (dict)
  • object_id – The id of the singular object to test permissions on PUT/DELETE/GET
  • expected_codes

    The expected response codes when performing each endpoint request. E.g.

    {
        'plural-get': 200,
        'get': 200,
        'delete': 403,
        'post': 200,
        'put': 200,
    }