コード例 #1
0
ファイル: test_gengo.py プロジェクト: Givemore/fjord
    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
コード例 #2
0
ファイル: test_gengo.py プロジェクト: xrile/fjord
    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
コード例 #3
0
ファイル: test_gengo.py プロジェクト: Givemore/fjord
    def test_push_translations_low_balance_mails_admin(self):
        """Tests that a low balance sends email and does nothing else"""
        # Verify nothing is in the outbox
        assert len(mail.outbox) == 0

        # Call push_translation which should balk and email the
        # admin
        ght = GengoHumanTranslator()
        ght.push_translations()

        # Verify an email got sent and no jobs were created
        assert len(mail.outbox) == 1
        assert GengoJob.objects.count() == 0
コード例 #4
0
ファイル: test_gengo.py プロジェクト: groovecoder/fjord
    def test_push_translations_low_balance_mails_admin(self):
        """Tests that a low balance sends email and does nothing else"""
        # Verify nothing is in the outbox
        assert len(mail.outbox) == 0

        # Call push_translation which should balk and email the
        # admin
        ght = GengoHumanTranslator()
        ght.push_translations()

        # Verify an email got sent and no jobs were created
        assert len(mail.outbox) == 1
        assert GengoJob.objects.count() == 0
コード例 #5
0
ファイル: test_gengo.py プロジェクト: xrile/fjord
    def test_push_translations_low_balance_mails_admin(self):
        """Tests that a low balance sends email and does nothing else"""
        # Add recipients to mailing list
        ml = MailingList.objects.get(name='gengo_balance')
        ml.members = u'*****@*****.**'
        ml.save()

        # Verify nothing is in the outbox
        assert len(mail.outbox) == 0

        # Call push_translation which should balk and email the
        # admin
        ght = GengoHumanTranslator()
        ght.push_translations()

        # Verify an email got sent and no jobs were created
        assert len(mail.outbox) == 1
        assert GengoJob.objects.count() == 0
コード例 #6
0
ファイル: test_gengo.py プロジェクト: hoosteeno/fjord
    def test_push_translations_low_balance_mails_admin(self):
        """Tests that a low balance sends email and does nothing else"""
        # Add recipients to mailing list
        ml = MailingList.objects.get(name='gengo_balance')
        ml.members = u'*****@*****.**'
        ml.save()

        # Verify nothing is in the outbox
        assert len(mail.outbox) == 0

        # Call push_translation which should balk and email the
        # admin
        ght = GengoHumanTranslator()
        ght.push_translations()

        # Verify an email got sent and no jobs were created
        assert len(mail.outbox) == 1
        assert GengoJob.objects.count() == 0
コード例 #7
0
ファイル: test_gengo.py プロジェクト: Givemore/fjord
    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
コード例 #8
0
ファイル: test_gengo.py プロジェクト: xrile/fjord
    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