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 = "ru-RU" self.doUpload()
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" 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 = "ru-RU" self.doUpload() def doUpload(self): #ensure file is uploaded which is necesary for all tests uploadData = UploadData(self.FILE_PATH, self.FILE_NAME, self.FILE_TYPE) return self.fapi.upload(uploadData) def testFileList(self): res = self.fapi.list() assert_equal(True, res.find(self.CODE_SUCCESS_TOKEN) > 0 ) def testFileStatus(self): res = self.fapi.status(self.FILE_NAME, self.locale) assert_equal(True, res.find(self.CODE_SUCCESS_TOKEN) > 0 ) def testGetFileFromServer(self): res = 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 = 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 = self.fapi.list() count_old = res.count('"fileUri":') res = self.fapi.delete(self.FILE_NAME) assert_equal(True, res.find(self.CODE_SUCCESS_TOKEN) > 0 ) res = 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 = self.fapi.rename(self.FILE_NAME, self.FILE_NAME_NEW) assert_equal(True, res.find(self.CODE_SUCCESS_TOKEN) > 0 )