-
Notifications
You must be signed in to change notification settings - Fork 86
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
DeepL offers a free API now #604
Closed
Closed
Changes from 5 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
554373e
DeepL offers a free API now
ramiboutas 3ffee28
typo from copy-paste fixed
ramiboutas 719798e
Create test_deepl_translator.py
ramiboutas d3cad72
simple tests added -> auth_key_is_free_account
ramiboutas bbffe0b
auth_key did not exist as variable, now it does
ramiboutas 418401b
code refactored
ramiboutas 9bc761a
Update test_deepl_translator.py
ramiboutas dd4f1dc
options added to WAGTAILLOCALIZE_MACHINE_TRANSLATOR
ramiboutas 96ec48f
Update test_deepl_translator.py
ramiboutas File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
16 changes: 16 additions & 0 deletions
16
wagtail_localize/machine_translators/tests/test_deepl_translator.py
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,16 @@ | ||
|
||
from django.test import TestCase | ||
|
||
from wagtail_localize.machine_translators.deepl import auth_key_is_free_account | ||
|
||
|
||
class TestDeeplTranslator(TestCase): | ||
def setUp(self): | ||
self.free_auth_key = "asd-23-ssd-243-adsf-dummy-auth-key:fx" | ||
self.paid_auth_key = "asd-23-ssd-243-adsf-dummy-auth-key:bla" | ||
|
||
def test_api_free(self): | ||
self.assertEqual(auth_key_is_free_account(self.free_auth_key), True) | ||
|
||
def test_api_paid(self): | ||
self.assertEqual(auth_key_is_free_account(self.paid_auth_key), False) | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
This is a start, but I was thinking checking that
DeepLTranslator.translate
uses the correct URL based on the key, since that is what we want to test first and foremostThere 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.
That it is what I also wanted but I dont know how to do that; my apologies. I will learn more about writting tests and come back to the issue again.
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.
Look for mocking (e.g. https://bhch.github.io/posts/2017/09/python-testing-how-to-mock-requests-during-tests/)
alternatively, move the logic to return a URL to a method in
DeepLTranslator
(e.g.get_api_endpoint
), and use that inrequests.post
. Then you can test withoverride_settings
to change the keyin your test you could call
DeepLTranslator({}).get_api_endpoint()
and check its value