Skip to content

Commit

Permalink
feat(operators): add output size limit
Browse files Browse the repository at this point in the history
  • Loading branch information
h2non committed Mar 29, 2017
1 parent 186f117 commit 8d1bc60
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 9 deletions.
62 changes: 62 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,68 @@ Showcase
}
})
Full-featured error report example:

.. code-block:: python
Traceback (most recent call last):
File "grappa-http/tests/http_test.py", line 38, in test_http_tutorial
res | should.have.body.equal.to('{\n "foo": "baa"\n}')
File "grappa/grappa/test.py", line 208, in __ror__
return self.__overload__(value)
File "grappa/grappa/test.py", line 196, in __overload__
return self.__call__(subject, overload=True)
File "grappa/grappa/test.py", line 73, in __call__
return self._trigger() if overload else Test(subject)
File "grappa/grappa/test.py", line 113, in _trigger
raise err
AssertionError: Oops! Something went wrong!
The following assertion was not satisfied
subject "{\n "foo": "bar"\n}" should have body equal to "{\n "foo": "baa"\n}"
What we expected
a response body data equal to:
{
"foo": "baa"
}
What we got instead
a response body with data:
{
"foo": "bar"
}
Difference comparison
> {
> - "foo": "bar"
> ? ^
> + "foo": "baa"
> ? ^
> }
Where
File "grappa-http/tests/http_test.py", line 38, in test_http_tutorial
30| res | should.have.content('json')
31|
32| # Test response headers
33| (res | (should.have.header('Content-Type')
34| .that.should.be.equal('application/json')))
35| res | should.have.header('Server').that.should.contain('nginx')
36|
37| # Test response body
38| > res | should.have.body.equal.to('{\n "foo": "baa"\n}')
39| res | should.have.body.that.contains('foo')
40|
41| # Test response body length
42| res | should.have.body.length.of(20)
43| res | should.have.body.length.higher.than(10)
44|
45| # Test response JSON body
Features
--------

Expand Down
9 changes: 6 additions & 3 deletions grappa_http/operators/body.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ class BodyOperator(BaseOperator):
# Enable raw reporting mode for this operator
raw_mode = True

# Limit raw size characters
raw_size = 500

# List of suboperators
suboperators = (
JsonOperator,
Expand All @@ -58,13 +61,13 @@ class BodyOperator(BaseOperator):

# Error message templates
expected_message = Operator.Dsl.Message(
'a response body data equal to: {value}',
'a response body data not equal to: {value}',
'a response body data equal to:\n {value}',
'a response body data not equal to:\n {value}',
)

# Subject message template
subject_message = Operator.Dsl.Message(
'a response body with data: {value}',
'a response body with data:\n {value}',
)

def _on_access(self, res):
Expand Down
9 changes: 6 additions & 3 deletions grappa_http/operators/json_body.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,18 +46,21 @@ class JsonOperator(BaseOperator):
# Enable raw reporting mode for this operator
raw_mode = True

# Raw limit characters
raw_size = 500

# Show match diff on error
show_diff = True

# Error message templates
expected_message = Operator.Dsl.Message(
'a response JSON body equal to: {value}',
'a response JSON body not equal to: {value}',
'a response JSON body equal to:\n {value}',
'a response JSON body not equal to:\n {value}',
)

# Subject message template
subject_message = Operator.Dsl.Message(
'a response JSON body with data: {value}',
'a response JSON body with data:\n {value}',
)

def _on_access(self, res):
Expand Down
9 changes: 6 additions & 3 deletions grappa_http/operators/json_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,21 @@ class JsonSchemaOperator(BaseOperator):
# Enable raw reporting mode for this operator
raw_mode = True

# Limit raw size characters
raw_size = 500

# Show match diff on error
show_diff = True

# Error message templates
expected_message = Operator.Dsl.Message(
'a response JSON body that matches the JSONSchema: {value}',
'a response JSON body that does not matches the JSONSchem: {value}',
'a response JSON body that matches JSONSchema:\n {value}',
'a response JSON body that does not matches JSONSchem:\n {value}',
)

# Subject message template
subject_message = Operator.Dsl.Message(
'a JSON body with data: {value}',
'a JSON body with data:\n {value}',
)

def _on_access(self, res):
Expand Down

0 comments on commit 8d1bc60

Please sign in to comment.