当前位置: 首页>>代码示例>>Python>>正文


Python MyGengo.getTranslationJobs方法代码示例

本文整理汇总了Python中mygengo.MyGengo.getTranslationJobs方法的典型用法代码示例。如果您正苦于以下问题:Python MyGengo.getTranslationJobs方法的具体用法?Python MyGengo.getTranslationJobs怎么用?Python MyGengo.getTranslationJobs使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在mygengo.MyGengo的用法示例。


在下文中一共展示了MyGengo.getTranslationJobs方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: MyGengo

# 需要导入模块: from mygengo import MyGengo [as 别名]
# 或者: from mygengo.MyGengo import getTranslationJobs [as 别名]
# -*- coding: utf-8 -*-
#!/usr/bin/python

from mygengo import MyGengo

# Get an instance of MyGengo to work with...
gengo = MyGengo(
    public_key = 'your_public_key',
    private_key = 'your_private_key',
    sandbox = True, # possibly false, depending on your dev needs
)

# Think of this as a "search my jobs" method, and it becomes very self-explanatory.
print gengo.getTranslationJobs(status = "upaid", count = 15)
开发者ID:crschmidt,项目名称:mygengo-python,代码行数:16,代码来源:getTranslationJobs.py

示例2: TestTranslationSingleJobFlow

# 需要导入模块: from mygengo import MyGengo [as 别名]
# 或者: from mygengo.MyGengo import getTranslationJobs [as 别名]
class TestTranslationSingleJobFlow(unittest.TestCase):
	"""
		Tests the flow of creating a job, updating it, getting the details, and then
		deleting the job. This is the thick of it!

		Flow is as follows:

			1: Create a mock job and get an estimate for it (setUp)
			2: Create three jobs - 1 single, 2 batched
			3: Update the first job with some arbitrary information or something
			4: Post a comment on the first job
			6: Perform a hell of a lot of GETs to the Gengo API to check stuff
			7: Delete the job if all went well (teardown phase)
	"""
	def setUp(self):
		"""
			Creates the initial batch of jobs for the other test functions here to operate on.
		"""
		# First we'll create three jobs - one regular, and two at the same time...
		self.myGengo = MyGengo(public_key = public_key, private_key = private_key, sandbox = SANDBOX)
		self.created_job_ids = []

		single_job = {
			'type': 'text',
			'slug': 'Single :: English to Japanese',
			'body_src': 'Test%ding myGe%dngo A%dPI li%dbrary calls.' % (int(random.randrange(1,226,1)), int(random.randrange(1,226,1)), int(random.randrange(1,226,1)), int(random.randrange(1,226,1))),
			'lc_src': 'en',
			'lc_tgt': 'ja',
			'tier': 'standard',
			'auto_approve': 0,
		}

		job = self.myGengo.postTranslationJob(job = single_job)
		self.assertEqual(job['opstat'], 'ok')
		self.assertIsNotNone(job['response']['job']['job_id'])
		self.created_job_ids.append(job['response']['job']['job_id'])

	@unittest.skip("We don't test Gengo.getTranslationJobPreviewImage() because it's potentially resource heavy on the Gengo API.")
	def test_getTranslationJobPreviewImage(self):
		"""
			This test could be a bit more granular, but I'm undecided at the moment - testing the response stream
			of this method is more of a Unit Test for Gengo than Gengo. Someone can extend if they see fit, but I
			currently see no reason to mess with this further.
		"""
		img = self.myGengo.getTranslationJobPreviewImage(id = self.created_job_ids[0])
		self.assertIsNotNone(img)

	def test_postJobDataMethods(self):
		"""
			Tests all the Gengo methods that deal with updating jobs, posting comments, etc. test_getJobDataMethods() checks things,
			but they need to exist first - think of this as the alcoholic mother to _getJobDataMethods().
		"""
		# The 'update' method can't really be tested, as it requires the translator having actually done something before
		# it's of any use. Thing is, in automated testing, we don't really have a method to flip the switch on the Gengo end. If we
		# WERE to test this method, it'd look a little something like this:
		#
		#	updated_job = self.myGengo.updateTranslationJob(id = self.created_job_ids[0], action = {
		#		'action': 'purchase',
		#	})
		#	self.assertEqual(updated_job['opstat'], 'ok')

		posted_comment = self.myGengo.postTranslationJobComment(id = self.created_job_ids[0], comment = {
			'body': 'I love lamp oh mai gawd',
		})
		self.assertEqual(posted_comment['opstat'], 'ok')

	def test_getJobDataMethods(self):
		"""
			Test a ton of methods that GET data from the Gengo API, based on the jobs we've created and such.

			These are separate from the other GET request methods because this might be a huge nuisance to their API,
			and I figure it's worth separating out the pain-point test cases so they could be disabled easily in a
			distribution or something.
		"""
		# Pull down data about one specific job...
		job = self.myGengo.getTranslationJob(id = self.created_job_ids[0])
		self.assertEqual(job['opstat'], 'ok')

		# Pull down the 10 most recently submitted jobs.
		jobs = self.myGengo.getTranslationJobs()
		self.assertEqual(jobs['opstat'], 'ok')

		# Pull down the comment(s) we created earlier in this test suite.
		job_comments = self.myGengo.getTranslationJobComments(id = self.created_job_ids[0])
		self.assertEqual(job_comments['opstat'], 'ok')

		# Pull down feedback. This should work fine, but there'll be no feedback or anything, so... meh.
		feedback = self.myGengo.getTranslationJobFeedback(id = self.created_job_ids[0])
		self.assertEqual(feedback['opstat'], 'ok')

		# Lastly, pull down any revisions that definitely didn't occur due to this being a simulated test.
		revisions = self.myGengo.getTranslationJobRevisions(id = self.created_job_ids[0])
		self.assertEqual(revisions['opstat'], 'ok')

		# So it's worth noting here that we can't really test getTranslationJobRevision(), because no real revisions
		# exist at this point, and a revision ID is required to pull that method off successfully. Bai now.

	def tearDown(self):
		"""
			Delete every job we've created for this somewhat ridiculously thorough testing scenario.
#.........这里部分代码省略.........
开发者ID:kbairak,项目名称:mygengo-python,代码行数:103,代码来源:tests.py

示例3: TestTranslationJobFlow

# 需要导入模块: from mygengo import MyGengo [as 别名]
# 或者: from mygengo.MyGengo import getTranslationJobs [as 别名]

#.........这里部分代码省略.........
				'lc_src': 'ja',
				'lc_tgt': 'en',
				'tier': 'ultra',
			},
		}
		
		# Now that we've got the job, let's go ahead and see how much it'll cost.
		cost_assessment = self.myGengo.determineTranslationCost(jobs = {'jobs': multiple_jobs})
		self.assertEqual(cost_assessment['opstat'], 'ok')
		
		# If that method worked, sweet. Move on and create three jobs, store their IDs. Make sure we got an ID
		# back, since these methods are otherwise largely useless without that returned data. These tests walk a fine
		# line between testing myGengo and the myGengo API functionality as a whole - watch yourself if you add to this. :)
		job = self.myGengo.postTranslationJob(job = single_job)
		self.assertEqual(job['opstat'], 'ok')
		self.assertIsNotNone(job['response']['job']['job_id'])
		self.created_job_ids.append(job['response']['job']['job_id'])
		
		jobs = self.myGengo.postTranslationJobs(jobs = {'jobs': multiple_jobs})
		self.assertEqual(job['opstat'], 'ok')
		
		# This is a fairly ugly way to check for and retrieve job IDs; in an ideal system you know the keys, and... well,
		# truthfully we do here too. I suppose this is moreso here as an example of how to get IDs in a situation where you
		# don't know the keys. May or may not be useful to some.
		for job_obj in jobs['response']['jobs']:
			for job in job_obj:
				self.assertIsNotNone(job_obj[job]['job_id'])
				self.created_job_ids.append(job_obj[job]['job_id'])
	
	@unittest.skip("We don't test myGengo.getTranslationJobPreviewImage() because it's potentially resource heavy on the myGengo API.")
	def test_getTranslationJobPreviewImage(self):
		"""
			This test could be a bit more granular, but I'm undecided at the moment - testing the response stream
			of this method is more of a Unit Test for myGengo than myGengo. Someone can extend if they see fit, but I 
			currently see no reason to mess with this further.
		"""
		img = self.myGengo.getTranslationJobPreviewImage(id = self.created_job_ids[0])
		self.assertIsNotNone(img)
	
	def test_postJobDataMethods(self):
		"""
			Tests all the myGengo methods that deal with updating jobs, posting comments, etc. test_getJobDataMethods() checks things,
			but they need to exist first - think of this as the alcoholic mother to _getJobDataMethods().
		"""
		# The 'update' method can't really be tested, as it requires the translator having actually done something before
		# it's of any use. Thing is, in automated testing, we don't really have a method to flip the switch on the myGengo end. If we
		# WERE to test this method, it'd look a little something like this:
		#	
		#	updated_job = self.myGengo.updateTranslationJob(id = self.created_job_ids[0], action = {
		#		'action': 'purchase',
		#	})
		#	self.assertEqual(updated_job['opstat'], 'ok')
		
		posted_comment = self.myGengo.postTranslationJobComment(id = self.created_job_ids[0], comment = {
			'body': 'I love lamp oh mai gawd',
		})
		self.assertEqual(posted_comment['opstat'], 'ok')
	
	def test_getJobDataMethods(self):
		"""
			Test a ton of methods that GET data from the myGengo API, based on the jobs we've created and such.
			
			These are separate from the other GET request methods because this might be a huge nuisance to their API,
			and I figure it's worth separating out the pain-point test cases so they could be disabled easily in a 
			distribution or something.
		"""
		# Pull down data about one specific job...
		job = self.myGengo.getTranslationJob(id = self.created_job_ids[0])
		self.assertEqual(job['opstat'], 'ok')
		
		# Pull down the 10 most recently submitted jobs.
		jobs = self.myGengo.getTranslationJobs()
		self.assertEqual(jobs['opstat'], 'ok')
		
		# Test getting the batch that a job is in...
		job_batch = self.myGengo.getTranslationJobBatch(id = self.created_job_ids[1])
		self.assertEqual(job_batch['opstat'], 'ok')
		
		# Pull down the comment(s) we created earlier in this test suite.
		job_comments = self.myGengo.getTranslationJobComments(id = self.created_job_ids[0])
		self.assertEqual(job_comments['opstat'], 'ok')
		
		# Pull down feedback. This should work fine, but there'll be no feedback or anything, so... meh.
		feedback = self.myGengo.getTranslationJobFeedback(id = self.created_job_ids[0])
		self.assertEqual(feedback['opstat'], 'ok')
		
		# Lastly, pull down any revisions that definitely didn't occur due to this being a simulated test.
		revisions = self.myGengo.getTranslationJobRevisions(id = self.created_job_ids[0])
		self.assertEqual(revisions['opstat'], 'ok')
		
		# So it's worth noting here that we can't really test getTranslationJobRevision(), because no real revisions
		# exist at this point, and a revision ID is required to pull that method off successfully. Bai now.
	
	def tearDown(self):
		"""
			Delete every job we've created for this somewhat ridiculously thorough testing scenario.
		"""
		for id in self.created_job_ids:
			deleted_job = self.myGengo.deleteTranslationJob(id = id)
			self.assertEqual(deleted_job['opstat'], 'ok')
开发者ID:fvbock,项目名称:mygengo-python,代码行数:104,代码来源:tests.py

示例4: TestTranslationJobFlowMixedOrder

# 需要导入模块: from mygengo import MyGengo [as 别名]
# 或者: from mygengo.MyGengo import getTranslationJobs [as 别名]

#.........这里部分代码省略.........
				multiple_jobs[k] = {
						'type': 'file',
						'identifier': j['identifier'],
						'comment': 'Test comment for filejob %s' % (k,),
						'glossary_id': None,
						'use_preferred': 0,
						'force': 1
					}
			else:
				multiple_jobs[k] = multiple_jobs_quote[k]
				multiple_jobs[k]['comment'] = 'Test comment for textjob %s' % (k,)
				multiple_jobs[k]['glossary_id'] = None
				multiple_jobs[k]['use_preferred'] = 0
				multiple_jobs[k]['force'] = 1


		jobs = self.myGengo.postTranslationJobs(jobs = {'jobs': multiple_jobs})
		self.assertEqual(jobs['opstat'], 'ok')
		self.assertTrue('order_id' in jobs['response'])
		self.assertTrue('credits_used' in jobs['response'])
		self.assertEqual(jobs['response']['job_count'], 2)

		# get some order information - in v2 the jobs need to have gone through a
		# queueing system so we wait a little bit
		time.sleep( 30 )
		resp = self.myGengo.getTranslationOrderJobs(id = jobs['response']['order_id'])
		self.assertEqual(len(resp['response']['order']['jobs_available']), 2)
		self.created_job_ids.extend(resp['response']['order']['jobs_available'])

	@unittest.skip("We don't test Gengo.getTranslationJobPreviewImage() because it's potentially resource heavy on the Gengo API.")
	def test_getTranslationJobPreviewImage(self):
		"""
			This test could be a bit more granular, but I'm undecided at the moment - testing the response stream
			of this method is more of a Unit Test for Gengo than Gengo. Someone can extend if they see fit, but I
			currently see no reason to mess with this further.
		"""
		img = self.myGengo.getTranslationJobPreviewImage(id = self.created_job_ids[0])
		self.assertIsNotNone(img)

	def test_postJobDataMethods(self):
		"""
			Tests all the Gengo methods that deal with updating jobs, posting comments, etc. test_getJobDataMethods() checks things,
			but they need to exist first - think of this as the alcoholic mother to _getJobDataMethods().
		"""
		# The 'update' method can't really be tested, as it requires the translator having actually done something before
		# it's of any use. Thing is, in automated testing, we don't really have a method to flip the switch on the Gengo end. If we
		# WERE to test this method, it'd look a little something like this:
		#
		#	updated_job = self.myGengo.updateTranslationJob(id = self.created_job_ids[0], action = {
		#		'action': 'purchase',
		#	})
		#	self.assertEqual(updated_job['opstat'], 'ok')

		posted_comment = self.myGengo.postTranslationJobComment(id = self.created_job_ids[0], comment = {
			'body': 'I love lamp oh mai gawd',
		})
		self.assertEqual(posted_comment['opstat'], 'ok')

	def test_getJobDataMethods(self):
		"""
			Test a ton of methods that GET data from the Gengo API, based on the jobs we've created and such.

			These are separate from the other GET request methods because this might be a huge nuisance to their API,
			and I figure it's worth separating out the pain-point test cases so they could be disabled easily in a
			distribution or something.
		"""
		# Pull down data about one specific job...
		job = self.myGengo.getTranslationJob(id = self.created_job_ids[0])
		self.assertEqual(job['opstat'], 'ok')

		# Pull down the 10 most recently submitted jobs.
		jobs = self.myGengo.getTranslationJobs()
		self.assertEqual(jobs['opstat'], 'ok')

		# Test getting the batch that a job is in...
		job_batch = self.myGengo.getTranslationJobBatch(id = self.created_job_ids[1])
		self.assertEqual(job_batch['opstat'], 'ok')

		# Pull down the comment(s) we created earlier in this test suite.
		job_comments = self.myGengo.getTranslationJobComments(id = self.created_job_ids[0])
		self.assertEqual(job_comments['opstat'], 'ok')

		# Pull down feedback. This should work fine, but there'll be no feedback or anything, so... meh.
		feedback = self.myGengo.getTranslationJobFeedback(id = self.created_job_ids[0])
		self.assertEqual(feedback['opstat'], 'ok')

		# Lastly, pull down any revisions that definitely didn't occur due to this being a simulated test.
		revisions = self.myGengo.getTranslationJobRevisions(id = self.created_job_ids[0])
		self.assertEqual(revisions['opstat'], 'ok')

		# So it's worth noting here that we can't really test getTranslationJobRevision(), because no real revisions
		# exist at this point, and a revision ID is required to pull that method off successfully. Bai now.

	def tearDown(self):
		"""
			Delete every job we've created for this somewhat ridiculously thorough testing scenario.
		"""
		for id in self.created_job_ids:
			deleted_job = self.myGengo.deleteTranslationJob(id = id)
			self.assertEqual(deleted_job['opstat'], 'ok')
开发者ID:kbairak,项目名称:mygengo-python,代码行数:104,代码来源:tests.py


注:本文中的mygengo.MyGengo.getTranslationJobs方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。