Assertion Operators¶
Attributes¶
response¶
Response semantic operator for better expressivity.
Type | attribute |
Assertion mode | positive |
Examples:
response | should.have.response.status(200)
response | should.have.response.type.of('json')
response | expect.to.have.response.status(200)
response | expect.to.have.response.type.of('json')
Accessors¶
ok¶
Asserts HTTP response status should be 200
.
Type | attribute |
Related operators | server_error bad_request status |
Assertion form:
res | should.be.ok
res | expect.to.be.ok
Negation form:
res | should.not_be.ok
res | expect.to_not.be.ok
bad_request¶
Asserts HTTP response status should be a server error (400
-499
).
Type | attribute |
Related operators | server_error ok status |
Assertion form:
res | should.be.bad_request
res | expect.to.be.bad_request
Negation form:
res | should.not_be.bad_request
res | expect.to_not.be.bad_request
server_error¶
Asserts HTTP response status should be a server error (500
-599
).
Type | attribute |
Related operators | status bad_request ok |
Assertion form:
res | should.be.server_error
res | expect.to.be.server_error
Negation form:
res | should.not_be.server_error
res | expect.to_not.be.server_error
Matchers¶
status¶
Asserts HTTP response status name or code.
Type | matcher |
Chained aliases | code |
Related operators | headers bad_request ok server_error |
Assertion form:
res | should.be.status(200)
res | expect.to.be.status(200)
Negation form:
res | should.not_be.status(200)
res | expect.to_not.be.status(200)
header¶
headers¶
Asserts HTTP response header(s) presence and/or values.
Type | matcher |
Chained aliases | equal to be of |
Yields | header value |
Related operators | content status |
Optional keywords | includes: bool |
Assertion form:
res | should.have.header('Content-Type', 'application/json')
res | should.have.header('Content-Type').equal.to('application/json')
res | expect.to_not.have.header('Server', 'nginx')
res | expect.to_not.have.header('server').equal.to('nginx')
Negation form:
res | should.not_have.header('Server', 'nginx')
res | should.not_have.header('Server').equal.to('nginx')
res | expect.to.have.header('Server', 'nginx')
res | expect.to.have.header('server').equal.to('nginx')
ctype¶
content¶
Asserts HTTP response content type value.
Type | matcher |
Chained aliases | equal to be of type |
Related operators | header |
Assertion form:
res | should.be.content('json')
res | should.be.content.of('xml')
res | should.have.response.content.type('html')
res | should.have.response.content.type('application/json')
res | should.have.response.content.equal.to('application/json')
res | expect.to.have.content('json')
res | expect.to.have.content.of('xml')
res | expect.to.have.content.type('html')
res | expect.to.have.response.content.equal.to('application/json')
Negation form:
res | should.not_have.content('json')
res | should.not_have.content.of('json')
res | expect.to.not_have.content('json')
res | expect.to.not_have.content.of('xml')
res | expect.to.not_have.content.type('html')
res | expect.to_not.have.response.content.equal.to('application/json')
body¶
data¶
Asserts HTTP response body content as string.
Type | matcher |
Chained aliases | equal to be |
Yields | body |
Related operators | header status json |
Assertion form:
res | should.have.body('hello world')
res | should.have.body.equal.to('hello world')
res | should.have.body.match.to(r'(\w+) world$')
res | should.have.body.to.contain('world')
res | expect.to.have.body('hello world')
res | expect.to.have.body.equal.to('hello world')
res | expect.to.have.body.to.match(r'(\w+) world$')
res | expect.to.have.body.to.contain('world')
Negation form:
res | should.not_have.body('hello world')
res | should.not_have.body.equal.to('hello world')
res | should.have.body.match.to(r'(\w+) world$')
res | should.not_have.body.to.contain('world')
res | expect.to_not.have.body('hello world')
res | expect.to_not.have.body.equal.to('hello world')
res | expect.to_not.have.body.to.match(r'(\w+) world$')
res | expect.to_not.have.body.to.contain('world')
json¶
Asserts HTTP response body JSON content.
Type | matcher |
Chained aliases | equal to be |
Yields | parsed json |
Related operators | header status body jsonschema |
Assertion form:
res | should.have.json({'foo': 'bar'})
res | should.have.json.equal.to({'foo': 'bar'})
res | should.have.json(r'(\w+) world$')
res | should.have.json.to.contain('world')
res | expect.to.have.json({'foo': 'bar'})
res | expect.to.have.json.equal.to({'foo': 'bar'})
res | expect.to.have.json.to.match(r'(\w+) world$')
res | expect.to.have.json.to.contain('world')
Negation form:
res | should.not_have.json({'foo': 'bar'})
res | should.not_have.json.equal.to({'foo': 'bar'})
res | should.have.json.match.to(r'(\w+) world$')
res | should.not_have.json.to.contain('world')
res | expect.to_not.have.json({'foo': 'bar'})
res | expect.to_not.have.json.equal.to({'foo': 'bar'})
res | expect.to_not.have.json.to.match(r'(\w+) world$')
res | expect.to_not.have.json.to.contain('world')
jsonschema¶
json_schema¶
Asserts HTTP response body JSON against a JSONSchema.
Type | matcher |
Chained aliases | equal to be match |
Yields | parsed json |
Related operators | header body json |
Assertion form:
res | should.satisfy.jsonschema(schema)
res | should.satisfy.jsonschema.equal.to(schema)
res | expect.to.satisfy.jsonschema(schema)
res | expect.to.satisfy.jsonschema.equal.to(schema)
Negation form:
res | should.do_not.satisfy.jsonschema(schema)
res | should.do_not.satisfy.jsonschema.equal.to(schema)
res | expect.to_not.satisfy.jsonschema(schema)
res | expect.to_not.satisfy.jsonschema.equal.to(schema)
verb¶
method¶
Asserts HTTP request method.
Type | matcher |
Chained aliases | equal to be |
Related operators | header status body |
Assertion form:
res | should.be.method('GET')
res | expect.to.be.method('GET')
Negation form:
res | should.not_be.method('GET')
res | expect.to_not.be.method('GET')
url¶
Asserts HTTP request target URL.
Type | matcher |
Chained aliases | equal to be |
Yields subject | url value |
Suboperators | path port hostname query |
Related operators | header status body |
Assertion form:
res | should.have.url('http://foo.org')
res | should.have.url('foo.org', strict=False)
res | should.have.url.hostname('foo.org')
res | should.have.url.port(80)
res | should.have.url.protocol('http')
res | should.have.url.path('/bar/baz')
res | should.have.url.query({'x': 'y', 'z': True})
res | expect.to.have.url('http://foo.org')
res | expect.to.have.url('foo.org', strict=False)
res | expect.to.have.url.hostname('foo.org')
res | expect.to.have.url.port(80)
res | expect.to.have.url.protocol('http')
res | expect.to.have.url.path('/bar/baz')
res | expect.to.have.url.query({'x': 'y', 'z': True})
Negation form:
res | should.not_have.url('http://foo.org')
res | should.not_have.url('foo.org', strict=False)
res | should.not_have.url.hostname('foo.org')
res | should.not_have.url.port(80)
res | should.not_have.url.protocol('http')
res | should.not_have.url.path('/bar/baz')
res | should.not_have.url.query({'x': 'y', 'z': True})
res | expect.to_not.have.url('http://foo.org')
res | expect.to_not.have.url('foo.org', strict=False)
res | expect.to_not.have.url.hostname('foo.org')
res | expect.to_not.have.url.port(80)
res | expect.to_not.have.url.protocol('http')
res | expect.to_not.have.url.path('/bar/baz')
res | expect.to_not.have.url.query({'x': 'y', 'z': True})