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: - endpoint –
string
: The endpoint to test - data1 –
dict
: Data to create the initial entity with (POST) - data2 –
dict
: Data to update the entity with (PUT) - key –
string
: The key field in the response returned when performing a create. - check_keys –
list
: A list of keys to comparedata_1
anddata_2
to returned API responses. (To ensure expected response data) - keys_from_prev –
list
: A list of keys to check that they persisted after a create/update. - create –
bool
: Should create a new object and test it’s existence - delete –
bool
: Should delete the newly created object and test that it has been deleted. - update –
bool
: Should performs PUT (update) - read –
bool
: Should perform a plural read - initial_count –
int
: The initial number of entities in the endpoint’s dataset
- endpoint –
-
-
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, }
-