subui.validators module

class subui.validators.BaseValidator(test_step=None, **kwargs)[source]

Bases: object

Base validator which should be sub-classed to create custom validators.

Variables:BaseValidator.expected_attrs (tuple) –

Required attributes for the validator. _check_improper_configuration() will verify that all of these attributes are defined.

Note

Each validator should only define required attributes for itself. _get_expected_attrs() will automatically return required attributes from all current validator and base classes.

Parameters:test_step

subui.step.TestStep instance which will be used to make assertions on.

Note

This parameter is not really required in the __init__ because the same step will be passed in test() however is useful in __init__ in case subclass validator needs to apply custom login according to values from the step.

expected_attrs = None
test(test_step)[source]

Test the step’s server response by making all the necessary assertions. This method by default saves the test_step parameter into step and validates the validator by using _check_improper_configuration(). All subclass validators should actually implement assertions in this method.

Parameters:test_step – Test step
class subui.validators.FormInitialDataValidator(test_step=None, **kwargs)[source]

Bases: subui.validators.BaseValidator

Validator checks that form in response has expected data in initial data.

Variables:
context_data_form_name = u'form'
expected_attrs = (u'initial_data_key',)
expected_initial_data_value = None
initial_data_key = None
test(test_step)[source]
test_initial_value = False
test_initial_value_not_none = True
test_initial_value_present = True
class subui.validators.HeaderContentTypeValidator(test_step=None, **kwargs)[source]

Bases: subui.validators.HeaderValidator

Validator to check that the expected “Content-Type” header is returned.

header_name = u'Content-Type'
class subui.validators.HeaderLocationValidator(test_step=None, **kwargs)[source]

Bases: subui.validators.HeaderValidator

Validator to check that the redirect “Location” header is returned

header_name = u'Location'
class subui.validators.HeaderValidator(test_step=None, **kwargs)[source]

Bases: subui.validators.BaseValidator

Validator which can check that a particular header is returned and that it is of particular value.

Variables:
expected_attrs = (u'header_name', u'expected_header')
expected_header = None
header_name = None
test(test_step)[source]

Test the response returned with :py:attr:header_name header and that its value is equal to :py:attr:expected_header if :py:attr:test_header_value is True. If :py:attr:test_contains_value is True, header value will be tested to contain expected value.

test_contains_value = False
test_header_value = True
class subui.validators.RedirectToRouteValidator(test_step=None, **kwargs)[source]

Bases: subui.validators.StatusCodeRedirectValidator

Validator which also checks that the server returns a redirect to an expected Django route.

Variables:expected_route_name (str) – Route name to which the server should redirect to
expected_attrs = (u'expected_route_name',)
expected_route_name = None
test(test_step)[source]

Test the response by additionally testing that the response redirects to an expected route as defined by expected_route_name.

class subui.validators.ResponseContentContainsValidator(test_step=None, **kwargs)[source]

Bases: subui.validators.StatusCodeOkValidator

Validator which also checks that returned response content contains expect string.

Variables:expected_content (str) – Expected string in the server response
expected_attrs = (u'expected_content',)
expected_content = None
test(test_step)[source]

Test the response by additionally testing that the response context contains expected string as defined by expected_content.

class subui.validators.ResponseContentNotContainsValidator(test_step=None, **kwargs)[source]

Bases: subui.validators.StatusCodeOkValidator

Validator checks that returned response content does not contain unexpected string.

Variables:unexpected_content (str) – Unexpected string in the server response
expected_attrs = (u'unexpected_content',)
test(test_step)[source]

Test the response by additionally testing that the response context does not contain the unexpected string as defined by unexpected_content.

unexpected_content = None
class subui.validators.SessionDataValidator(test_step=None, **kwargs)[source]

Bases: subui.validators.BaseValidator

Validator which allows to verify the data in the session based on session key.

Variables:
expected_attrs = (u'expected_session_key',)
expected_session_key = None
expected_session_secondary_keys = []
test(test_step)[source]

Test that expected session key is present. If expected session data provided, ensure the expected session key data matches what is there currently.

class subui.validators.StatusCodeCreatedValidator(test_step=None, **kwargs)[source]

Bases: subui.validators.StatusCodeValidator

Validator to check that the returned status code is created - 201

expected_status_code = 201
class subui.validators.StatusCodeOkValidator(test_step=None, **kwargs)[source]

Bases: subui.validators.StatusCodeValidator

Validator to check that the returned status code is OK - 200

expected_status_code = 200
class subui.validators.StatusCodeRedirectValidator(test_step=None, **kwargs)[source]

Bases: subui.validators.HeaderLocationValidator, subui.validators.StatusCodeValidator

Validator to check that the server returns a redirect with the “Location” header defined.

expected_status_code = 302
test_header_value = False
class subui.validators.StatusCodeValidator(test_step=None, **kwargs)[source]

Bases: subui.validators.BaseValidator

Validator which allows to verify the returned server status code such as “OK-200” or “Redirect-302”, etc.

Variables:StatusCodeValidator.expected_status_code (int) – Expected status code to be returned by the server
expected_attrs = (u'expected_status_code',)
expected_status_code = None
test(test_step)[source]

Test that the response status code matched expected status code.