-
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.
Merge pull request #11 from ubclaunchpad/files_by_language
Files by language
- Loading branch information
Showing
11 changed files
with
154 additions
and
55 deletions.
There are no files selected for viewing
Binary file not shown.
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
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 |
---|---|---|
@@ -1,4 +1,9 @@ | ||
asgiref==3.8.1 | ||
certifi==2024.8.30 | ||
charset-normalizer==3.4.0 | ||
Django==5.1.1 | ||
djangorestframework==3.15.2 | ||
idna==3.10 | ||
requests==2.32.3 | ||
sqlparse==0.5.1 | ||
urllib3==2.2.3 |
Binary file modified
BIN
+1.51 KB
(220%)
i18nilize/src/internationalize/__pycache__/helpers.cpython-311.pyc
Binary file not shown.
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 was deleted.
Oops, something went wrong.
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,4 @@ | ||
{ | ||
"thanks": "merci", | ||
"hello": "bonjour" | ||
} |
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,4 @@ | ||
{ | ||
"hello": "hola", | ||
"thanks": "gracias" | ||
} |
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 |
---|---|---|
@@ -1,29 +1,45 @@ | ||
import unittest | ||
from unittest.mock import patch, Mock | ||
import json | ||
from src.internationalize.generate_file import generate_file | ||
from src.internationalize.helpers import get_json | ||
import os | ||
from src.internationalize.helpers import generate_file | ||
|
||
# run tests using python -m tests.test_generate_file at i18nilize directory level | ||
|
||
class TestGenerateFile(unittest.TestCase): | ||
generate_file() | ||
data = get_json("src/internationalize/jsonFile/translations.json") | ||
class TestGenerateFile(unittest.TestCase): | ||
def setUp(self): | ||
self.TEST_TOKEN = '85124f79-0829-4b80-8b5c-d52700d86e46' | ||
|
||
def test_token(self): | ||
self.assertEqual(self.data['Token'], "85124f79-0829-4b80-8b5c-d52700d86e46") | ||
|
||
def test_translations(self): | ||
translations = self.data['translations'] | ||
self.assertEqual(len(translations), 2) | ||
@patch('src.internationalize.helpers.requests.get') | ||
def test_generate_file_success(self, mock_get): | ||
mock_response = Mock() | ||
mock_response.status_code = 200 | ||
mock_response.json.return_value = { | ||
'hello': 'hola', | ||
'thanks': 'gracias' | ||
} | ||
mock_get.return_value = mock_response | ||
|
||
generate_file('spanish', self.TEST_TOKEN) | ||
|
||
expected_file_path = './src/internationalize/languages/spanish.json' | ||
self.assertTrue(os.path.exists(expected_file_path)) | ||
|
||
# French | ||
self.assertEqual(translations[0]['language'], "French") | ||
self.assertEqual(translations[0]['hello'], "bonjour") | ||
self.assertEqual(translations[0]['No'], "Non") | ||
self.assertEqual(translations[0]['Why'], "pourquoi") | ||
with open (expected_file_path, 'r') as file: | ||
content = file.read() | ||
expected_content = json.dumps(mock_response.json.return_value, indent = 4) | ||
self.assertEqual(content, expected_content) | ||
|
||
# Spanish | ||
self.assertEqual(translations[1]['language'], "Spanish") | ||
self.assertEqual(translations[1]['hello'], "Hola") | ||
@patch('src.internationalize.helpers.requests.get') | ||
def test_generate_file_error(self, mock_get): | ||
mock_response = Mock() | ||
mock_response.status_code = 404 | ||
mock_get.return_value = mock_response | ||
|
||
generate_file('french', self.TEST_TOKEN) | ||
|
||
expected_file_path = './src/internationalize/languages/french.json' | ||
self.assertFalse(os.path.exists(expected_file_path)) | ||
|
||
unittest.main() | ||
if __name__ == '__main__': | ||
unittest.main() |