1515import sys
1616
1717if sys .version_info [:2 ] <= (3 , 7 ):
18- from mock import Mock , patch
18+ from mock import Mock , patch
1919else :
2020 from unittest .mock import Mock , patch
2121
2222import phrase_api
2323from phrase_api .api .uploads_api import UploadsApi # noqa: E501
2424from phrase_api .rest import ApiException
2525
26-
2726class TestUploadsApi (unittest .TestCase ):
2827 """UploadsApi unit test stubs"""
2928
@@ -42,7 +41,7 @@ def test_upload_create(self, mock_post):
4241 Upload a new file # noqa: E501
4342 """
4443 mock_post .return_value = Mock (ok = True )
45- mock_post .return_value .data = '{"id": "upload_id", "format": "simple_json "}' .encode ()
44+ mock_post .return_value .data = '{"id": "upload_id", "format": "csv "}' .encode ()
4645 mock_post .return_value .getencoding .return_value = 'utf-8'
4746 mock_post .return_value .status = 201
4847 mock_post .return_value .getheader .side_effect = { 'Content-Type' : "application/json" }.get
@@ -52,17 +51,29 @@ def test_upload_create(self, mock_post):
5251 api_instance = phrase_api .UploadsApi (api_client )
5352 api_response = api_instance .upload_create (
5453 project_id ,
55- file = "./test/fixtures/en.json" ,
56- file_format = "simple_json" ,
57- locale_id = "en"
54+ file = "./test/fixtures/test.csv" ,
55+ file_format = "csv" ,
56+ locale_id = "en" ,
57+ locale_mapping = {
58+ "en" : 2
59+ },
60+ format_options = {
61+ "deep_parameter" : {"foo" : "bar" }
62+ }
5863 )
5964
6065 self .assertEqual ("https://api.phrase.com/v2/projects/project_id_example/uploads" , mock_post .call_args_list [0 ].args [1 ])
66+ body = mock_post .call_args .kwargs ["body" ].decode ('utf-8' )
67+ self .assertRegex (body , r'name="file"; filename="test.csv"\r\nContent-Type: text/csv\r\n\r\n' )
68+ self .assertRegex (body , r'name="file_format"\r\n\r\ncsv\r\n' )
69+ self .assertRegex (body , r'name="locale_id"\r\n\r\nen\r\n' )
70+ self .assertRegex (body , r'name="locale_mapping\[en\]"\r\n\r\n2\r\n' )
71+ self .assertRegex (body , r'name="format_options\[deep_parameter\]\[foo\]"\r\n\r\nbar\r\n' )
6172
6273 self .assertIsNotNone (api_response )
6374 self .assertIsInstance (api_response , phrase_api .models .upload .Upload )
6475 self .assertEqual ("upload_id" , api_response .id )
65- self .assertEqual ("simple_json " , api_response .format )
76+ self .assertEqual ("csv " , api_response .format )
6677
6778 def test_upload_show (self ):
6879 """Test case for upload_show
0 commit comments