Ejemplo n.º 1
0
 def test_init(self):
     ud = UploadData("path", "name", "type")
     assert_equal(ud.path, "path")
     assert_equal(ud.name, "name")
     assert_equal(ud.type, "type")
     assert_equal(ud.type, "type")
     assert_equal(ud.approveContent, "false")
     assert_equal(ud.callbackUrl, "")
Ejemplo n.º 2
0
 def testImport(self):
     uploadData = UploadData(self.FILE_PATH, self.FILE_NAME, self.FILE_TYPE)
     uploadData.uri = self.uri
     uploadData.name = self.FILE_NAME_IMPORT
     resp, status = self.fapi.import_call(uploadData, self.locale, translationState="PUBLISHED")
     assert_equal(resp.code, self.CODE_SUCCESS_TOKEN)
     assert_equal(resp.data.wordCount, 2)
     assert_equal(resp.data.stringCount, 2)
     assert_equal(resp.data.translationImportErrors, [])
Ejemplo n.º 3
0
def upload_smartling_file(filepath,
                          filename,
                          locale='de-DE',
                          file_type='json'):
    uploadDataUtf16 = UploadData(filepath, filename, file_type)
    uploadDataUtf16.setApproveContent("true")
    uploadDataUtf16.setCallbackUrl(settings.SMARTLING_CALLBACK_URL)
    useSandbox = False
    example = SmartlingApi(useSandbox, uploadDataUtf16, locale, filename)
    example.fapi.upload(example.uploadData)
Ejemplo n.º 4
0
    def test_addDirective(self):
        ud = UploadData("path", "name", "type")
        assert_equal(len(ud.directives), 0)

        ud.addDirective(SmartlingDirective("name", "value"))
        assert_equal(len(ud.directives), 1)
        assert_equal(ud.directives[0].name, "name")

        ud.addDirective(SmartlingDirective("name2", "value2"))
        assert_equal(len(ud.directives), 2)
        assert_equal(ud.directives[1].value, "value2")
Ejemplo n.º 5
0
    def test_commandUpload_Callback_Approved(self):
        ud = UploadData("path", "name", "type")
        ud.setApproveContent("true")
        ud.setCallbackUrl("smartling.com")

        api = FileApiBase("host", "apiKey", "projectId")
        api.uploadMultipart = self.mock_uploadMultipart
        params = api.commandUpload(ud)

        assert_equal(len(params), 5)
        assert_equal(params[Params.APPROVED], "true")
        assert_equal(params[Params.CALLBACK_URL], "smartling.com")
Ejemplo n.º 6
0
    def test_commandUpload(self):
        ud = UploadData("path", "name", "type")

        api = FileApiBase("host", "apiKey", "projectId")
        api.uploadMultipart = self.mock_uploadMultipart
        params = api.commandUpload(ud)

        assert_equal(len(params), 4)
        assert_equal(params[Params.FILE_URI], "name")
        assert_equal(params[Params.FILE_TYPE], "type")
        assert_equal(params[Params.FILE_PATH], "pathname")
        assert_equal(params[Params.APPROVED], "false")
Ejemplo n.º 7
0
    def test_commandUpload_Directives(self):
        ud = UploadData("path", "name", "type")
        ud.setApproveContent("true")
        ud.setCallbackUrl("smartling.com")
        ud.addDirective(
            SmartlingDirective("placeholder_format_custom", "\[.+?\]"))
        ud.addDirective(SmartlingDirective("placeholder_format", "IOS"))

        api = FileApiBase("host", "apiKey", "projectId")
        api.uploadMultipart = self.mock_uploadMultipart
        params = api.commandUpload(ud)

        assert_equal(len(params), 7)
        assert_equal(params["smartling.placeholder_format_custom"], "\[.+?\]")
        assert_equal(params["smartling.placeholder_format"], "IOS")
Ejemplo n.º 8
0
def upload_file(fapi, file_name, conf):
    """ Uploads a file to smartling
    """
    if not conf.has_key('file-type'):
        raise SmarterlingError("%s doesn't have a file-type" % file_name)
    print("Uploading %s to smartling" % file_name)
    data = UploadData(
        os.path.dirname(file_name)+os.sep,
        os.path.basename(file_name),
        conf.get('file-type'))
    data.setUri(file_uri(file_name, conf))
    if conf.has_key('approve-content'):
        data.setApproveContent("true" if conf.get('approve-content', True) else "false")
    if conf.has_key('callback-url'):
        data.setCallbackUrl(conf.get('callback-url'))
    for name, value in conf.get('directives', {}).items():
        data.addDirective(SmartlingDirective(name, value))
    (response, code) = fapi.upload(data)
    if code!=200:
        print(repr(response))
        raise SmarterlingError("Error uploading file: %s" % file_name)
    else:
        print("Uploaded %s, wordCount: %s, stringCount: %s" % (file_name, response.data.wordCount, response.data.stringCount))
Ejemplo n.º 9
0
 def doUpload(self, name, uri):
     #ensure file is uploaded which is necessary for all tests
     uploadData = UploadData(self.FILE_PATH, name, self.FILE_TYPE)
     uploadData.setUri(uri)
     uploadData.setCallbackUrl(self.CALLBACK_URL)
     return self.fapi.upload(uploadData)
Ejemplo n.º 10
0
 def test_setCallbackUrl(self):
     ud = UploadData("path", "name", "type")
     ud.setCallbackUrl("smartling.com")
     assert_equal(ud.callbackUrl, "smartling.com")
Ejemplo n.º 11
0
 def test_setApproveContent(self):
     ud = UploadData("path", "name", "type")
     ud.setApproveContent("true")
     assert_equal(ud.approveContent, "true")