Adding New Tests
This testing tool is intended to be straightforward to extend. If you encounter an implementation which is operating outside of the specification and a current test suite does not identify this behaviour, please consider adding a test as follows:
- First, raise an Issue against this repository. Even if you do not have the time to write additional tests, a good explanation of the issue identified could allow someone else to do so on your behalf.
- Once an issue has been raised, feel free to assign it to yourself. We would welcome any Pull Requests which add to the set of tests available. Once a Pull Request is raised, one of the specification maintainers will review it before including it in the test suite.
Test Suite Structure
All test suite classes inherit from
GenericTest which implements some basic schema checks on GET/HEAD/OPTIONS methods from the specification. It also provides access to a ‘Specification’ object which contains a parsed version of the API RAML, and provides access to schemas for the development of additional tests.
Each manually defined test case is expected to be defined as a method starting with
test_, taking an object of class
Test. This will allow it to be automatically discovered and run as part of the test suite.
The return type for each test case must be the result of calling one of the methods on the
Test object shown below.
The first argument,
details, is used to specify the reason for the test result. It is required for
OPTIONAL(Not Implemented), or
NA(Not Applicable), and is recommended for all cases other than a straightforward
The second argument,
link, is optional. It may be used to specify a link to more information, such as to a sub-heading on one of the NMOS Wiki Specifications pages. It is recommended especially to provide further explanation of the effect of an
OPTIONALfeature being unimplemented.
Examples of each result are included below:
from .TestResult import Test def test_my_stuff(self, test): """My test description""" # Test code if test_passed: return test.PASS() elif test_failed: return test.FAIL("Reason for failure") elif test_warning: return test.WARNING("Reason the API configuration or response is not recommended") elif test_disabled: return test.DISABLED("Explanation of why the test is disabled and e.g. how to change the test suite " "config to allow it to be run") elif test_could_not_test: return test.UNCLEAR("Explanation of what prior responses prevented this test being run") elif test_not_implemented: return test.OPTIONAL("Explanation of what wasn't implemented, and why you might require it", "https://github.com/AMWA-TV/nmos/wiki/Specifications#what-is-required-vs-optional") elif test_manual: return test.MANUAL("Explanation of why the test is not (yet) tested automatically, and e.g. how to " "run it manually") elif test_not_applicable: return test.NA("Explanation of why the test is not applicable, e.g. due to the version of the " "specification being tested")
The following methods may be of use within a given test definition.
Requesting from an API
# All keyword parameters are optional # Where 'json' is the body of the request in json and 'data' is the body as url encoded form data self.do_request(method, url, json=json, data=data, headers=headers, auth=auth)
Returns a tuple of the request status (True/False) and a Requests library Response object.
Testing an API’s response
self.check_response(schema, method, response)
Return a tuple of the test status (True/False) and a string indicating the error in the case this is False.
Accessing response schemas
self.get_schema(api_name, method, path, status_code)
Returns a JSON schema, or None if it is unavailable.
Validating a JSON schema
Raises an exception upon validation failure.