forked from Smartling/api-sdk-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtestFAPI.py
More file actions
96 lines (77 loc) · 3.64 KB
/
testFAPI.py
File metadata and controls
96 lines (77 loc) · 3.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
''' Copyright 2012 Smartling, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this work except in compliance with the License.
* You may obtain a copy of the License in the LICENSE file, or at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
'''
import os
import sys
lib_path = os.path.abspath('../')
sys.path.append(lib_path) # allow to import ../smartlingApiSdk/SmartlingFileApi
from smartlingApiSdk.SmartlingFileApi import SmartlingFileApi
from smartlingApiSdk.UploadData import UploadData
from nose.tools import assert_equal
# don't forget to set real API_KEY and PROJECT_ID
# or use environment variables:
# export SL_API_KEY=********-****-****-****-************
# export SL_PROJECT_ID=*******
class testFapi(object):
HOST = 'sandbox-api.smartling.com'
MY_API_KEY = "YOUR_API_KEY"
MY_PROJECT_ID = "YOUR_PROJECT_ID"
FILE_NAME = "java.properties"
FILE_TYPE = "javaProperties"
FILE_PATH = "../resources/"
FILE_NAME_NEW = "java.properties.renamed"
CALLBACK_URL = "http://google.com/?q=hello"
CODE_SUCCESS_TOKEN = '"code":"SUCCESS"'
def setUp(self):
self.MY_API_KEY = os.environ.get('SL_API_KEY', self.MY_API_KEY)
self.MY_PROJECT_ID = os.environ.get('SL_PROJECT_ID', self.MY_PROJECT_ID)
self.fapi = SmartlingFileApi(self.HOST, self.MY_API_KEY, self.MY_PROJECT_ID)
self.locale = os.environ.get('SL_LOCALE', "ru-RU")
self.doUpload()
def doUpload(self):
#ensure file is uploaded which is necessary for all tests
uploadData = UploadData(self.FILE_PATH, self.FILE_NAME, self.FILE_TYPE)
uploadData.setCallbackUrl(self.CALLBACK_URL)
return self.fapi.upload(uploadData)
def testFileList(self):
res, status = self.fapi.list()
assert_equal(True, res.find(self.CODE_SUCCESS_TOKEN) > 0)
def testFileStatus(self):
res, status = self.fapi.status(self.FILE_NAME, self.locale)
assert_equal(True, res.find(self.CODE_SUCCESS_TOKEN) > 0)
def testGetFileFromServer(self):
res, status = self.fapi.get(self.FILE_NAME, self.locale)
lines = open(self.FILE_PATH + self.FILE_NAME, "rb").readlines()
assert_equal(len(res.split("\n")), len(lines))
def testGetFileWithTypeFromServer(self):
res, status = self.fapi.get(self.FILE_NAME, self.locale, retrievalType='pseudo')
lines = open(self.FILE_PATH + self.FILE_NAME, "rb").readlines()
assert_equal(len(res.split("\n")), len(lines))
def testFileDelete(self):
res, status = self.fapi.list()
count_old = res.count('"fileUri":')
res, status = self.fapi.delete(self.FILE_NAME)
assert_equal(True, res.find(self.CODE_SUCCESS_TOKEN) > 0)
res, status = self.fapi.list()
count_new = res.count('"fileUri":')
assert_equal(count_old - 1, count_new)
self.doUpload() # ensure file is uploaded back after it's deleted
def testFileRename(self):
self.fapi.delete(self.FILE_NAME_NEW)
res, status = self.fapi.rename(self.FILE_NAME, self.FILE_NAME_NEW)
assert_equal(True, res.find(self.CODE_SUCCESS_TOKEN) > 0)
def testLastModified(self):
resp, status = self.fapi.last_modified(self.FILE_NAME)
assert_equal(True, resp.find(self.CODE_SUCCESS_TOKEN) > 0)
assert_equal(True, len(resp.data.items)>0)