Skip to content

Commit 97db6b0

Browse files
committed
1. Add summary
2. Add Docker variable 3. Fix bug
1 parent 80ae9bb commit 97db6b0

File tree

3 files changed

+47
-5
lines changed

3 files changed

+47
-5
lines changed

Dockerfile

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1+
ARG PYTHON_VERSION=3.9.13
2+
ARG VARIANT=slim-buster
3+
14
#Build stage, using slim based-image because alpine cannot use Pandas and Matplotlib
2-
FROM python:3.9.13-slim-buster AS builder
5+
FROM python:${PYTHON_VERSION}-${VARIANT} AS builder
36

47
#Copy requirements.txt
58
COPY requirements.txt .
@@ -8,9 +11,11 @@ COPY requirements.txt .
811
RUN pip install --user -r requirements.txt
912

1013
# Run stage, using slim based-image because alpine cannot use Pandas and Matplotlib
11-
FROM python:3.9.13-slim-buster
14+
FROM python:${PYTHON_VERSION}-${VARIANT}
1215
WORKDIR /app
1316

17+
LABEL maintainer="Developer Advocate"
18+
1419
# Update PATH environment variable + set Python buffer to make Docker print every message instantly.
1520
ENV PATH=/root/.local:$PATH \
1621
USERNAME=DOCKER_CONTAINER \

README.md

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,31 @@ The first step is to unzip or download the example project folder into a directo
137137
```
138138
(http_unittest) $>tests\python -m unittest discover
139139
```
140+
Example Result:
141+
142+
```
143+
(http_unittest) $>tests\python -m unittest test_rdp_http_controller
144+
145+
RDP authentication failure: 401 Unauthorized
146+
Text: {"error": "invalid_client", "error_description": "Invalid Application Credential."}
147+
..Authentication success
148+
.Authentication success
149+
.Receive ESG Data from RDP APIs
150+
.Receive ESG Data from RDP APIs
151+
..RDP APIs: ESG data request failure: 401 Unauthorized
152+
Text: {"error": {"id": "XXXXXXXXXX", "code": "401", "message": "token expired", "status": "Unauthorized"}}
153+
.Receive Search Explore Data from RDP APIs
154+
.RDP APIs: Search Explore request failure: 400 Bad Request
155+
Text: {"error": {"id": "00000000-0000-0000-0000-000000000000", "code": "400", "message": "Validation error", "status": "Bad Request", "errors": [{"key": "json", "reason": "json.View in body should be one of [CatalogItems Entities]"}]}}
156+
.Receive Search Explore Data from RDP APIs
157+
..RDP APIs: Search Explore request failure: 401 Unauthorized
158+
Text: {"error": {"id": "XXXXXXXXXX", "code": "401", "message": "token expired", "status": "Unauthorized"}}
159+
.
160+
----------------------------------------------------------------------
161+
Ran 13 tests in 0.031s
162+
163+
OK
164+
```
140165
141166
### <a id="docker_example_run"></a>Run example test suite in Docker
142167
@@ -153,13 +178,25 @@ The first step is to unzip or download the example project folder into a directo
153178
```
154179
$> docker rm python_unittest
155180
```
181+
182+
183+
184+
That covers how to run an example test suite.
185+
156186
## <a id="summary"></a>Conclusion and Next Steps
157187
158-
**To Add Conclusion and Next Steps here.**
188+
Unit testing is now the mandatory process of a software development lifecycle for both modern and legacy applications. It helps to expose unintentional behaviors of a tiny part of the application quicker than trying to find bugs in a big complex phase. It speeds up the overall feedback loop and improves trust among the project team. Unit testing also helps improves application source code quality, developers have more confidence in refactoring the source code for better performance and cleaner code. As the author of this article, I also have learned a lot from this project. There are a lot of error handlers or code logic that I never think of until I started to write unit test cases.
189+
190+
This example project demonstrates the manual unit testing method. However, developers should run unit test cases automatically every time they made changes to the code (or configurations). The most practical technique is running automated unit tests as part of the developers' Continuous Integration/Continuous Delivery (CI/CD) pipeline. Developers can apply the TDD (Test-driven development) practice that writing and correcting the failed tests before writing new code with their project too.
191+
192+
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).
193+
194+
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.
195+
159196
160197
## <a id="references"></a>References
161198
162-
For further details, please check out the following resources:
199+
That brings me to the end of my unit test example project. For further details, please check out the following resources:
163200
* [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.
164201
* [Refinitiv Data Platform APIs Playground page](https://api.refinitiv.com).
165202
* [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).

unittest-article.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ A mock is a fake object that is constructed to look and act like real data withi
313313

314314
The purpose of mocking is to isolate and focus on the code being tested and not on the behavior or state of external dependencies. By mocking out external dependencies, developers can run tests as often without being affected by any unexpected changes or irregularities of those dependencies. Mocking also helps developers save time and computing resources if they have to test HTTP requests that fetch a lot of data.
315315

316-
This example project uses the [Responses](https://github.com/getsentry/responses) library for mocking the Requests library.
316+
This example project uses the [Responses](https://github.com/getsentry/responses) library which is built specifically for mocking the Requests library.
317317

318318
### <a id="add_mock_test"></a>Adding a mock Object to the test case
319319

0 commit comments

Comments
 (0)