Skip to content

Commit

Permalink
test: fix python upload test
Browse files Browse the repository at this point in the history
  • Loading branch information
theSoenke committed Oct 23, 2023
1 parent 6610a1f commit 31e379c
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions clients/python/test/test_uploads_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,26 +30,28 @@ def setUp(self):
def tearDown(self):
pass

@patch('phrase_api.ApiClient.request')
@patch('urllib3.PoolManager.urlopen')
def test_upload_create(self, mock_post):
"""Test case for upload_create
Upload a new file # noqa: E501
"""
mock_post.return_value = Mock(ok=True)
mock_post.return_value.data = '{"id": "upload_id", "format": "simple_json"}'
mock_post.return_value.data = '{"id": "upload_id", "format": "simple_json"}'.encode()
mock_post.return_value.getencoding.return_value = 'utf-8'
mock_post.return_value.status = 201
mock_post.return_value.getheader.side_effect = { 'Content-Type': "application/json" }.get

project_id = "project_id_example"
with phrase_api.ApiClient(self.configuration) as api_client:
api_instance = phrase_api.UploadsApi(api_client)
api_response = api_instance.upload_create(
project_id,
file="./test/fixtures/en.json",
file_format="simple_json",
format_options={"enable_pluralization": True}
file_format="simple_json"
)

mock_post.assert_called_with("POST", "https://api.phrase.com/v2/projects/project_id_example/uploads", query_params=[], headers={'Accept': 'application/json', 'Content-Type': 'multipart/form-data', 'User-Agent': 'OpenAPI-Generator/1.14.0/python', 'Authorization': 'token YOUR_API_KEY'}, post_params=[('file_format', 'simple_json'), ('format_options', {'enable_pluralization': True}), ('file', ('en.json', b'{\n "key": "value"\n}\n', 'application/json'))], body=None, _preload_content=True, _request_timeout=None)
self.assertEqual("https://api.phrase.com/v2/projects/project_id_example/uploads", mock_post.call_args_list[0].args[1])

self.assertIsNotNone(api_response)
self.assertIsInstance(api_response, phrase_api.models.upload.Upload)
Expand Down

0 comments on commit 31e379c

Please sign in to comment.