Skip to content

Commit

Permalink
Deploying from phrase/openapi@446fd60b
Browse files Browse the repository at this point in the history
  • Loading branch information
Phrase committed Nov 20, 2024
1 parent 8b0b8df commit c2bb3e9
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 12 deletions.
5 changes: 3 additions & 2 deletions phrase_api/api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,14 +151,15 @@ def __call_api(
if query_params:
query_params = self.sanitize_for_serialization(query_params)
query_params = self.parameters_to_tuples(query_params, collection_formats)
query_params = self.flatten_query_params(query_params)
query_params = self.flatten_params(query_params)

# post parameters
if post_params or files:
post_params = post_params if post_params else []
post_params = self.sanitize_for_serialization(post_params)
post_params = self.parameters_to_tuples(post_params,
collection_formats)
post_params = self.flatten_params(post_params)
post_params.extend(self.files_parameters(files))

# auth setting
Expand Down Expand Up @@ -453,7 +454,7 @@ def parameters_to_tuples(self, params, collection_formats):
new_params.append((k, v))
return new_params

def flatten_query_params(self, params):
def flatten_params(self, params):
result_params = {}
for key, value in params:
if isinstance(value, dict):
Expand Down
3 changes: 0 additions & 3 deletions test/fixtures/en.json

This file was deleted.

2 changes: 2 additions & 0 deletions test/fixtures/test.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
key_name,en,comment
key1,Hello,description
25 changes: 18 additions & 7 deletions test/test_uploads_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,14 @@
import sys

if sys.version_info[:2] <= (3, 7):
from mock import Mock, patch
from mock import Mock, patch
else:
from unittest.mock import Mock, patch

import phrase_api
from phrase_api.api.uploads_api import UploadsApi # noqa: E501
from phrase_api.rest import ApiException


class TestUploadsApi(unittest.TestCase):
"""UploadsApi unit test stubs"""

Expand All @@ -42,7 +41,7 @@ def test_upload_create(self, mock_post):
Upload a new file # noqa: E501
"""
mock_post.return_value = Mock(ok=True)
mock_post.return_value.data = '{"id": "upload_id", "format": "simple_json"}'.encode()
mock_post.return_value.data = '{"id": "upload_id", "format": "csv"}'.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
Expand All @@ -52,17 +51,29 @@ def test_upload_create(self, mock_post):
api_instance = phrase_api.UploadsApi(api_client)
api_response = api_instance.upload_create(
project_id,
file="./test/fixtures/en.json",
file_format="simple_json",
locale_id="en"
file="./test/fixtures/test.csv",
file_format="csv",
locale_id="en",
locale_mapping={
"en": 2
},
format_options={
"deep_parameter": {"foo": "bar"}
}
)

self.assertEqual("https://api.phrase.com/v2/projects/project_id_example/uploads", mock_post.call_args_list[0].args[1])
body = mock_post.call_args.kwargs["body"].decode('utf-8')
self.assertRegex(body, r'name="file"; filename="test.csv"\r\nContent-Type: text/csv\r\n\r\n')
self.assertRegex(body, r'name="file_format"\r\n\r\ncsv\r\n')
self.assertRegex(body, r'name="locale_id"\r\n\r\nen\r\n')
self.assertRegex(body, r'name="locale_mapping\[en\]"\r\n\r\n2\r\n')
self.assertRegex(body, r'name="format_options\[deep_parameter\]\[foo\]"\r\n\r\nbar\r\n')

self.assertIsNotNone(api_response)
self.assertIsInstance(api_response, phrase_api.models.upload.Upload)
self.assertEqual("upload_id", api_response.id)
self.assertEqual("simple_json", api_response.format)
self.assertEqual("csv", api_response.format)

def test_upload_show(self):
"""Test case for upload_show
Expand Down

0 comments on commit c2bb3e9

Please sign in to comment.