33HttpCtrl library provides HTTP/HTTPS client and server API to Robot Framework to make REST API testing easy.
44
55Authors: Andrei Novikov
6- Date: 2018-2021
6+ Date: 2018-2022
77Copyright: The 3-Clause BSD License
88
99"""
1515
1616from robot .api import logger
1717
18+ from HttpCtrl .utils .logger import LoggerAssistant
19+
1820from HttpCtrl .internal_messages import IgnoreRequest
1921from HttpCtrl .http_server import HttpServer
2022from HttpCtrl .http_stub import HttpStubContainer , HttpStubCriteria
2628class Client :
2729 """
2830
29- HTTP/HTTPS Client Library that provides comprehensive interface to Robot Framework to control HTTP/HTTPS client.
31+ HTTP/HTTPS Client library that provides comprehensive interface to Robot Framework to control HTTP/HTTPS client.
3032
3133 See other HttpCtrl libraries:
3234
3335 - HttpCtrl.Server_ - HTTP Server API for testing where easy-controlled HTTP server is required.
3436
3537 - HttpCtrl.Json_ - Json related API for testing where work with Json message is required.
3638
39+ - HttpCtrl.Logging_ - Logging related API to configure the logging system that is used by HttpCtrl library.
40+
3741 .. _HttpCtrl.Server: server.html
3842 .. _HttpCtrl.Json: json.html
43+ .. _HttpCtrl.Logging: logging.html
3944
4045 Example how to send GET request to obtain origin IP address and check that response is not empty:
4146
@@ -212,7 +217,8 @@ def __send(self, connection_type, method, url, body):
212217 logger .info ("Request (type: '%s', method '%s') was sent to '%s'." % (connection_type , method , endpoint ))
213218 logger .info ("%s %s" % (method , url ))
214219 if body is not None :
215- logger .info ("%s" % body )
220+ body_to_log = LoggerAssistant .get_body (body )
221+ logger .info ("%s" % body_to_log )
216222
217223 return connection
218224
@@ -658,16 +664,19 @@ def get_body_from_response(self, response):
658664class Server :
659665 """
660666
661- HTTP Server Library that provides comprehensive interface to Robot Framework to control HTTP server.
667+ HTTP Server library that provides comprehensive interface to Robot Framework to control HTTP server.
662668
663669 See other HttpCtrl libraries:
664670
665671 - HttpCtrl.Client_ - HTTP/HTTP Client API for testing where easy-controlled HTTP/HTTPS client is required.
666672
667673 - HttpCtrl.Json_ - Json related API for testing where work with Json message is required.
668674
675+ - HttpCtrl.Logging_ - Logging related API to configure the logging system that is used by HttpCtrl library.
676+
669677 .. _HttpCtrl.Client: client.html
670678 .. _HttpCtrl.Json: json.html
679+ .. _HttpCtrl.Logging: logging.html
671680
672681 Here is an example of receiving POST request. In this example HTTP client sends POST request to HTTP server. HTTP
673682 server receives it and checks incoming request for correctness.
@@ -1283,7 +1292,7 @@ def reply_by(self, status, body=None):
12831292class Json :
12841293 """
12851294
1286- Json Library provide comprehensive interface to Robot Framework to work with JSON structures that are actively
1295+ Json library provide comprehensive interface to Robot Framework to work with JSON structures that are actively
12871296 used for Internet communication nowadays.
12881297
12891298 See other HttpCtrl libraries:
@@ -1292,8 +1301,11 @@ class Json:
12921301
12931302 - HttpCtrl.Server_ - HTTP Server API for testing where easy-controlled HTTP server is required.
12941303
1304+ - HttpCtrl.Logging_ - Logging related API to configure the logging system that is used by HttpCtrl library.
1305+
12951306 .. _HttpCtrl.Client: client.html
12961307 .. _HttpCtrl.Server: server.html
1308+ .. _HttpCtrl.Logging: logging.html
12971309
12981310 Example where Json values are updated in a string and then read from it:
12991311
@@ -1457,3 +1469,57 @@ def set_json_value_in_string(json_string, path, value):
14571469 current_element = current_element [key ]
14581470
14591471 return json .dumps (json_content )
1472+
1473+
1474+
1475+ class Logging :
1476+ """
1477+
1478+ Logging library provide functionality to configure the logging system that is used by HttpCtrl library.
1479+
1480+ See other HttpCtrl libraries:
1481+
1482+ - HttpCtrl.Client_ - HTTP/HTTP Client API for testing where easy-controlled HTTP/HTTPS client is required.
1483+
1484+ - HttpCtrl.Server_ - HTTP Server API for testing where easy-controlled HTTP server is required.
1485+
1486+ - HttpCtrl.Json_ - Json related API for testing where work with Json message is required.
1487+
1488+ .. _HttpCtrl.Client: client.html
1489+ .. _HttpCtrl.Server: server.html
1490+ .. _HttpCtrl.Json: json.html
1491+
1492+ """
1493+
1494+ @staticmethod
1495+ def set_body_size_limit_to_log (body_size ):
1496+ """
1497+
1498+ Set body (HTTP request/response) size that is allowed to log. By default the library logs `512` symbols of the body. If the
1499+ limit should be removed then `${None}` value can be provided to the function.
1500+
1501+ The logging body limit protects test logs to be too large if tests use big data for testing.
1502+
1503+ Example how to set the logging body limit to 1024 symbols:
1504+
1505+ +----------------------------+------+
1506+ | Set Body Size Limit To Log | 1024 |
1507+ +----------------------------+------+
1508+
1509+ .. code:: text
1510+
1511+ Set Body Size Limit To Log 1024
1512+
1513+ Example how to remove the logging body limit:
1514+
1515+ +----------------------------+---------+
1516+ | Set Body Size Limit To Log | ${None} |
1517+ +----------------------------+---------+
1518+
1519+ .. code:: text
1520+
1521+ Set Body Size Limit To Log ${None}
1522+
1523+ """
1524+
1525+ LoggerAssistant .set_body_size (body_size )
0 commit comments