github.com/phrase/openapi@v0.0.0-20240514140800-49e8a106740e/clients/python/test/test_uploads_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  import phrase_api
    18  from phrase_api.api.uploads_api import UploadsApi  # noqa: E501
    19  from phrase_api.rest import ApiException
    20  
    21  
    22  class TestUploadsApi(unittest.TestCase):
    23      """UploadsApi unit test stubs"""
    24  
    25      def setUp(self):
    26          self.configuration = phrase_api.Configuration()
    27          self.configuration.api_key['Authorization'] = 'YOUR_API_KEY'
    28          self.configuration.api_key_prefix['Authorization'] = 'token'
    29  
    30      def tearDown(self):
    31          pass
    32  
    33      @patch('urllib3.PoolManager.urlopen')
    34      def test_upload_create(self, mock_post):
    35          """Test case for upload_create
    36  
    37          Upload a new file  # noqa: E501
    38          """
    39          mock_post.return_value = Mock(ok=True)
    40          mock_post.return_value.data = '{"id": "upload_id", "format": "simple_json"}'.encode()
    41          mock_post.return_value.getencoding.return_value = 'utf-8'
    42          mock_post.return_value.status = 201
    43          mock_post.return_value.getheader.side_effect = { 'Content-Type': "application/json" }.get
    44  
    45          project_id = "project_id_example"
    46          with phrase_api.ApiClient(self.configuration) as api_client:
    47              api_instance = phrase_api.UploadsApi(api_client)
    48              api_response = api_instance.upload_create(
    49                  project_id,
    50                  file="./test/fixtures/en.json",
    51                  file_format="simple_json",
    52                  locale_id="en"
    53              )
    54  
    55              self.assertEqual("https://api.phrase.com/v2/projects/project_id_example/uploads", mock_post.call_args_list[0].args[1])
    56  
    57              self.assertIsNotNone(api_response)
    58              self.assertIsInstance(api_response, phrase_api.models.upload.Upload)
    59              self.assertEqual("upload_id", api_response.id)
    60              self.assertEqual("simple_json", api_response.format)
    61  
    62      def test_upload_show(self):
    63          """Test case for upload_show
    64  
    65          Get a single upload  # noqa: E501
    66          """
    67          pass
    68  
    69      def test_uploads_list(self):
    70          """Test case for uploads_list
    71  
    72          List uploads  # noqa: E501
    73          """
    74          pass
    75  
    76  
    77  if __name__ == '__main__':
    78      unittest.main()