github.com/phrase/openapi@v0.0.0-20240514140800-49e8a106740e/clients/python/test/test_locales_api.py (about) 1 # coding: utf-8 2 3 """ 4 Phrase Strings API Reference 5 6 The version of the OpenAPI document: 2.0.0 7 Contact: support@phrase.com 8 Generated by: https://openapi-generator.tech 9 """ 10 11 12 from __future__ import absolute_import 13 14 import unittest 15 from unittest.mock import Mock, patch 16 17 18 import phrase_api 19 from phrase_api.api.locales_api import LocalesApi # noqa: E501 20 from phrase_api.rest import ApiException 21 22 23 class TestLocalesApi(unittest.TestCase): 24 """LocalesApi unit test stubs""" 25 26 def setUp(self): 27 self.configuration = phrase_api.Configuration() 28 self.configuration.api_key['Authorization'] = 'YOUR_API_KEY' 29 self.configuration.api_key_prefix['Authorization'] = 'token' 30 31 def tearDown(self): 32 pass 33 34 def test_account_locales(self): 35 """Test case for account_locales 36 37 List locales used in account # noqa: E501 38 """ 39 pass 40 41 42 43 def test_locale_create(self): 44 """Test case for locale_create 45 46 Create a locale # noqa: E501 47 """ 48 pass 49 50 def test_locale_delete(self): 51 """Test case for locale_delete 52 53 Delete a locale # noqa: E501 54 """ 55 pass 56 57 @patch('urllib3.PoolManager.urlopen') 58 def test_locale_download(self, mock_get): 59 """Test case for locale_download 60 61 Download a locale # noqa: E501 62 """ 63 64 body = bytes('{"key":"value"}', 'utf-8') 65 mock_get.return_value = Mock(ok=True) 66 mock_get.return_value.data = body 67 mock_get.return_value.status = 200 68 mock_get.return_value.getencoding.return_value = 'utf-8' 69 mock_get.return_value.getheader.side_effect = { 'Content-Disposition': None }.get 70 71 with phrase_api.ApiClient(self.configuration) as api_client: 72 api_instance = phrase_api.api.locales_api.LocalesApi(api_client) 73 api_response = api_instance.locale_download("project_id_example", "en", file_format="simple_json", format_options={"enable_pluralization": True, "custom_metadata_columns": { "E": "text" }}) 74 75 self.assertEqual("https://api.phrase.com/v2/projects/project_id_example/locales/en/download?file_format=simple_json&format_options%5Benable_pluralization%5D=True&format_options%5Bcustom_metadata_columns%5D%5BE%5D=text", mock_get.call_args_list[0].args[1]) 76 77 self.assertIsNotNone(api_response) 78 file = open(api_response, "r") 79 content = file.read() 80 file.close() 81 self.assertEqual(body.decode(), content) 82 83 def test_locale_show(self): 84 """Test case for locale_show 85 86 Get a single locale # noqa: E501 87 """ 88 pass 89 90 def test_locale_update(self): 91 """Test case for locale_update 92 93 Update a locale # noqa: E501 94 """ 95 pass 96 97 @patch('phrase_api.ApiClient.request') 98 def test_locales_list(self, mock_get): 99 """Test case for locales_list 100 101 List locales # noqa: E501 102 """ 103 mock_get.return_value = Mock(ok=True) 104 mock_get.return_value.data = '[{"id":"locale_id","name":"locale_name","code":"locale_code","default":true,"main":true,"rtl":true,"plural_forms":["plural_forms"]}]' 105 106 project_id = "project_id_example" 107 with phrase_api.ApiClient(self.configuration) as api_client: 108 api_instance = phrase_api.api.locales_api.LocalesApi(api_client) 109 api_response = api_instance.locales_list(project_id) 110 111 self.assertIsNotNone(api_response) 112 self.assertEqual(1, len(api_response)) 113 self.assertIsInstance(api_response[0], phrase_api.models.locale.Locale) 114 self.assertEqual("locale_id", api_response[0].id) 115 self.assertEqual("locale_id", api_response[0].id) 116 self.assertEqual("locale_name", api_response[0].name) 117 118 119 120 if __name__ == '__main__': 121 unittest.main()