generated from rochacbruno/python-project-template
-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#59: Give ability to override worksection project hash
- Loading branch information
Showing
9 changed files
with
123 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -58,8 +58,10 @@ jobs: | |
env: | ||
WS_URL_ALL_USERS: ${{ secrets.WS_URL_ALL_USERS }} | ||
WS_URL_POST_COMMENT: ${{ secrets.WS_URL_POST_COMMENT }} | ||
WS_EMAIL: ${{ secrets.WS_EMAIL }} | ||
WS_ADMIN_EMAIL: ${{ secrets.WS_EMAIL }} | ||
WS_ADMIN_USER_ID: ${{ secrets.WS_ADMIN_USER_ID }} | ||
WS_PRJ_223728_HASH: ${{ secrets.WS_PRJ_223728_HASH }} | ||
WS_PRJ_1010_HASH: ${{ secrets.WS_PRJ_1010_HASH }} | ||
- name: "Upload coverage to Codecov" | ||
uses: codecov/[email protected] | ||
# with: | ||
|
@@ -85,7 +87,7 @@ jobs: | |
env: | ||
WS_URL_ALL_USERS: ${{ secrets.WS_URL_ALL_USERS }} | ||
WS_URL_POST_COMMENT: ${{ secrets.WS_URL_POST_COMMENT }} | ||
WS_EMAIL: ${{ secrets.WS_EMAIL }} | ||
WS_ADMIN_EMAIL: ${{ secrets.WS_EMAIL }} | ||
WS_ADMIN_USER_ID: ${{ secrets.WS_ADMIN_USER_ID }} | ||
WS_INT_TESTS_DISABLED: true | ||
|
||
|
@@ -111,7 +113,7 @@ jobs: | |
env: | ||
WS_URL_ALL_USERS: ${{ secrets.WS_URL_ALL_USERS }} | ||
WS_URL_POST_COMMENT: ${{ secrets.WS_URL_POST_COMMENT }} | ||
WS_EMAIL: ${{ secrets.WS_EMAIL }} | ||
WS_ADMIN_EMAIL: ${{ secrets.WS_EMAIL }} | ||
WS_ADMIN_USER_ID: ${{ secrets.WS_ADMIN_USER_ID }} | ||
WS_INT_TESTS_DISABLED: true | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,11 +6,13 @@ services: | |
environment: | ||
WS_URL_ALL_USERS: "https://xxx.worksection.com/xxxx" | ||
WS_URL_POST_COMMENT: "https://xxx.worksection.com/xxxx" | ||
WS_EMAIL: "[email protected]" | ||
WS_ADMIN_EMAIL: "[email protected]" | ||
WS_ADMIN_USER_ID: "370080" | ||
WS_PRJ_223728_HASH: "xxx" | ||
build: | ||
dockerfile: Containerfile | ||
context: . | ||
entrypoint: g2w --log=DEBUG | ||
ports: | ||
- "8080:8080" | ||
restart: always |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
from .push import Push | ||
from .ws import Ws | ||
from .api import LoggableRoute | ||
|
||
__all__ = ["Push", "Ws"] | ||
__all__ = ["Push", "Ws", "LoggableRoute"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import logging | ||
import time | ||
from typing import Callable | ||
|
||
from fastapi import Request, Response | ||
from fastapi.routing import APIRoute | ||
|
||
# @todo #/DEV Extract timings to a separate route. | ||
""" | ||
Interceptor that logs all for incoming requests/responses. | ||
""" | ||
|
||
|
||
class LoggableRoute(APIRoute): | ||
def get_route_handler(self) -> Callable: | ||
original_route_handler = super().get_route_handler() | ||
|
||
async def custom_route_handler(req: Request) -> Response: | ||
before = time.time() | ||
resp: Response = await original_route_handler(req) | ||
duration = time.time() - before | ||
resp.headers["X-Response-Time"] = str(duration) | ||
# @todo #58/DEV Ensure that logging is enabled for HTTP traffic and | ||
# could be used. | ||
logging.debug("req duration: {0}", duration) | ||
logging.debug( | ||
"req: %s, duration: %s, resp: %s, resp. headers: %s", | ||
req, | ||
duration, | ||
resp, | ||
resp.headers, | ||
) | ||
return resp | ||
|
||
return custom_route_handler |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -50,14 +50,15 @@ Please note, that `GitLab` commit messages must have the following format: `#WS- | |
version: "3.9" | ||
services: | ||
g2ws: | ||
image: dgroup/g2w:0.1.0 | ||
image: dgroup/g2w:0.2.0 | ||
container_name: g2w | ||
environment: | ||
# Mandatory environment variables (docker, podman, etc.) | ||
WS_URL_ALL_USERS: "https://xxx.worksection.com/xxxx" # https://worksection.com/faq/api-user.html#q1572 | ||
WS_URL_POST_COMMENT: "https://xxx.worksection.com/xxxx" # https://worksection.com/faq/api-comments.html#q1575 | ||
WS_EMAIL: "[email protected]" # plain worksection user email | ||
WS_ADMIN_EMAIL: "[email protected]" # plain worksection user email | ||
WS_ADMIN_USER_ID: "370080" # plain worksection user id | ||
WS_PRJ_223728_HASH: "xxx" # HASH generated for a particular Worksection project | ||
build: | ||
dockerfile: Containerfile | ||
context: . | ||
|
@@ -162,3 +163,6 @@ curl --request POST \ | |
```bash | ||
pip install g2w | ||
``` | ||
|
||
## Materials & Links | ||
* http://www.md5.cz - generate WS hash |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,7 +19,7 @@ def test_users(): | |
|
||
|
||
@pytest.mark.skipif(os.getenv("WS_INT_TESTS_DISABLED") is not None, reason="Integration tests are disabled") | ||
@pytest.mark.skipif(os.getenv("WS_EMAIL") is None, reason="Email account for worksection is absent") | ||
@pytest.mark.skipif(os.getenv("WS_ADMIN_EMAIL") is None, reason="WS_ADMIN_EMAIL variable 'WS_URL_POST_COMMENT' is absent") | ||
@pytest.mark.skipif(os.getenv("WS_URL_POST_COMMENT") is None, reason="Environment variable 'WS_URL_POST_COMMENT' is absent") | ||
def test_add_comment(): | ||
assert ( | ||
|
@@ -30,3 +30,13 @@ def test_add_comment(): | |
)["id"] | ||
is not None | ||
) | ||
|
||
|
||
@pytest.mark.skipif(os.getenv("WS_PRJ_1010_HASH") is None, reason="Environment variable 'WS_PRJ_1010_HASH' is absent") | ||
def test_post_comment_url(): | ||
assert ( | ||
Ws(post_comment="https://test.ws.com/api/admin/v2/?action=post_comment&page=/project/{0}/{1}/&email_user_from={2}&text={3}&hash={4}", email="[email protected]").post_comment_url( | ||
1010, 1234, "text" | ||
) | ||
== "https://test.ws.com/api/admin/v2/?action=post_comment&page=/project/1010/1234/&[email protected]&text=text&hash=1fsasdfj" | ||
) |
076ab31
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wasn't able to retrieve PDD puzzles from the code base and submit them to GitHub. If you think that it's a bug on our side, please submit it to yegor256/0pdd:
Please, copy and paste this stack trace to GitHub: