subui.step module¶
-
class
subui.step.StatefulUrlParamsTestStep(**kwargs)[source]¶ Bases:
subui.step.TestStepTest step same as
TestStepexcept it referencesurl_argsandurl_kwargsfrom the state.Having url computed from the state, allows for a particular step to change
url_argsorurl_kwargshence future steps will fetch different resources.-
get_url_args()[source]¶ Get URL args for Django’s
reverseSimilar to
TestStep.get_url_args()except url args are retrieved by default from state and if not available get args from class attribute.Returns: tuple of url_args
-
get_url_kwargs()[source]¶ Get URL kwargs fpr Django’s
reverseSimilar to
TestStep.get_url_kwargs()except url args are retrieved by default from state and if not available get kwargs from class attribute.Returns: dict of url_kwargs
-
-
class
subui.step.TestStep(**kwargs)[source]¶ Bases:
objectTest step for
subui.test_runner.SubUITestRunner.The step is responsible for executing a self-contained task such as submitting a form to a particular URL and then make assertions regarding the server response.
Variables: - TestStep.test (unittest.TestCase) – Test class instance
with which validators are going to run all their
assertions with. By default it is an instance of
unittest.TestCasehowever can be changed to any other class to add additional assertion methods. - url_name (str) – Name of the url as defined in
urls.pyby which the URL is going to be calculated. - url_args (tuple) – URL args to be used while calculating
the URL using Django’s
reverse. - url_kwargs (dict) – URL kwargs to be used while calculating
the URL using Django’s
reverse. - request_method (str) – HTTP method to use for the request.
Default is
"post" - urlconf (str) – Django URL Configuration.
- content_type (str) – Content-Type of the request.
- overriden_settings (dict) – Dictionary of settings to be overriden for the test request.
- data (dict) – Data to be sent to the server in the request
- state (pycontext.context.Context) – Reference to a global state from the test runner.
- TestStep.validators (list) – List of response validators
- response – Server response for the made request.
This attribute is only available after
request()is called.
Parameters: kwargs (dict) – A dictionary of values which will overwrite any instance attributes. This allows to pass additional data to the test step without necessarily subclassing and manually instantiating step instance.
-
content_type= None¶
-
data= None¶
-
get_content_type()[source]¶ Get
content_typewhich will be used when making the test request.By default this returns
content_type, if defined, else empty string.Return type: str
-
get_override_settings()[source]¶ Get
overriden_settingswhich will be used to decorate the request with the defined settings to be overriden.By default this returns
overriden_settings, if defined, else empty dictReturn type: dict
-
get_request_data(data=None)[source]¶ Get data dict to be sent to the server.
Parameters: data – Data to be used while sending server request. If not defined, datais returned.Return type: dict
-
get_request_kwargs()[source]¶ Get kwargs to be passed to the
client.By default this returns dict of format:
{ 'path': ..., 'data': ... }
Can be overwritten in case additional parameters need to be passed to the client to make the request.
Return type: dict
-
get_url()[source]¶ Compute the URL to request using Django’s
reverse.Reverse is called using
url_name,get_url_args()andget_url_args().Return type: str
-
get_url_args()[source]¶ Get
url_argswhich will be used to compute the URL usingreverse.By default this returns
url_args, if defined, else empty tuple.Return type: tuple
-
get_url_kwargs()[source]¶ Get
url_kwargswhich will be used to compute the URL usingreverse.By default this returns
url_kwargs, if defined, else empty dict.Return type: dict
-
get_urlconf()[source]¶ Get
urlconfwhich will be used to compute the URL usingreverseBy default this returns
urlconf, if defined, else NoneReturn type: str
-
get_validators()[source]¶ Get all validators.
By default returns
validatorshowever can be used as a hook to returns additional validators dynamically.Return type: list
-
init(client, steps, step_index, step_key, state)[source]¶ Initialize the step with necessary values from the test runner.
Parameters: - client (django.test.client.Client) – Django test client to use to make server requests
- steps (collections.OrderedDict) – All steps from the test runner. This and step index allows to get previous and/or next steps.
- step_index (int) – Index of the step within all steps test runner will execute.
- step_key (str) – Key of the state of how it was provided to the test runner in case test step needs to reference other steps within the runner by their.
- state (platform_utils.utils.dt_context.BaseContext) – Global state reference from the test runner.
-
next_steps¶ Get
collections.OrderedDictof next steps excluding itself, if any.Return type: collections.OrderedDict
-
overriden_settings= None¶
-
prev_steps¶ Get
collections.OrderedDictof previous steps excluding itself, if any.Note
The steps are returned in order of adjacency from the current step. For example (using list instead of OrederedDict in example):
> step = TestStep() > step.steps = [0, 1, 2, 3, 4] > step.step_index = 3 > step.prev_steps [2, 1, 0]
Return type: collections.OrderedDict
-
request()[source]¶ Make the server request. Server response is then saved in
request.Before making the request,
pre_request_hook()is called andpost_request_hook()is called after the request.Returns: server response
-
request_method= u'post'¶
-
state= None¶
-
test= <unittest.case.TestCase testMethod=__init__>¶
-
test_response()[source]¶ Test the server response by looping over all validators as returned by
get_validators().Before assertions,
pre_test_response()is called andpost_test_response()is called after assertions.
-
url_args= None¶
-
url_kwargs= None¶
-
url_name= None¶
-
urlconf= None¶
-
validators= []¶
- TestStep.test (unittest.TestCase) – Test class instance
with which validators are going to run all their
assertions with. By default it is an instance of