-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Thibault Ballier
committed
Oct 31, 2023
1 parent
fc40da8
commit 14bd003
Showing
5 changed files
with
97 additions
and
1 deletion.
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
pytest==7.4.3 |
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,62 @@ | ||
import json | ||
import base64 | ||
from unittest import mock | ||
|
||
from .data_decoder import decode_data | ||
|
||
|
||
class __UtilArgsData: | ||
args: dict[str, str] | ||
|
||
def __init__(self) -> None: | ||
self.args = {} | ||
|
||
|
||
def test_decode_data_flask_data() -> None: | ||
data = base64.b64encode(json.dumps({ | ||
"username": "flask_username", | ||
"password": "flask_password", | ||
"team_id": "flask_team_id" | ||
}).encode("utf-8")).decode("utf-8") | ||
|
||
util_args = __UtilArgsData() | ||
util_args.args = {"data": data} | ||
|
||
with mock.patch("flask.request", util_args): | ||
username, password, team_id = decode_data() | ||
|
||
assert username == "flask_username" | ||
assert password == "flask_password" | ||
assert team_id == "flask_team_id" | ||
|
||
|
||
def test_decode_data_flask_args() -> None: | ||
util_args = __UtilArgsData() | ||
util_args.args = { | ||
"username": "flask_args_username", | ||
"password": "flask_args_password", | ||
"team_id": "flask_args_team_id", | ||
} | ||
|
||
with mock.patch("flask.request", util_args): | ||
username, password, team_id = decode_data() | ||
|
||
assert username == "flask_args_username" | ||
assert password == "flask_args_password" | ||
assert team_id == "flask_args_team_id" | ||
|
||
|
||
def test_decode_data_env() -> None: | ||
util_args = __UtilArgsData() | ||
env = { | ||
"username": "env_username", | ||
"password": "env_password", | ||
"team_id": "env_team_id", | ||
} | ||
with (mock.patch("flask.request", util_args), | ||
mock.patch("utils.data_decoder.env", env)): | ||
username, password, team_id = decode_data() | ||
|
||
assert username == "env_username" | ||
assert password == "env_password" | ||
assert team_id == "env_team_id" |
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,18 @@ | ||
from unittest import mock | ||
|
||
from .env import load_env_data | ||
|
||
|
||
def test_env() -> None: | ||
env = { | ||
"username": "u", | ||
"password": "p", | ||
"team_id": "ti", | ||
} | ||
|
||
with mock.patch("utils.env.env", env): | ||
username, password, team_id = load_env_data() | ||
|
||
assert username == "u" | ||
assert password == "p" | ||
assert team_id == "ti" |
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,12 @@ | ||
import pytest | ||
|
||
from .utils import normalize | ||
|
||
|
||
@pytest.mark.parametrize("test_input,expected", [ | ||
("J'aimerais ça. Du pâté !", "J'aimerais ca. Du pate !"), | ||
("phrase normale", "phrase normale"), | ||
]) | ||
def test_normalize(test_input, expected) -> None: | ||
result = normalize(test_input) | ||
assert expected == result |
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