-
-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Add Alibaba machine translate service #10237
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #10237 +/- ##
=======================================
Coverage 90.85% 90.86%
=======================================
Files 546 547 +1
Lines 56694 56741 +47
Branches 9038 9040 +2
=======================================
+ Hits 51512 51557 +45
- Misses 3596 3597 +1
- Partials 1586 1587 +1
|
Hey @nijel @orangesunny do i need to do anything else here ? |
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.
Besides above feedback, can you please add tests for this backend?
docs/admin/machine.rst
Outdated
Alibaba | ||
--- |
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.
Alibaba | |
--- | |
Alibaba | |
------- |
How should i write tests ? as they dont have a specific url to fetch and i am using their sdk. It is similar to aws where they are using a stubber but i guess that same stubber wont work here as it is aws specific |
You can use generic Python mock instead, or you can use responses to mock HTTP for the library. |
As for the tests, the library seems to be built on top of requests, so you can use existing mocking by weblate/weblate/machinery/tests.py Lines 1225 to 1258 in 1a4fdc4
|
Tried this, but it still makes the request and gives InvalidAccessKeyId.NotFound error ======================================================================
|
Ah, they are using a vendored requests instead of a dependency. It should be possible to patch that as well using Looking at the class AlibabaTranslationTest(BaseMachineTranslationTest):
....
mock = responses.RequestsMock(target="aliyunsdkcore.vendored.requests.adapters.HTTPAdapter.send")
def mock_response(self):
self.mock.add(...)
@mock.activate
def test_translate(self, **kwargs):
super().test_translate(**kwargs) |
Followed the approach from GoogleV3Translation and used the patch.object to override the call for the do_action_with_exception method and this works finally. |
Merged, thanks for your contribution! |
Proposed changes
Fixes #7659
Checklist
Other information