Skip to content

Commit

Permalink
docs: Explain how integration tests work
Browse files Browse the repository at this point in the history
  • Loading branch information
mauricioabreu committed Jun 6, 2018
1 parent 9d00945 commit 0c516f8
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
34 changes: 34 additions & 0 deletions docs/contributing/testing.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
Testing the client
==================

Every feature of a codebase must be tested if we want to be more confident about it.
Tests help to document what the code does and how it works. Need a new feature or need to change
the behavior of a current function? Tests are here to cover you.

Integration tests
-----------------

The purpose of an Integration test is to ensure that our code units, depending on other units, work as expected.
In our case, we need to test how our code behave when interacting to the real API. How does it handle real JSON responses?

To acomplish this task, we use `Betamax <https://github.com/betamaxpy/betamax>`_ library. It records real requests made to the API,
saves it as JSON and replays it next time, without hitting the production site again.

Here is an example on how to test the creation of a new configuration:

.. code-block:: python
class TestConfiguration(object):
def test_create_configuration(self):
client = Azion(token)
recorder = betamax.Betamax(client.session)
with recorder.use_cassette('Configuration_create'):
configuration = client.create_configuration(
'Dummy configuration', 'www.example.com', 'ww2.example.com',
cname=['www.example-cname.com'], delivery_protocol='http')
assert isinstance(configuration, Configuration)
`Cassettes` are the files used to store/load requests and responses. A good convention is to name them with the resource capitalized
and the action of the API function in lowercase, for example: ``Configuration_create``
8 changes: 8 additions & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,14 @@ API

api/index

Contributing
============

.. toctree::
:maxdepth: 2

contributing/testing

Indices and tables
==================

Expand Down

0 comments on commit 0c516f8

Please sign in to comment.