You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+44-42Lines changed: 44 additions & 42 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,11 +1,11 @@
1
1
# Getting Start Unit Test for an HTTP REST Application with Python
2
-
- version: 1.1
3
-
- Last update: Jan 2023
2
+
- version: 2.0
3
+
- Last update: Feb 2025
4
4
- Environment: Windows
5
5
- Prerequisite: [Access to RDP credentials](#prerequisite)
6
6
7
7
Example Code Disclaimer:
8
-
ALL EXAMPLE CODE IS PROVIDED ON AN “AS IS” AND “AS AVAILABLE” BASIS FOR ILLUSTRATIVE PURPOSES ONLY. REFINITIV MAKES NO REPRESENTATIONS OR WARRANTIES OF ANY KIND, EXPRESS OR IMPLIED, AS TO THE OPERATION OF THE EXAMPLE CODE, OR THE INFORMATION, CONTENT, OR MATERIALS USED IN CONNECTION WITH THE EXAMPLE CODE. YOU EXPRESSLY AGREE THAT YOUR USE OF THE EXAMPLE CODE IS AT YOUR SOLE RISK.
8
+
ALL EXAMPLE CODE IS PROVIDED ON AN “AS IS” AND “AS AVAILABLE” BASIS FOR ILLUSTRATIVE PURPOSES ONLY. LSEG MAKES NO REPRESENTATIONS OR WARRANTIES OF ANY KIND, EXPRESS OR IMPLIED, AS TO THE OPERATION OF THE EXAMPLE CODE, OR THE INFORMATION, CONTENT, OR MATERIALS USED IN CONNECTION WITH THE EXAMPLE CODE. YOU EXPRESSLY AGREE THAT YOUR USE OF THE EXAMPLE CODE IS AT YOUR SOLE RISK.
9
9
10
10
## <aid="intro"></a>Introduction
11
11
@@ -15,7 +15,7 @@ Unit testing is a software testing method that helps developers verify if any ch
15
15
16
16
Modern applications also need to connect to other services like APIs, databases, data storage, etc. The unit testing needs to cover those modules too. This example project shows how to run unit test cases for a [Python](https://www.python.org/) application that performs HTTP REST operations which is the most basic task of today's application functionality. With unit testing, developers can verify if their code can connect and consume content via HTTP REST API in any code updates.
17
17
18
-
The demo application uses a de-facto [Requests](https://requests.readthedocs.io/en/latest/) library to connect to the [Refinitiv Data Platform (RDP) APIs](https://developers.refinitiv.com/en/api-catalog/refinitiv-data-platform/refinitiv-data-platform-apis) as the example HTTP REST APIs and uses the Python built-in [unittest](https://docs.python.org/3.9/library/unittest.html) as a test framework.
18
+
The demo application uses a de-facto [Requests](https://requests.readthedocs.io/en/latest/) library to connect to the [Delivery Platform (RDP) APIs](https://developers.lseg.com/en/api-catalog/refinitiv-data-platform/refinitiv-data-platform-apis)(formerly known as Refinitiv Data Platform)as the example HTTP REST APIs and uses the Python built-in [unittest](https://docs.python.org/3.9/library/unittest.html) as a test framework.
19
19
20
20
**Note**:
21
21
This demo project is not cover all test cases for the HTTP operations and all RDP APIs services. It aims to give the readers an idea about how to unit test an application that makes an HTTP connection with Python only.
@@ -80,23 +80,24 @@ Please find more detail about the unittest framework from the following resource
80
80
-[unittest standard library documentation](https://docs.python.org/3.9/library/unittest.html).
81
81
-[Getting Started With Testing in Python](https://realpython.com/python-testing/).
82
82
83
-
## <aid="whatis_rdp"></a>What is Refinitiv Data Platform (RDP) APIs?
83
+
## <aid="whatis_rdp"></a>What is Delivery Platform (RDP) APIs?
84
84
85
-
The [Refinitiv Data Platform (RDP) APIs](https://developers.refinitiv.com/en/api-catalog/refinitiv-data-platform/refinitiv-data-platform-apis) provide various Refinitiv data and content for developers via easy-to-use Web-based API.
85
+
The [RDP APIs](https://developers.lseg.com/en/api-catalog/refinitiv-data-platform/refinitiv-data-platform-apis) provide various LSEG data and content for developers via easy-to-use Web-based API.
86
86
87
-
RDP APIs give developers seamless and holistic access to all of the Refinitiv content such as Environmental Social and Governance (ESG), News, Research, etc, and commingled with their content, enriching, integrating, and distributing the data through a single interface, delivered wherever they need it. The RDP APIs delivery mechanisms are the following:
88
-
* Request - Response: RESTful web service (HTTP GET, POST, PUT or DELETE)
89
-
* Alert: delivery is a mechanism to receive asynchronous updates (alerts) to a subscription.
90
-
* Bulks: deliver substantial payloads, like the end-of-day pricing data for the whole venue.
91
-
* Streaming: deliver real-time delivery of messages.
87
+
RDP APIs give developers seamless and holistic access to all of the LSEG content such as Environmental Social and Governance (ESG), News, Research, etc, and commingled with their content, enriching, integrating, and distributing the data through a single interface, delivered wherever they need it. The RDP APIs delivery mechanisms are the following:
88
+
89
+
- Request - Response: RESTful web service (HTTP GET, POST, PUT or DELETE)
90
+
- Alert: delivery is a mechanism to receive asynchronous updates (alerts) to a subscription.
91
+
- Bulks: deliver substantial payloads, like the end-of-day pricing data for the whole venue.
92
+
- Streaming: deliver real-time delivery of messages.
92
93
93
94
This example project is focusing on the Request-Response: RESTful web service delivery method only.
94
95
95
-

96
+

96
97
97
-
For more detail regarding the Refinitiv Data Platform, please see the following APIs resources:
## <aid="testsuite_detail"></a>Test Suit Development Detail
@@ -108,11 +109,11 @@ Please see the full details over the test suite implementation on the [unittest-
108
109
This demo project requires the following dependencies.
109
110
110
111
1. RDP Access credentials.
111
-
2.Python [Anaconda](https://www.anaconda.com/distribution/) or [MiniConda](https://docs.conda.io/en/latest/miniconda.html) distribution/package manager.
112
+
2.[Python](https://www.python.org/) 3.10 and above
112
113
3.[Docker Desktop/Engine](https://docs.docker.com/get-docker/) application for running the test suite with Docker.
113
114
5. Internet connection.
114
115
115
-
Please contact your Refinitiv representative to help you to access the RDP account and services. You can find more detail regarding the RDP access credentials set up from the lease see the *Getting Started for User ID* section of the [Getting Start with Refinitiv Data Platform](https://developers.refinitiv.com/en/article-catalog/article/getting-start-with-refinitiv-data-platform) article.
116
+
Please contact your LSEG representative to help you to access the RDP account and services. You can find more detail regarding the RDP access credentials set up from the lease see the *Getting Started for User ID* section of the [Getting Start with Data Platform](https://developers.lseg.com/en/article-catalog/article/getting-start-with-refinitiv-data-platform) article.
116
117
117
118
118
119
## <aid="how_to_run"></a>How to run the example test suite
@@ -121,14 +122,14 @@ The first step is to unzip or download the example project folder into a directo
121
122
122
123
### <aid="python_example_run"></a>Run example test suite in a console
123
124
124
-
1. Open Anaconda Prompt and go to the project's folder.
125
-
2. Run the following command in the Anaconda Prompt application to create a Conda environment named *http_unittest* for the project.
125
+
1. Open a Command Prompt and go to the project's folder.
126
+
2. Run the following command in the Command Prompt application to create a Python Virtual environment named *http_unittest* for the project.
@@ -197,30 +198,31 @@ This example project demonstrates the manual unit testing method. However, devel
197
198
198
199
The [unittest](https://docs.python.org/3.9/library/unittest.html) framework and [Responses](https://github.com/getsentry/responses) mocking library are very good starting points to learn a unit test with [Python](https://www.python.org/) and build a simple test suite to test HTTP operations source code. If developers need more advanced features, they can explore other Python unit test frameworks such as [pytest](https://docs.pytest.org/en/7.1.x/), [nose2](https://github.com/nose-devs/nose2), or [doctest](https://github.com/doctest/doctest).
199
200
200
-
At the same time, the [Refinitiv Data Platform (RDP) APIs](https://developers.refinitiv.com/en/api-catalog/refinitiv-data-platform/refinitiv-data-platform-apis) provide various Refinitiv data and content for developers via an easy-to-use Web-based API. The APIs are easy to integrate into any application and platform that supports the HTTP protocol and JSON message format.
201
+
At the same time, the [RDP APIs](https://developers.lseg.com/en/api-catalog/refinitiv-data-platform/refinitiv-data-platform-apis) provide various LSEG data and content for developers via an easy-to-use Web-based API. The APIs are easy to integrate into any application and platform that supports the HTTP protocol and JSON message format.
201
202
202
203
## <a id="references"></a>References
203
204
204
205
That brings me to the end of my unit test example project. For further details, please check out the following resources:
205
-
* [Refinitiv Data Platform APIs page](https://developers.refinitiv.com/en/api-catalog/refinitiv-data-platform/refinitiv-data-platform-apis) on the [Refinitiv Developer Community](https://developers.refinitiv.com/) website.
206
-
* [Refinitiv Data Platform APIs Playground page](https://api.refinitiv.com).
207
-
* [Refinitiv Data Platform APIs: Introduction to the Request-Response API](https://developers.refinitiv.com/en/api-catalog/refinitiv-data-platform/refinitiv-data-platform-apis/tutorials#introduction-to-the-request-response-api).
208
-
* [Refinitiv Data Platform APIs: Authorization - All about tokens](https://developers.refinitiv.com/en/api-catalog/refinitiv-data-platform/refinitiv-data-platform-apis/tutorials#authorization-all-about-tokens).
209
-
* [Limitations and Guidelines for the RDP Authentication Service](https://developers.refinitiv.com/en/article-catalog/article/limitations-and-guidelines-for-the-rdp-authentication-service) article.
210
-
* [Getting Started with Refinitiv Data Platform](https://developers.refinitiv.com/en/article-catalog/article/getting-start-with-refinitiv-data-platform) article.
211
-
* [Python unittest framework official page](https://docs.python.org/3/library/unittest.html).
* [Python Guide: Testing Your Code](https://docs.python-guide.org/writing/tests/) article.
214
-
* [Getting Started With Testing in Python](https://realpython.com/python-testing/) article.
215
-
* [Mocking External APIs in Python](https://realpython.com/testing-third-party-apis-with-mocks/) article.
216
-
* [How To Use unittest to Write a Test Case for a Function in Python](https://www.digitalocean.com/community/tutorials/how-to-use-unittest-to-write-a-test-case-for-a-function-in-python) article.
217
-
* [Mocking API calls in Python](https://auth0.com/blog/mocking-api-calls-in-python/) article.
218
-
* [How and when to use Unit Testing properly](https://softwareengineering.stackexchange.com/questions/89064/how-and-when-to-use-unit-testing-properly) post.
219
-
* [13 Tips for Writing Useful Unit Tests](https://betterprogramming.pub/13-tips-for-writing-useful-unit-tests-ca20706b5368) blog post.
220
-
221
-
For any questions related to Refinitiv Data Platform APIs, please use the [RDP APIs Forum](https://community.developers.refinitiv.com/spaces/231/index.html) on the [Developers Community Q&A page](https://community.developers.refinitiv.com/).
206
+
207
+
- [RDP APIs page](https://developers.lseg.com/en/api-catalog/refinitiv-data-platform/refinitiv-data-platform-apis) on the [Refinitiv Developer Community](https://developers.refinitiv.com/) website.
- [RDP APIs: Introduction to the Request-Response API](https://developers.lseg.com/en/api-catalog/refinitiv-data-platform/refinitiv-data-platform-apis/tutorials#introduction-to-the-request-response-api).
210
+
- [RDP APIs - All about tokens](https://developers.lseg.com/en/api-catalog/refinitiv-data-platform/refinitiv-data-platform-apis/tutorials#authorization-all-about-tokens).
211
+
- [Limitations and Guidelines for the RDP Authentication Service](https://developers.lseg.com/en/article-catalog/article/limitations-and-guidelines-for-the-rdp-authentication-service) article.
212
+
- [Getting Started with Data Platform](https://developers.lseg.com/en/article-catalog/article/getting-start-with-refinitiv-data-platform) article.
213
+
- [Python unittest framework official page](https://docs.python.org/3/library/unittest.html).
- [Python Guide: Testing Your Code](https://docs.python-guide.org/writing/tests/) article.
216
+
- [Getting Started With Testing in Python](https://realpython.com/python-testing/) article.
217
+
- [Mocking External APIs in Python](https://realpython.com/testing-third-party-apis-with-mocks/) article.
218
+
- [How To Use unittest to Write a Test Case for a Function in Python](https://www.digitalocean.com/community/tutorials/how-to-use-unittest-to-write-a-test-case-for-a-function-in-python) article.
219
+
- [Mocking API calls in Python](https://auth0.com/blog/mocking-api-calls-in-python/) article.
220
+
- [How and when to use Unit Testing properly](https://softwareengineering.stackexchange.com/questions/89064/how-and-when-to-use-unit-testing-properly) post.
221
+
- [13 Tips for Writing Useful Unit Tests](https://betterprogramming.pub/13-tips-for-writing-useful-unit-tests-ca20706b5368) blog post.
222
+
223
+
For any questions related to RDP APIs, please use the [Developers Community Q&A page](https://community.developers.refinitiv.com/).
222
224
223
225
## Developers Articles
224
226
225
-
* [Getting Start Unit Test for an HTTP REST Application with Python](https://developers.refinitiv.com/en/article-catalog/article/getting-start-unit-test-for-an-http-rest-application-with-python) article.
227
+
* [Getting Start Unit Test for an HTTP REST Application with Python](https://developers.lseg.com/en/article-catalog/article/getting-start-unit-test-for-an-http-rest-application-with-python) article.
226
228
* [Getting Start With Unit Test for an HTTP REST Application with Python](https://wasin-waeosri.medium.com/getting-start-unit-test-for-an-http-rest-application-with-python-c57810cc4e56) Medium blog post.
ALL EXAMPLE CODE IS PROVIDED ON AN “AS IS” AND “AS AVAILABLE” BASIS FOR ILLUSTRATIVE PURPOSES ONLY. REFINITIV MAKES NO REPRESENTATIONS OR WARRANTIES OF ANY KIND, EXPRESS OR IMPLIED, AS TO THE OPERATION OF THE EXAMPLE CODE, OR THE INFORMATION, CONTENT, OR MATERIALS USED IN CONNECTION WITH THE EXAMPLE CODE. YOU EXPRESSLY AGREE THAT YOUR USE OF THE EXAMPLE CODE IS AT YOUR SOLE RISK.
10
+
ALL EXAMPLE CODE IS PROVIDED ON AN “AS IS” AND “AS AVAILABLE” BASIS FOR ILLUSTRATIVE PURPOSES ONLY. LSEG MAKES NO REPRESENTATIONS OR WARRANTIES OF ANY KIND, EXPRESS OR IMPLIED, AS TO THE OPERATION OF THE EXAMPLE CODE, OR THE INFORMATION, CONTENT, OR MATERIALS USED IN CONNECTION WITH THE EXAMPLE CODE. YOU EXPRESSLY AGREE THAT YOUR USE OF THE EXAMPLE CODE IS AT YOUR SOLE RISK.
ALL EXAMPLE CODE IS PROVIDED ON AN “AS IS” AND “AS AVAILABLE” BASIS FOR ILLUSTRATIVE PURPOSES ONLY. LSEG MAKES NO REPRESENTATIONS OR WARRANTIES OF ANY KIND, EXPRESS OR IMPLIED, AS TO THE OPERATION OF THE EXAMPLE CODE, OR THE INFORMATION, CONTENT, OR MATERIALS USED IN CONNECTION WITH THE EXAMPLE CODE. YOU EXPRESSLY AGREE THAT YOUR USE OF THE EXAMPLE CODE IS AT YOUR SOLE RISK.
0 commit comments