-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add ednote and associations description text fields in translated mac…
…ro [SDNTB-875] (#517) * add ednote and associations description text fields in translated macro [SDNTB-875] * add tests
- Loading branch information
1 parent
4a28e97
commit 9b28ea0
Showing
2 changed files
with
85 additions
and
0 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
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,67 @@ | ||
from superdesk.tests import TestCase | ||
from superdesk.metadata.item import CONTENT_STATE | ||
|
||
from ntb.macros import nob_NO_translate_macro | ||
from unittest.mock import patch, MagicMock | ||
|
||
|
||
class TranslateMacroTestCase(TestCase): | ||
item = { | ||
"headline": "TEAS EXPO", | ||
"body_html": "<p>Hva synes du om Norge aftan_eftan.vok-a2e</p>", | ||
"guid": "9d7ba4b4-69a6-4f45-be96-1b0f26a6f89a", | ||
"abstract": "", | ||
"description_text": "None", | ||
"ednote": "Hva", | ||
"associations": { | ||
"editor_1": { | ||
"guid": "9e7ba4b4-69a6-4f45-be96-1b0f26a6f89b", | ||
"description_text": "Hva synes du om Norge", | ||
} | ||
}, | ||
"state": CONTENT_STATE.INGESTED, | ||
} | ||
|
||
user_preferences = { | ||
"user_preferences": { | ||
"macro_config": { | ||
"fields": {"Formval nynorskrobot": "headline,description_text"} | ||
} | ||
} | ||
} | ||
|
||
api_response_mock = { | ||
"document": { | ||
"headline": "TEA EXPO", | ||
"body_html": "<p>Kva synest du om Noreg aftan_eftan.vok-a2e</p>", | ||
"guid": "9d7ba4b4-69a6-4f45-be96-1b0f26a6f89a", | ||
"abstract": "", | ||
"description_text": "None", | ||
"ednote": "Kva", | ||
"associations_desc_editor_1": "Kva synest du om Noreg", | ||
}, | ||
"prefs": {"headline": True}, | ||
"fileType": "html", | ||
} | ||
|
||
@patch("ntb.macros.nob_NO_translate_macro.get_user", return_value=user_preferences) | ||
@patch("ntb.macros.nob_NO_translate_macro.requests.post") | ||
def test_associate_item_translated(self, mock_post, mock_get_user): | ||
# Mock the API response | ||
mock_post.return_value = MagicMock( | ||
status_code=200, json=lambda: self.api_response_mock | ||
) | ||
|
||
item = self.item.copy() | ||
|
||
nob_NO_translate_macro.callback(item) | ||
|
||
self.assertEqual(item["headline"], "TEA EXPO") | ||
self.assertEqual( | ||
item["body_html"], "<p>Kva synest du om Noreg aftan_eftan.vok-a2e</p>" | ||
) | ||
self.assertEqual(item["ednote"], "Kva") | ||
self.assertEqual( | ||
item["associations"]["editor_1"]["description_text"], | ||
"Kva synest du om Noreg", | ||
) |