Exemple #1
0
    def test_gengo_push_translations(self):
        """Tests GengoOrders get created"""
        ght = GengoHumanTranslator()

        # Create a few jobs covering multiple languages
        descs = [
            ('es', u'Facebook no se puede enlazar con peru'),
            ('es', u'No es compatible con whatsap'),

            ('de', u'Absturze und langsam unter Android'),
        ]
        for lang, desc in descs:
            obj = SuperModel(locale=lang, desc=desc)
            obj.save()

            job = GengoJob(
                content_object=obj,
                tier='standard',
                src_field='desc',
                dst_field='trans_desc',
                src_lang=lang,
                dst_lang='en'
            )
            job.save()

        with patch('fjord.translations.gengo_utils.Gengo') as GengoMock:
            mocker = GengoMock.return_value
            mocker.getAccountBalance.return_value = {
                u'opstat': u'ok',
                u'response': {
                    u'credits': '400.00',
                    u'currency': u'USD'
                }
            }
            # FIXME: This returns the same thing both times, but to
            # make the test "more kosher" we'd have this return two
            # different order_id values.
            mocker.postTranslationJobs.return_value = {
                u'opstat': u'ok',
                u'response': {
                    u'order_id': u'1337',
                    u'job_count': 2,
                    u'credits_used': u'0.35',
                    u'currency': u'USD'
                }
            }

            ght.push_translations()

            assert GengoOrder.objects.count() == 2

            order_by_id = dict(
                [(order.id, order) for order in GengoOrder.objects.all()]
            )

            jobs = GengoJob.objects.all()
            for job in jobs:
                assert job.order_id in order_by_id
Exemple #2
0
    def test_gengo_push_translations(self):
        """Tests GengoOrders get created"""
        ght = GengoHumanTranslator()

        # Create a few jobs covering multiple languages
        descs = [
            ('es', u'Facebook no se puede enlazar con peru'),
            ('es', u'No es compatible con whatsap'),
            ('de', u'Absturze und langsam unter Android'),
        ]
        for lang, desc in descs:
            obj = SuperModel(locale=lang, desc=desc)
            obj.save()

            job = GengoJob(content_object=obj,
                           tier='standard',
                           src_field='desc',
                           dst_field='trans_desc',
                           src_lang=lang,
                           dst_lang='en')
            job.save()

        with patch('fjord.translations.gengo_utils.Gengo') as GengoMock:
            mocker = GengoMock.return_value
            mocker.getAccountBalance.return_value = {
                u'opstat': u'ok',
                u'response': {
                    u'credits': '400.00',
                    u'currency': u'USD'
                }
            }
            # FIXME: This returns the same thing both times, but to
            # make the test "more kosher" we'd have this return two
            # different order_id values.
            mocker.postTranslationJobs.return_value = {
                u'opstat': u'ok',
                u'response': {
                    u'order_id': u'1337',
                    u'job_count': 2,
                    u'credits_used': u'0.35',
                    u'currency': u'USD'
                }
            }

            ght.push_translations()

            assert GengoOrder.objects.count() == 2

            order_by_id = dict([(order.id, order)
                                for order in GengoOrder.objects.all()])

            jobs = GengoJob.objects.all()
            for job in jobs:
                assert job.order_id in order_by_id
Exemple #3
0
    def test_pull_translations(self):
        ght = GengoHumanTranslator()

        obj = SuperModel(locale='es', desc=u'No es compatible con whatsap')
        obj.save()

        gj = GengoJob(
            content_object=obj,
            tier='standard',
            src_field='desc',
            dst_field='trans_desc',
            src_lang='es',
            dst_lang='en'
        )
        gj.save()

        order = GengoOrder(order_id=u'263413')
        order.save()

        gj.assign_to_order(order)

        gtoj_resp = {
            u'opstat': u'ok',
            u'response': {
                u'order': {
                    u'jobs_pending': [],
                    u'jobs_revising': [],
                    u'as_group': 0,
                    u'order_id': u'263413',
                    u'jobs_queued': u'0',
                    u'total_credits': u'0.35',
                    u'currency': u'USD',
                    u'total_units': u'7',
                    u'jobs_approved': [u'746197'],
                    u'jobs_reviewable': [],
                    u'jobs_available': [],
                    u'total_jobs': u'1'
                }
            }
        }

        gtjb_resp = {
            u'opstat': u'ok',
            u'response': {
                u'jobs': [
                    {
                        u'status': u'approved',
                        u'job_id': u'746197',
                        u'currency': u'USD',
                        u'order_id': u'263413',
                        u'body_tgt': u'No es compatible con whatsap',
                        u'body_src': u'Not compatible with whatsap',
                        u'credits': u'0.35',
                        u'eta': -1,
                        u'custom_data': u'localhost||GengoJob||{0}'.format(
                            gj.id),
                        u'tier': u'standard',
                        u'lc_tgt': u'en',
                        u'lc_src': u'es',
                        u'auto_approve': u'1',
                        u'unit_count': u'7',
                        u'slug': u'Mozilla Input feedback response',
                        u'ctime': 1403296006
                    }
                ]
            }
        }

        with patch('fjord.translations.gengo_utils.Gengo') as GengoMock:
            instance = GengoMock.return_value
            instance.getTranslationOrderJobs.return_value = gtoj_resp
            instance.getTranslationJobBatch.return_value = gtjb_resp

            ght.pull_translations()

            jobs = GengoJob.objects.all()
            assert len(jobs) == 1
            assert jobs[0].status == 'complete'

            orders = GengoOrder.objects.all()
            assert len(orders) == 1
            assert orders[0].status == 'complete'
Exemple #4
0
    def test_gengo_push_translations_not_enough_balance(self):
        """Tests enough balance for one order, but not both"""
        ght = GengoHumanTranslator()

        # Create a few jobs covering multiple languages
        descs = [
            ('es', u'Facebook no se puede enlazar con peru'),
            ('de', u'Absturze und langsam unter Android'),
        ]
        for lang, desc in descs:
            obj = SuperModel(locale=lang, desc=desc)
            obj.save()

            job = GengoJob(
                content_object=obj,
                tier='standard',
                src_field='desc',
                dst_field='trans_desc',
                src_lang=lang,
                dst_lang='en'
            )
            job.save()

        with patch('fjord.translations.gengo_utils.Gengo') as GengoMock:
            # FIXME: This returns the same thing both times, but to
            # make the test "more kosher" we'd have this return two
            # different order_id values.
            mocker = GengoMock.return_value
            mocker.getAccountBalance.return_value = {
                u'opstat': u'ok',
                u'response': {
                    # Enough for one order, but dips below threshold
                    # for the second one.
                    u'credits': '20.30',
                    u'currency': u'USD'
                }
            }
            mocker.postTranslationJobs.return_value = {
                u'opstat': u'ok',
                u'response': {
                    u'order_id': u'1337',
                    u'job_count': 2,
                    u'credits_used': u'0.35',
                    u'currency': u'USD'
                }
            }

            ght.push_translations()

            assert GengoOrder.objects.count() == 1
            # The "it's too low" email only.
            assert len(mail.outbox) == 1

        with patch('fjord.translations.gengo_utils.Gengo') as GengoMock:
            # FIXME: This returns the same thing both times, but to
            # make the test "more kosher" we'd have this return two
            # different order_id values.
            mocker = GengoMock.return_value
            mocker.getAccountBalance.return_value = {
                u'opstat': u'ok',
                u'response': {
                    # This is the balance after one order.
                    u'credits': '19.95',
                    u'currency': u'USD'
                }
            }
            mocker.postTranslationJobs.return_value = {
                u'opstat': u'ok',
                u'response': {
                    u'order_id': u'1337',
                    u'job_count': 2,
                    u'credits_used': u'0.35',
                    u'currency': u'USD'
                }
            }

            # The next time push_translations runs, it shouldn't
            # create any new jobs, but should send an email.
            ght.push_translations()

            assert GengoOrder.objects.count() == 1
            # This generates one more email.
            assert len(mail.outbox) == 2
Exemple #5
0
    def test_pull_translations(self):
        ght = GengoHumanTranslator()

        obj = SuperModel(locale='es', desc=u'No es compatible con whatsap')
        obj.save()

        gj = GengoJob(content_object=obj,
                      tier='standard',
                      src_field='desc',
                      dst_field='trans_desc',
                      src_lang='es',
                      dst_lang='en')
        gj.save()

        order = GengoOrder(order_id=u'263413')
        order.save()

        gj.assign_to_order(order)

        gtoj_resp = {
            u'opstat': u'ok',
            u'response': {
                u'order': {
                    u'jobs_pending': [],
                    u'jobs_revising': [],
                    u'as_group': 0,
                    u'order_id': u'263413',
                    u'jobs_queued': u'0',
                    u'total_credits': u'0.35',
                    u'currency': u'USD',
                    u'total_units': u'7',
                    u'jobs_approved': [u'746197'],
                    u'jobs_reviewable': [],
                    u'jobs_available': [],
                    u'total_jobs': u'1'
                }
            }
        }

        gtjb_resp = {
            u'opstat': u'ok',
            u'response': {
                u'jobs': [{
                    u'status':
                    u'approved',
                    u'job_id':
                    u'746197',
                    u'currency':
                    u'USD',
                    u'order_id':
                    u'263413',
                    u'body_tgt':
                    u'No es compatible con whatsap',
                    u'body_src':
                    u'Not compatible with whatsap',
                    u'credits':
                    u'0.35',
                    u'eta':
                    -1,
                    u'custom_data':
                    u'localhost||GengoJob||{0}'.format(gj.id),
                    u'tier':
                    u'standard',
                    u'lc_tgt':
                    u'en',
                    u'lc_src':
                    u'es',
                    u'auto_approve':
                    u'1',
                    u'unit_count':
                    u'7',
                    u'slug':
                    u'Mozilla Input feedback response',
                    u'ctime':
                    1403296006
                }]
            }
        }

        with patch('fjord.translations.gengo_utils.Gengo') as GengoMock:
            instance = GengoMock.return_value
            instance.getTranslationOrderJobs.return_value = gtoj_resp
            instance.getTranslationJobBatch.return_value = gtjb_resp

            ght.pull_translations()

            jobs = GengoJob.objects.all()
            assert len(jobs) == 1
            assert jobs[0].status == 'complete'

            orders = GengoOrder.objects.all()
            assert len(orders) == 1
            assert orders[0].status == 'complete'
Exemple #6
0
    def test_gengo_push_translations_not_enough_balance(self):
        """Tests enough balance for one order, but not both"""
        # Add recipients to mailing list
        ml = MailingList.objects.get(name='gengo_balance')
        ml.members = u'*****@*****.**'
        ml.save()

        ght = GengoHumanTranslator()

        # Create a few jobs covering multiple languages
        descs = [
            ('es', u'Facebook no se puede enlazar con peru'),
            ('de', u'Absturze und langsam unter Android'),
        ]
        for lang, desc in descs:
            obj = SuperModel(locale=lang, desc=desc)
            obj.save()

            job = GengoJob(content_object=obj,
                           tier='standard',
                           src_field='desc',
                           dst_field='trans_desc',
                           src_lang=lang,
                           dst_lang='en')
            job.save()

        with patch('fjord.translations.gengo_utils.Gengo') as GengoMock:
            # FIXME: This returns the same thing both times, but to
            # make the test "more kosher" we'd have this return two
            # different order_id values.
            mocker = GengoMock.return_value
            mocker.getAccountBalance.return_value = {
                u'opstat': u'ok',
                u'response': {
                    # Enough for one order, but dips below threshold
                    # for the second one.
                    u'credits': '20.30',
                    u'currency': u'USD'
                }
            }
            mocker.postTranslationJobs.return_value = {
                u'opstat': u'ok',
                u'response': {
                    u'order_id': u'1337',
                    u'job_count': 2,
                    u'credits_used': u'0.35',
                    u'currency': u'USD'
                }
            }

            ght.push_translations()

            assert GengoOrder.objects.count() == 1
            # The "it's too low" email only.
            assert len(mail.outbox) == 1

        with patch('fjord.translations.gengo_utils.Gengo') as GengoMock:
            # FIXME: This returns the same thing both times, but to
            # make the test "more kosher" we'd have this return two
            # different order_id values.
            mocker = GengoMock.return_value
            mocker.getAccountBalance.return_value = {
                u'opstat': u'ok',
                u'response': {
                    # This is the balance after one order.
                    u'credits': '19.95',
                    u'currency': u'USD'
                }
            }
            mocker.postTranslationJobs.return_value = {
                u'opstat': u'ok',
                u'response': {
                    u'order_id': u'1337',
                    u'job_count': 2,
                    u'credits_used': u'0.35',
                    u'currency': u'USD'
                }
            }

            # The next time push_translations runs, it shouldn't
            # create any new jobs, but should send an email.
            ght.push_translations()

            assert GengoOrder.objects.count() == 1
            # This generates one more email.
            assert len(mail.outbox) == 2