Exemplo n.º 1
0
class TestTranslationSingleJobFlow(unittest.TestCase):
    """
    Tests the flow of creating a job, adding a comment, getting the details,
    and then deleting the job.
    """
    def setUp(self):
        self.gengo = Gengo(public_key=API_PUBKEY,
                           private_key=API_PRIVKEY,
                           sandbox=True)
        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.gengo.postTranslationJob(job=single_job)
        self.assertEqual(job['opstat'], 'ok')
        self.assertTrue(job['response']['job']['job_id'] is not None)
        self.created_job_ids.append(job['response']['job']['job_id'])

    def test_postJobComment(self):
        """
        Tests posting a comment to a job.
        """
        posted_comment = self.gengo.postTranslationJobComment(
            id=self.created_job_ids[0],
            comment={'body': 'I love lamp oh mai gawd'})
        job_comments = self.gengo.getTranslationJobComments(
            id=self.created_job_ids[0])
        self.assertEqual(posted_comment['opstat'], 'ok')
        self.assertEqual(job_comments['opstat'], 'ok')
        self.assertEqual(job_comments['response']['thread'][0]['body'],
                         'I love lamp oh mai gawd')

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

        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.gengo.getTranslationJob(id=self.created_job_ids[0])
        self.assertEqual(job['opstat'], 'ok')

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

        # Pull down feedback. This should work fine, but there'll be no
        # feedback.
        feedback = self.gengo.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.gengo.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 id in self.created_job_ids:
            deleted_job = self.gengo.deleteTranslationJob(id=id)
            self.assertEqual(deleted_job['opstat'], 'ok')
Exemplo n.º 2
0
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

from gengo import Gengo

# Get an instance of Gengo to work with...
gengo = Gengo(
    public_key='your_public_key',
    private_key='your_private_key',
    sandbox=True,
)

# Post over a job for translation.
gengo.postTranslationJob(job={
    'type': 'text', # REQUIRED. Type to translate, you'll probably always put 'text' here. ;P
    'slug': 'Single :: English to Japanese', # REQUIRED. Slug for internally storing, can be generic.
    'body_src': 'Testing Gengo API library calls.', # REQUIRED. The text you're translating. ;P
    'lc_src': 'en', # REQUIRED. source_language_code (see getServiceLanguages() for a list of codes)
    'lc_tgt': 'ja', # REQUIRED. target_language_code (see getServiceLanguages() for a list of codes)
    'tier': 'standard', # REQUIRED. tier type ("machine", "standard", "pro", or "ultra")

    'auto_approve': 0, # OPTIONAL. Hopefully self explanatory (1 = yes, 0 = no),
    'comment': 'HEY THERE TRANSLATOR', # OPTIONAL. Comment to leave for translator.
    'callback_url': 'http://...', # OPTIONAL. Callback URL that updates are sent to.
    'custom_data': 'your optional custom data, limited to 1kb.' # OPTIONAL
})
Exemplo n.º 3
0
class TestTranslationSingleJobFlow(unittest.TestCase):
    """
    Tests the flow of creating a job, adding a comment, getting the details,
    and then deleting the job.
    """
    def setUp(self):
        self.gengo = Gengo(public_key=API_PUBKEY,
                           private_key=API_PRIVKEY,
                           sandbox=True)
        self.created_job_ids = []

        single_job = {
            'type': 'text',
            'slug': 'Single :: English to Japanese',
            'body_src': 'Test%ding Ge%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.gengo.postTranslationJob(job=single_job)
        self.assertEqual(job['opstat'], 'ok')
        self.assertTrue(job['response']['job']['job_id'] is not None)
        self.created_job_ids.append(job['response']['job']['job_id'])

    def test_postJobComment(self):
        """
        Tests posting a comment to a job.
        """
        posted_comment = self.gengo.postTranslationJobComment(
            id=self.created_job_ids[0],
            comment={'body': 'I love lamp oh mai gawd'})
        job_comments = self.gengo.getTranslationJobComments(
            id=self.created_job_ids[0])
        self.assertEqual(posted_comment['opstat'], 'ok')
        self.assertEqual(job_comments['opstat'], 'ok')
        self.assertEqual(job_comments['response']['thread'][0]['body'],
                         'I love lamp oh mai gawd')

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

        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.gengo.getTranslationJob(id=self.created_job_ids[0])
        self.assertEqual(job['opstat'], 'ok')

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

        # Pull down feedback. This should work fine, but there'll be no
        # feedback.
        feedback = self.gengo.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.gengo.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 id in self.created_job_ids:
            deleted_job = self.gengo.deleteTranslationJob(id=id)
            self.assertEqual(deleted_job['opstat'], 'ok')
Exemplo n.º 4
0
# Get an instance of Gengo to work with...
gengo = Gengo(
    public_key='your_public_key',
    private_key='your_private_key',
    sandbox=True,
)

# Post over a job for translation.
gengo.postTranslationJob(
    job={
        'type':
        'text',  # REQUIRED. Type to translate, you'll probably always put 'text' here. ;P
        'slug':
        'Single :: English to Japanese',  # REQUIRED. Slug for internally storing, can be generic.
        'body_src':
        'Testing Gengo API library calls.',  # REQUIRED. The text you're translating. ;P
        'lc_src':
        'en',  # REQUIRED. source_language_code (see getServiceLanguages() for a list of codes)
        'lc_tgt':
        'ja',  # REQUIRED. target_language_code (see getServiceLanguages() for a list of codes)
        'tier':
        'standard',  # REQUIRED. tier type ("machine", "standard", "pro", or "ultra")
        'auto_approve':
        0,  # OPTIONAL. Hopefully self explanatory (1 = yes, 0 = no),
        'comment':
        'HEY THERE TRANSLATOR',  # OPTIONAL. Comment to leave for translator.
        'callback_url':
        'http://...',  # OPTIONAL. Callback URL that updates are sent to.
        'custom_data': 'your optional custom data, limited to 1kb.'  # OPTIONAL
    })