Commit c87a046f authored by Andrea Il Grande's avatar Andrea Il Grande
Browse files

added mock server library

parent d09d0ab1
Loading
Loading
Loading
Loading
+262 −0
Original line number Diff line number Diff line
------------------------------------------------------------------------

CHANGE NOTES FOR 0.3.1 (RELEASED: Dec 3, 2022)

------------------------------------------------------------------------

GENERAL CHANGES

- Fixed bug in function `Send HTTPS Request Async` when HTTP protocol was used instead of HTTPS.
  See: https://github.com/annoviko/robotframework-httpctrl/pull/39

- Fixed bug with response header types when `HTTPMessage` object was returned instead of `dict`.
  See: https://github.com/annoviko/robotframework-httpctrl/issues/40


------------------------------------------------------------------------

CHANGE NOTES FOR 0.3.0 (RELEASED: Jul 4, 2022)

------------------------------------------------------------------------

GENERAL CHANGES

- Introduce new argument `resp_body_to_file` for functions `Send HTTP Request`, `Send HTTP Request Async`, 
    `Send Https Request`, `Send Https Request Async` to write response body to a file that is specified
    by the argument.
  See: https://github.com/annoviko/robotframework-httpctrl/issues/36

- Changed return type for `Get Body From Response` and `Get Response Body` from `string` to `bytes`.
  See: https://github.com/annoviko/robotframework-httpctrl/issues/37


------------------------------------------------------------------------

CHANGE NOTES FOR 0.2.7 (RELEASED: Jun 30, 2022)

------------------------------------------------------------------------

GENERAL CHANGES

- Introduce the limit for body size to log and corresponding library `HttpCtrl.Logging` to configure it.
  See: https://github.com/annoviko/robotframework-httpctrl/issues/34


------------------------------------------------------------------------

CHANGE NOTES FOR 0.2.6 (RELEASED: Apr 26, 2022)

------------------------------------------------------------------------

GENERAL CHANGES

- Fixed bug with Flask based server that reply by 404.
  See: https://github.com/annoviko/robotframework-httpctrl/issues/33


------------------------------------------------------------------------

CHANGE NOTES FOR 0.2.5 (RELEASED: Dec 24, 2021)

------------------------------------------------------------------------

GENERAL CHANGES

- Update meta-information (CHANGE file).
  See: no reference


------------------------------------------------------------------------

CHANGE NOTES FOR 0.2.4 (RELEASED: Dec 24, 2021)

------------------------------------------------------------------------

GENERAL CHANGES

- Introduced new keyword `Set Stub Reply` to create server stub functions.
  See: https://github.com/annoviko/robotframework-httpctrl/issues/30

- Introduced new keyword `Get Stub Count` to get server stub statistic.
  See: https://github.com/annoviko/robotframework-httpctrl/issues/30


------------------------------------------------------------------------

CHANGE NOTES FOR 0.2.2 (RELEASED: Oct 18, 2021)

------------------------------------------------------------------------

GENERAL CHANGES

- Fixes bug with pypi installer 0.2.1.
  See: https://github.com/annoviko/robotframework-httpctrl/issues/27


------------------------------------------------------------------------

CHANGE NOTES FOR 0.2.1 (RELEASED: Oct 8, 2021)

------------------------------------------------------------------------

GENERAL CHANGES

- Change license to The 3-Clause BSD License.
  See: https://github.com/annoviko/robotframework-httpctrl/issues/26


------------------------------------------------------------------------

CHANGE NOTES FOR 0.2.0 (RELEASED: Oct 8, 2021)

------------------------------------------------------------------------

GENERAL CHANGES

- Change license to The 3-Clause BSD License.
  See: https://github.com/annoviko/robotframework-httpctrl/issues/26

- Feature to release the library automatically.
  See: https://github.com/annoviko/robotframework-httpctrl/issues/14


------------------------------------------------------------------------

CHANGE NOTES FOR 0.1.10 (RELEASED: Oct 7, 2021)

------------------------------------------------------------------------

GENERAL CHANGES:

- Fixed bug where body was not provided for HEAD, OPTION, DELETE and GET methods (HttpCtrl.Server).
  See: https://github.com/annoviko/robotframework-httpctrl/issues/24


------------------------------------------------------------------------

CHANGE NOTES FOR 0.1.9 (RELEASED: Sep 29, 2021)

------------------------------------------------------------------------

GENERAL CHANGES:

- Support bytes body type for `Reply By` (HttpCtrl.Server).
  See: https://github.com/annoviko/robotframework-httpctrl/issues/17

CORRECTED MAJOR BUGS:

- Fixed bug where response server body was used as a response reason (HttpCtrl.Server).
  See: https://github.com/annoviko/robotframework-httpctrl/issues/19


------------------------------------------------------------------------

CHANGE NOTES FOR 0.1.8 (RELEASED: Sep 28, 2021)

------------------------------------------------------------------------

GENERAL CHANGES:

- Option to bind client to the specific address only without port (HttpCtrl.Client).
  See: https://github.com/annoviko/robotframework-httpctrl/issues/21


------------------------------------------------------------------------

CHANGE NOTES FOR 0.1.7 (RELEASED: Sep 27, 2021)

------------------------------------------------------------------------

GENERAL CHANGES:

- Option to bind client to the specific address and port (HttpCtrl.Client).
  See: https://github.com/annoviko/robotframework-httpctrl/issues/21

- Supported IPv6 address (HttpCtrl.Client, HttpCtrl.Server).
  See: https://github.com/annoviko/robotframework-httpctrl/issues/15


------------------------------------------------------------------------

CHANGE NOTES FOR 0.1.6 (RELEASED: Jan 13, 2020)

------------------------------------------------------------------------

CORRECTED MAJOR BUGS:

- Fixed bug where function `Get Async Response` hangs when timeout is specified and message is not received (HttpCtrl.Server).
  See: https://github.com/annoviko/robotframework-httpctrl/issues/13


------------------------------------------------------------------------

CHANGE NOTES FOR 0.1.5 (RELEASED: Jan 13, 2020)

------------------------------------------------------------------------

CORRECTED MAJOR BUGS:

- Missing package in setup.py.
  See: https://github.com/annoviko/robotframework-httpctrl/issues/10


------------------------------------------------------------------------

CHANGE NOTES FOR 0.1.4 (RELEASED: Jan 13, 2020)

------------------------------------------------------------------------

GENERAL CHANGES:

- Introduced argument `timeout` for function `Wait For Request` to specify waiting time (HttpCtrl.Server).
  See: https://github.com/annoviko/robotframework-httpctrl/issues/11


------------------------------------------------------------------------

CHANGE NOTES FOR 0.1.3 (RELEASED: Oct 25, 2019)

------------------------------------------------------------------------

GENERAL CHANGES:

- Function `Wait And Ingore Request` to ignore incoming request by closing connection (HttpCtrl.Server).
  See: https://github.com/annoviko/robotframework-httpctrl/issues/8

- Optimized termination of the HTTP(S) server - problem with up-to 5 seconds delay (HttpCtrl.Server).
  See: https://github.com/annoviko/robotframework-httpctrl/issues/7

- Functions to work with async. received responses are introduced (HttpCtrl.Client).
  See: https://github.com/annoviko/robotframework-httpctrl/issues/5

- Functions `Send HTTPS Request Async` and `Send HTTP Request Async` must returns connection (HttpCtrl.Client).
  See: https://github.com/annoviko/robotframework-httpctrl/issues/5

CORRECTED MAJOR BUGS:

- Fixed bug where function `Wait For No Requests` ignored input timeout and always uses 5 seconds (HttpCtrl.Server).
  See: https://github.com/annoviko/robotframework-httpctrl/issues/6


------------------------------------------------------------------------

CHANGE NOTES FOR 0.1.2 (RELEASED: Sep 10, 2019)

------------------------------------------------------------------------

GENERAL CHANGES:

- Built-in documentation is updated.
  See: no reference


------------------------------------------------------------------------

CHANGE NOTES FOR 0.1.1 (RELEASED: Sep 9, 2019)

------------------------------------------------------------------------

GENERAL CHANGES:

- Bug correction for HttpCtrl.Server when client close connection after sending request.
  See: no reference
+29 −0
Original line number Diff line number Diff line
Copyright (c) 2018-2022 Andrei Novikov

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:

    1. Redistributions of source code must retain the above copyright
        notice, this list of conditions and the following disclaimer.

    2. Redistributions in binary form must reproduce the above
        copyright notice, this list of conditions and the following
        disclaimer in the documentation and/or other materials provided
        with the distribution.

    3. Neither the name of the copyright holder nor the names of its
        contributors may be used to endorse or promote products derived
        from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 No newline at end of file
+111 −0
Original line number Diff line number Diff line
HttpCtrl library for Robot Framework
====================================

**RobotFramework-HttpCtrl** is a library for Robot Framework that provides HTTP/HTTPS client and HTTP (IPv4 and IPv6) server services
to make REST API testing easy.

**License**: The 3-Clause BSD License

**Documentation**: https://annoviko.github.io/robotframework-httpctrl/


Dependencies
============

**Python version**: >=3.8


Setup
============

Make sure to add the src/ directory to your PYTHONPATH. This allows Python and Robot Framework to correctly locate the HttpCtrl modules.


Brief Overview of the Library Content
=====================================

**HttpCtrl** contains following general libraries:

- **HttpCtrl.Client** - provides API to work with HTTP/HTTPS client [`link client documentation`_].

- **HttpCtrl.Server** - provides API to work with HTTP server [`link server documentation`_].

- **HttpCtrl.Json** - provides API to work Json messages [`link json documentation`_].

- **HttpCtrl.Logging** - provides API to configure the logging system that is used by `HttpCtrl` library [`link logging documentation`_].

.. _link client documentation: https://annoviko.github.io/robotframework-httpctrl/client.html
.. _link server documentation: https://annoviko.github.io/robotframework-httpctrl/server.html
.. _link json documentation: https://annoviko.github.io/robotframework-httpctrl/json.html
.. _link logging documentation: https://annoviko.github.io/robotframework-httpctrl/logging.html


Examples
========

Send GET request to obtain origin IP address and check that is not empty:

.. code:: robotframework

    *** Settings ***

    Library         HttpCtrl.Client
    Library         HttpCtrl.Json

    *** Test Cases ***

    Get Origin Address
        Initialize Client   www.httpbin.org
        Send HTTP Request   GET   /ip

        ${response status}=   Get Response Status
        ${response body}=     Get Response Body
        ${response body}=     Decode Bytes To String   ${response body}   UTF-8

        ${expected status}=   Convert To Integer   200
        Should Be Equal   ${response status}   ${expected status}

        ${origin}=    Get Json Value From String   ${response body}   origin
        Should Not Be Empty   ${origin}


In this example HTTP client sends POST request to HTTP server. HTTP server receives it and checks incoming
request for correctness.

.. code:: robotframework

    *** Settings ***

    Library         String
    Library         HttpCtrl.Client
    Library         HttpCtrl.Server

    Test Setup       Initialize HTTP Client And Server
    Test Teardown    Terminate HTTP Server

    *** Test Cases ***

    Receive And Reply To POST
        ${request body}=   Set Variable   { "message": "Hello!" }
        Send HTTP Request Async   POST   /post   ${request body}

        Wait For Request
        Reply By   200

        ${method}=   Get Request Method
        ${url}=      Get Request Url
        ${body}=     Get Request Body
        ${body}=     Decode Bytes To String   ${body}   UTF-8

        Should Be Equal   ${method}   POST
        Should Be Equal   ${url}      /post
        Should Be Equal   ${body}     ${request body}

    *** Keywords ***

    Initialize HTTP Client And Server
        Initialize Client   127.0.0.1   8000
        Start Server        127.0.0.1   8000

    Terminate HTTP Server
        Stop Server
 No newline at end of file
+199 −0
Original line number Diff line number Diff line
|Build Status Linux| |PyPi|

HttpCtrl library for Robot Framework
====================================

**RobotFramework-HttpCtrl** is a library for Robot Framework that provides HTTP/HTTPS client and HTTP server (IPv4 and IPv6) services
to make REST API testing easy.

**Author**: Andrei Novikov

**License**: The 3-Clause BSD License

**Documentation**: https://annoviko.github.io/robotframework-httpctrl/


Request Feature
===============

New features are implemented by request that can be created here using issues [`Press Me to Create a Feature Request`_]. Please, do not hesitate to create feature requests.

.. _Press Me to Create a Feature Request: https://github.com/annoviko/robotframework-httpctrl/issues/new?assignees=&labels=&template=feature_request.md&title=


Bug Reporting
=============

Please, do not hesitate to report about bugs using issues here [`Press Me to Report a Bug`_].

.. _Press Me to Report a Bug: https://github.com/annoviko/robotframework-httpctrl/issues/new?assignees=&labels=bug&template=bug_report.md&title=


Dependencies
============

**Python version**: >=3.8


Setup
============

Make sure to add the src/ directory to your PYTHONPATH. This allows Python and Robot Framework to correctly locate the HttpCtrl modules.


Brief Overview of the Library Content
=====================================

**HttpCtrl** contains following general libraries:

- **HttpCtrl.Client** - provides API to work with HTTP/HTTPS client [`link client documentation`_].

- **HttpCtrl.Server** - provides API to work with HTTP server [`link server documentation`_].

- **HttpCtrl.Json** - provides API to work Json messages [`link json documentation`_].

- **HttpCtrl.Logging** - provides API to configure the logging system that is used by `HttpCtrl` library [`link logging documentation`_].

.. _link client documentation: https://annoviko.github.io/robotframework-httpctrl/client.html
.. _link server documentation: https://annoviko.github.io/robotframework-httpctrl/server.html
.. _link json documentation: https://annoviko.github.io/robotframework-httpctrl/json.html
.. _link logging documentation: https://annoviko.github.io/robotframework-httpctrl/logging.html


Examples
========

Send GET request to obtain origin IP address and check that is not empty:

.. code:: robotframework

    *** Settings ***

    Library         String
    Library         HttpCtrl.Client
    Library         HttpCtrl.Json

    *** Test Cases ***

    Get Origin Address
        Initialize Client   www.httpbin.org
        Send HTTP Request   GET   /ip

        ${response status}=   Get Response Status
        ${response body}=     Get Response Body
        ${response body}=     Decode Bytes To String   ${response body}   UTF-8

        ${expected status}=   Convert To Integer   200
        Should Be Equal   ${response status}   ${expected status}

        ${origin}=    Get Json Value From String   ${response body}   origin
        Should Not Be Empty   ${origin}


Send POST request and extract required information from response:

.. code:: robotframework

    *** Settings ***

    Library         String
    Library         HttpCtrl.Client
    Library         HttpCtrl.Json

    *** Test Cases ***

    Send POST Request
        Initialize Client   www.httpbin.org

        ${body}=   Set Variable   { "message": "Hello World!" }
        Send HTTP Request   POST   /post   ${body}

        ${response status}=   Get Response Status
        ${response body}=     Get Response Body
        ${response body}=     Decode Bytes To String   ${response body}   UTF-8

        ${expected status}=   Convert To Integer   200
        Should Be Equal   ${response status}   ${expected status}

        ${message}=    Get Json Value From String   ${response body}   data
        Should Be Equal   ${message}   ${body}


Send PATCH request using HTTPS protocol:

.. code:: robotframework

    *** Settings ***

    Library         String
    Library         HttpCtrl.Client
    Library         HttpCtrl.Json

    *** Test Cases ***

    Send HTTPS PATCH Request
        Initialize Client   www.httpbin.org

        ${body}=   Set Variable   { "volume": 77, "mute": false }
        Send HTTPS Request   PATCH   /patch   ${body}

        ${response status}=   Get Response Status
        ${response body}=     Get Response Body
        ${response body}=     Decode Bytes To String   ${response body}   UTF-8

        ${expected status}=   Convert To Integer   200
        Should Be Equal   ${response status}   ${expected status}

        ${volume}=   Get Json Value From String   ${response body}   json/volume
        Should Be Equal   ${volume}   ${77}

        ${mute}=   Get Json Value From String   ${response body}   json/mute
        Should Be Equal   ${mute}   ${False}


In this example HTTP client sends POST request to HTTP server. HTTP server receives it and checks incoming
request for correctness.

.. code:: robotframework

    *** Settings ***

    Library         String
    Library         HttpCtrl.Client
    Library         HttpCtrl.Server

    Test Setup       Initialize HTTP Client And Server
    Test Teardown    Terminate HTTP Server

    *** Test Cases ***

    Receive And Reply To POST
        ${request body}=   Set Variable   { "message": "Hello!" }
        Send HTTP Request Async   POST   /post   ${request body}

        Wait For Request
        Reply By   200

        ${method}=   Get Request Method
        ${url}=      Get Request Url
        ${body}=     Get Request Body
        ${body}=     Decode Bytes To String   ${body}   UTF-8

        Should Be Equal   ${method}   POST
        Should Be Equal   ${url}      /post
        Should Be Equal   ${body}     ${request body}

    *** Keywords ***

    Initialize HTTP Client And Server
        Initialize Client   127.0.0.1   8000
        Start Server        127.0.0.1   8000

    Terminate HTTP Server
        Stop Server


.. |Build Status Linux| image:: https://github.com/annoviko/robotframework-httpctrl/actions/workflows/build-httpctrl.yml/badge.svg
   :target: https://github.com/annoviko/robotframework-httpctrl/actions
.. |PyPi| image:: https://badge.fury.io/py/robotframework-httpctrl.svg
   :target: https://badge.fury.io/py/robotframework-httpctrl
 No newline at end of file
+1 −0
Original line number Diff line number Diff line
0.3.1
Loading