harry
commited on
Commit
·
fc2a750
1
Parent(s):
292c906
update tencent test.
Browse files- tests/test_tencent.py +18 -0
tests/test_tencent.py
CHANGED
|
@@ -54,3 +54,21 @@ def test_wrong_api_key(mock_requests):
|
|
| 54 |
mock_requests.get.return_value = mock_response
|
| 55 |
with pytest.raises(TencentAPIerror):
|
| 56 |
translator.translate("Hello")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 54 |
mock_requests.get.return_value = mock_response
|
| 55 |
with pytest.raises(TencentAPIerror):
|
| 56 |
translator.translate("Hello")
|
| 57 |
+
|
| 58 |
+
|
| 59 |
+
# the remaining tests are actual requests to Tencent translator API and use secret_id and secret_key
|
| 60 |
+
# if secret_id and secret_key variable is None, they are skipped
|
| 61 |
+
|
| 62 |
+
secret_id = None
|
| 63 |
+
secret_key = None
|
| 64 |
+
|
| 65 |
+
|
| 66 |
+
@pytest.mark.skipif(
|
| 67 |
+
secret_id is None or secret_key,
|
| 68 |
+
reason="secret_id or secret_key is not provided",
|
| 69 |
+
)
|
| 70 |
+
def test_tencent_successful_post_onetarget():
|
| 71 |
+
posted = TencentTranslator(
|
| 72 |
+
secret_id=secret_id, secret_key=secret_key, source="en", target="zh"
|
| 73 |
+
).translate("Hello! How are you?")
|
| 74 |
+
assert isinstance(posted, str)
|