Skip to content

Commit 107cb0d

Browse files
authored
Merge pull request #35 from annoviko/feature/034-body-log
Feature: Limit body to log
2 parents 9411fbb + a15ebf9 commit 107cb0d

20 files changed

+217
-26
lines changed

CHANGES

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
11
------------------------------------------------------------------------
22

3+
CHANGE NOTES FOR 0.2.7 (RELEASED: Jun 30, 2022)
4+
5+
------------------------------------------------------------------------
6+
7+
GENERAL CHANGES
8+
9+
- Introduce the limit for body size to log and corresponding library `HttpCtrl.Logging` to configure it.
10+
See: https://github.com/annoviko/robotframework-httpctrl/issues/34
11+
12+
13+
------------------------------------------------------------------------
14+
315
CHANGE NOTES FOR 0.2.6 (RELEASED: Apr 26, 2022)
416

517
------------------------------------------------------------------------

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Copyright (c) 2018-2021 Andrei Novikov
1+
Copyright (c) 2018-2022 Andrei Novikov
22

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

PKG-INFO.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,12 @@ Brief Overview of the Library Content
3636

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

39+
- **HttpCtrl.Logging** - provides API to configure the logging system that is used by `HttpCtrl` library [`link logging documentation`_].
40+
3941
.. _link client documentation: https://annoviko.github.io/robotframework-httpctrl/client.html
4042
.. _link server documentation: https://annoviko.github.io/robotframework-httpctrl/server.html
4143
.. _link json documentation: https://annoviko.github.io/robotframework-httpctrl/json.html
44+
.. _link logging documentation: https://annoviko.github.io/robotframework-httpctrl/logging.html
4245

4346

4447
Examples

README.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,12 @@ Brief Overview of the Library Content
5656

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

59+
- **HttpCtrl.Logging** - provides API to configure the logging system that is used by `HttpCtrl` library [`link logging documentation`_].
60+
5961
.. _link client documentation: https://annoviko.github.io/robotframework-httpctrl/client.html
6062
.. _link server documentation: https://annoviko.github.io/robotframework-httpctrl/server.html
6163
.. _link json documentation: https://annoviko.github.io/robotframework-httpctrl/json.html
64+
.. _link logging documentation: https://annoviko.github.io/robotframework-httpctrl/logging.html
6265

6366

6467
Examples

ci/github-ci-release.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ cd $PATH_SOURCE
104104
python3 -m robot.libdoc -v $version -F reST HttpCtrl.Client $PATH_REPO_GH_PAGES/client.html
105105
python3 -m robot.libdoc -v $version -F reST HttpCtrl.Server $PATH_REPO_GH_PAGES/server.html
106106
python3 -m robot.libdoc -v $version -F reST HttpCtrl.Json $PATH_REPO_GH_PAGES/json.html
107+
python3 -m robot.libdoc -v $version -F reST HttpCtrl.Logging $PATH_REPO_GH_PAGES/logging.html
107108

108109

109110
# Commit and push documentation changes

ci/github-ci.sh

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
# folders
2+
FOLDER_ROOT=`pwd`
3+
FOLDER_SRC=$FOLDER_ROOT/src
4+
FOLDER_TST=$FOLDER_ROOT/tst
5+
16
# error codes
27
EXIT_CODE_INCORRECT_PATH=1
38
EXIT_CODE_FAILED_TESTING=2
@@ -12,15 +17,15 @@ pip3 install docutils pygments
1217

1318
# export path to the library
1419
echo "Export path to the HttpCtrl library."
15-
cd src || exit $EXIT_CODE_INCORRECT_PATH
20+
cd $FOLDER_SRC || exit $EXIT_CODE_INCORRECT_PATH
1621
PYTHONPATH=`pwd`
1722
export PYTHONPATH=${PYTHONPATH}
1823

1924
echo "Path '$PYTHONPATH' is exported."
2025

2126
# run tests
2227
echo "Run tests for HttpCtrl."
23-
cd ../tst || exit $EXIT_CODE_INCORRECT_PATH
28+
cd $FOLDER_TST || exit $EXIT_CODE_INCORRECT_PATH
2429
python3 -m robot.run *.robot
2530
result=$?
2631

@@ -33,7 +38,12 @@ fi
3338

3439
# generate documentation
3540
echo "Generate documentation for HttpCtrl."
36-
cd ../src || exit $EXIT_CODE_INCORRECT_PATH
37-
python3 -m robot.libdoc -v 0.1.10 -F reST HttpCtrl.Client client.html
38-
python3 -m robot.libdoc -v 0.1.10 -F reST HttpCtrl.Server server.html
39-
python3 -m robot.libdoc -v 0.1.10 -F reST HttpCtrl.Json json.html
41+
42+
cd $FOLDER_ROOT
43+
version=`cat VERSION`
44+
45+
cd $FOLDER_SRC || exit $EXIT_CODE_INCORRECT_PATH
46+
python3 -m robot.libdoc -v $version -F reST HttpCtrl.Client client.html
47+
python3 -m robot.libdoc -v $version -F reST HttpCtrl.Server server.html
48+
python3 -m robot.libdoc -v $version -F reST HttpCtrl.Json json.html
49+
python3 -m robot.libdoc -v $version -F reST HttpCtrl.Logging logging.html

setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
HttpCtrl library provides HTTP/HTTPS client and server API to Robot Framework to make REST API testing easy.
44
55
Authors: Andrei Novikov
6-
Date: 2018-2021
6+
Date: 2018-2022
77
Copyright: The 3-Clause BSD License
88
99
"""
@@ -63,7 +63,7 @@ def load_version():
6363
author='Andrei Novikov',
6464
author_email='spb.andr@yandex.ru',
6565

66-
python_requires='>=3.4',
66+
python_requires='>=3.6',
6767
install_requires=['robotframework'],
6868

6969
package_dir={'': 'src'},

src/HttpCtrl/__init__.py

Lines changed: 71 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
HttpCtrl library provides HTTP/HTTPS client and server API to Robot Framework to make REST API testing easy.
44
55
Authors: Andrei Novikov
6-
Date: 2018-2021
6+
Date: 2018-2022
77
Copyright: The 3-Clause BSD License
88
99
"""
@@ -15,6 +15,8 @@
1515

1616
from robot.api import logger
1717

18+
from HttpCtrl.utils.logger import LoggerAssistant
19+
1820
from HttpCtrl.internal_messages import IgnoreRequest
1921
from HttpCtrl.http_server import HttpServer
2022
from HttpCtrl.http_stub import HttpStubContainer, HttpStubCriteria
@@ -26,16 +28,19 @@
2628
class 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):
658664
class 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):
12831292
class 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)

src/HttpCtrl/http_handler.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
HttpCtrl library provides HTTP/HTTPS client and server API to Robot Framework to make REST API testing easy.
44
55
Authors: Andrei Novikov
6-
Date: 2018-2021
6+
Date: 2018-2022
77
Copyright: The 3-Clause BSD License
88
99
"""

src/HttpCtrl/http_server.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
HttpCtrl library provides HTTP/HTTPS client and server API to Robot Framework to make REST API testing easy.
44
55
Authors: Andrei Novikov
6-
Date: 2018-2021
6+
Date: 2018-2022
77
Copyright: The 3-Clause BSD License
88
99
"""

0 commit comments

Comments
 (0)