Skip to content

Commit 0a9c20d

Browse files
Merge pull request #8 from LSEG-API-Samples/use_venv
Use venv
2 parents 2466ffe + 0a4b48a commit 0a9c20d

File tree

11 files changed

+115
-97
lines changed

11 files changed

+115
-97
lines changed

.dockerignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@ sample_jsons/
88
tests/__pycache__/
99
README.md
1010
.git/
11-
.gitignore
11+
.gitignore
12+
testenv/

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,6 @@ sample_jsons/
44
tests/__pycache__/
55
rdp_controller/__pycache__/
66
__pycache__/
7-
tree.txt
7+
tree.txt
8+
9+
testenv

Dockerfile

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
ARG PYTHON_VERSION=3.9.13
2-
ARG VARIANT=slim-buster
1+
ARG PYTHON_VERSION=3.11
2+
ARG VARIANT=slim-bookworm
33

44
#Build stage, using slim based-image because alpine cannot use Pandas and Matplotlib
55
FROM python:${PYTHON_VERSION}-${VARIANT} AS builder
@@ -8,13 +8,15 @@ FROM python:${PYTHON_VERSION}-${VARIANT} AS builder
88
COPY requirements.txt .
99

1010
# install dependencies to the local user directory (eg. /root/.local)
11-
RUN pip install --user -r requirements.txt
11+
#RUN pip install --user -r requirements.txt
12+
RUN pip install --trusted-host pypi.python.org --trusted-host files.pythonhosted.org --trusted-host pypi.org --no-cache-dir --user -r requirements.txt
13+
1214

1315
# Run stage, using slim based-image because alpine cannot use Pandas and Matplotlib
1416
FROM python:${PYTHON_VERSION}-${VARIANT}
1517
WORKDIR /app
1618

17-
LABEL maintainer="Developer Advocate"
19+
LABEL maintainer="Developer Relations"
1820

1921
# Update PATH environment variable + set Python buffer to make Docker print every message instantly.
2022
ENV PATH=/root/.local:$PATH \

LICENSE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (C) 2019-2022 Refinitiv. All rights reserved.
3+
Copyright (C) 2019-2025 LSEG. All rights reserved.
44

55
Permission is hereby granted, free of charge, to any person obtaining
66
a copy of this software and associated documentation files (the

README.md

Lines changed: 44 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
# 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
44
- Environment: Windows
55
- Prerequisite: [Access to RDP credentials](#prerequisite)
66

77
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.
99

1010
## <a id="intro"></a>Introduction
1111

@@ -15,7 +15,7 @@ Unit testing is a software testing method that helps developers verify if any ch
1515

1616
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.
1717

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.
1919

2020
**Note**:
2121
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
8080
- [unittest standard library documentation](https://docs.python.org/3.9/library/unittest.html).
8181
- [Getting Started With Testing in Python](https://realpython.com/python-testing/).
8282

83-
## <a id="whatis_rdp"></a>What is Refinitiv Data Platform (RDP) APIs?
83+
## <a id="whatis_rdp"></a>What is Delivery Platform (RDP) APIs?
8484

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.
8686

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.
9293

9394
This example project is focusing on the Request-Response: RESTful web service delivery method only.
9495

95-
![figure-2](images/02_rdp.png "Refinitiv Data Platform")
96+
![figure-2](images/02_rdp.png "Delivery Platform")
9697

97-
For more detail regarding the Refinitiv Data Platform, please see the following APIs resources:
98-
- [Quick Start](https://developers.refinitiv.com/en/api-catalog/refinitiv-data-platform/refinitiv-data-platform-apis/quick-start) page.
99-
- [Tutorials](https://developers.refinitiv.com/en/api-catalog/refinitiv-data-platform/refinitiv-data-platform-apis/tutorials) page.
98+
For more detail regarding the RDP APIs, please see the following APIs resources:
99+
- [Quick Start](https://developers.lseg.com/en/api-catalog/refinitiv-data-platform/refinitiv-data-platform-apis/quick-start) page.
100+
- [Tutorials](https://developers.lseg.com/en/api-catalog/refinitiv-data-platform/refinitiv-data-platform-apis/tutorials) page.
100101

101102

102103
## <a id="testsuite_detail"></a>Test Suit Development Detail
@@ -108,11 +109,11 @@ Please see the full details over the test suite implementation on the [unittest-
108109
This demo project requires the following dependencies.
109110

110111
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
112113
3. [Docker Desktop/Engine](https://docs.docker.com/get-docker/) application for running the test suite with Docker.
113114
5. Internet connection.
114115

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.
116117

117118

118119
## <a id="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
121122

122123
### <a id="python_example_run"></a>Run example test suite in a console
123124

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.
126127
```
127-
(base) $>conda create --name http_unittest python=3.9
128+
$>python -m venv http_unittest
128129
```
129-
3. Once the environment is created, activate a Conda *http_unittest* environment with this command in Anaconda Prompt.
130+
3. Once the environment is created, activate a virtual environment *http_unittest* environment with this command .
130131
```
131-
(base) $>conda activate http_unittest
132+
$>http_unittest\Script\activate
132133
```
133134
4. Run the following command to the dependencies in the *http_unittest* environment
134135
```
@@ -183,7 +184,7 @@ OK
183184
```
184185
$> docker rm python_unittest
185186
```
186-
![figure-3](images/03_docker_run_result.gif "Refinitiv Data Platform")
187+
![figure-3](images/03_docker_run_result.gif "Data Platform")
187188
188189
That covers how to run an example test suite.
189190
@@ -197,30 +198,31 @@ This example project demonstrates the manual unit testing method. However, devel
197198
198199
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).
199200
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.
201202
202203
## <a id="references"></a>References
203204
204205
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).
212-
* [Responses library page](https://github.com/getsentry/responses).
213-
* [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.
208+
- [RDP APIs Playground page](https://apidocs.refinitiv.com/Apps/ApiDocs).
209+
- [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).
214+
- [Responses library page](https://github.com/getsentry/responses).
215+
- [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/).
222224
223225
## Developers Articles
224226
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.
226228
* [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.

app.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
#| This source code is provided under the MIT license --
33
#| and is provided AS IS with no warranty or guarantee of fit for purpose. --
44
#| See the project's LICENSE.md for details. --
5-
#| Copyright Refinitiv 2022. All rights reserved. --
5+
#| Copyright LSEG 2025. All rights reserved. --
66
#|-----------------------------------------------------------------------------
77

88
"""
99
Example Code Disclaimer:
10-
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.
1111
"""
1212

1313
import sys

rdp_controller/rdp_http_controller.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
#|-----------------------------------------------------------------------------
2+
#| This source code is provided under the MIT license --
3+
#| and is provided AS IS with no warranty or guarantee of fit for purpose. --
4+
#| See the project's LICENSE.md for details. --
5+
#| Copyright LSEG 2025. All rights reserved. --
6+
#|-----------------------------------------------------------------------------
7+
8+
"""
9+
Example Code Disclaimer:
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.
11+
"""
12+
113
import requests
214
import json
315

requirements.txt

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
1-
certifi==2024.7.4
2-
charset-normalizer==2.1.0
3-
idna==3.7
4-
numpy==1.23.0
5-
pandas==1.4.3
6-
pip==23.3
7-
python-dateutil==2.8.2
8-
python-dotenv==0.20.0
9-
pytz==2022.1
10-
requests==2.32.2
11-
responses==0.21.0
12-
setuptools==70.0.0
13-
six==1.16.0
14-
urllib3==1.26.9
15-
wheel==0.38.1
16-
wincertstore==0.2
1+
certifi==2025.1.31
2+
charset-normalizer==3.4.1
3+
idna==3.10
4+
numpy==2.2.2
5+
pandas==2.2.3
6+
python-dateutil==2.9.0.post0
7+
python-dotenv==1.0.1
8+
pytz==2025.1
9+
PyYAML==6.0.2
10+
requests==2.32.3
11+
responses==0.25.6
12+
six==1.17.0
13+
tzdata==2025.1
14+
urllib3==2.3.0

0 commit comments

Comments
 (0)