Example #1
0
    def balance_good_to_continue(self, balance, threshold):
        """Checks whether balance is good to continue

        If it's not, this sends some mail and returns False.

        We check against a threshold that's high enough that we're
        pretty sure the next job we create will not exceed the credits
        in the account. Pretty sure if we exceed the credits in the
        account, it'll return a non-ok opstat and that'll throw an
        exception and everything will be ok data-consistency-wise.

        """
        # FIXME: This should email a different group than admin,
        # but I'm (ab)using the admin group for now because I know
        # they're set up right.
        if balance < threshold:
            mail_admins(
                subject='Gengo account balance {0} < {1}'.format(
                    balance, threshold),
                message=wrap_with_paragraphs(
                    'Dagnabit! Send more money or the translations get it! '
                    'Don\'t try no funny business, neither!'
                    '\n\n'
                    'Love,'
                    '\n\n'
                    'Fjord McGengo'))
            return False

        return True
Example #2
0
    def run_daily_activities(self):
        # If gengosystem is disabled, we don't want to do anything.
        if not waffle.switch_is_active('gengosystem'):
            return

        gengo_api = FjordGengo()

        if not gengo_api.is_configured():
            # If Gengo isn't configured, then we drop out here rather
            # than raise a GengoConfig error.
            return

        balance = gengo_api.get_balance()
        threshold = settings.GENGO_ACCOUNT_BALANCE_THRESHOLD

        if threshold < balance < (2 * threshold):
            mail_admins(
                subject='Warning: Gengo account balance {0} < {1}'.format(
                    balance, 2 * threshold),
                message=wrap_with_paragraphs(
                    'Dear mom,'
                    '\n\n'
                    'Translations are the fab. Running low on funds. Send '
                    'more money when you get a chance.'
                    '\n\n'
                    'Love,'
                    '\n\n'
                    'Fjord McGengo'))
Example #3
0
    def run_daily_activities(self):
        # If gengosystem is disabled, we don't want to do anything.
        if not waffle.switch_is_active('gengosystem'):
            return

        gengo_api = FjordGengo()

        if not gengo_api.is_configured():
            # If Gengo isn't configured, then we drop out here rather
            # than raise a GengoConfig error.
            return

        balance = gengo_api.get_balance()
        threshold = settings.GENGO_ACCOUNT_BALANCE_THRESHOLD

        if threshold < balance < (2 * threshold):
            mail_admins(
                subject='Warning: Gengo account balance {0} < {1}'.format(
                    balance, 2 * threshold),
                message=wrap_with_paragraphs(
                    'Dear mom,'
                    '\n\n'
                    'Translations are the fab. Running low on funds. Send '
                    'more money when you get a chance.'
                    '\n\n'
                    'Love,'
                    '\n\n'
                    'Fjord McGengo'
                )
            )
Example #4
0
    def balance_good_to_continue(self, balance, threshold):
        """Checks whether balance is good to continue

        If it's not, this sends some mail and returns False.

        We check against a threshold that's high enough that we're
        pretty sure the next job we create will not exceed the credits
        in the account. Pretty sure if we exceed the credits in the
        account, it'll return a non-ok opstat and that'll throw an
        exception and everything will be ok data-consistency-wise.

        """
        # FIXME: This should email a different group than admin,
        # but I'm (ab)using the admin group for now because I know
        # they're set up right.
        if balance < threshold:
            mail_admins(
                subject='Gengo account balance {0} < {1}'.format(
                    balance, threshold),
                message=wrap_with_paragraphs(
                    'Dagnabit! Send more money or the translations get it! '
                    'Don\'t try no funny business, neither!'
                    '\n\n'
                    'Love,'
                    '\n\n'
                    'Fjord McGengo'
                )
            )
            return False

        return True
Example #5
0
    def test_edge_cases(self):
        test_data = [
            (None, 72, None),
            ('abcdefghijkl\nfoo bar', 8, 'abcdefgh\nijkl\nfoo bar'),
        ]

        for arg, width, expected in test_data:
            eq_(wrap_with_paragraphs(arg, width), expected)
Example #6
0
    def test_edge_cases(self):
        test_data = [
            (None, 72, None),
            ('abcdefghijkl\nfoo bar', 8, 'abcdefgh\nijkl\nfoo bar'),
        ]

        for arg, width, expected in test_data:
            assert wrap_with_paragraphs(arg, width) == expected
Example #7
0
    def test_basic(self):
        test_data = [
            ("", 72, ""),
            ("abc", 72, "abc"),
            ("abc\ndef", 72, "abc\ndef"),
            ("abc def ghi jkl\nfoo bar\nbaz", 8, "abc def\nghi jkl\nfoo bar\nbaz"),
        ]

        for arg, width, expected in test_data:
            eq_(wrap_with_paragraphs(arg, width), expected)
Example #8
0
    def test_basic(self):
        test_data = [
            ('', 72, ''),
            ('abc', 72, 'abc'),
            ('abc\ndef', 72, 'abc\ndef'),
            ('abc def ghi jkl\nfoo bar\nbaz', 8,
             'abc def\nghi jkl\nfoo bar\nbaz'),
        ]

        for arg, width, expected in test_data:
            eq_(wrap_with_paragraphs(arg, width), expected)
Example #9
0
    def test_basic(self):
        test_data = [
            ('', 72, ''),
            ('abc', 72, 'abc'),
            ('abc\ndef', 72, 'abc\ndef'),
            ('abc def ghi jkl\nfoo bar\nbaz', 8,
             'abc def\nghi jkl\nfoo bar\nbaz'),
        ]

        for arg, width, expected in test_data:
            assert wrap_with_paragraphs(arg, width) == expected
Example #10
0
    def balance_good_to_continue(self, balance, threshold):
        """Checks whether balance is good to continue

        If it's not, this sends some mail and returns False.

        We check against a threshold that's high enough that we're
        pretty sure the next job we create will not exceed the credits
        in the account. Pretty sure if we exceed the credits in the
        account, it'll return a non-ok opstat and that'll throw an
        exception and everything will be ok data-consistency-wise.

        """
        # FIXME: This should email a different group than admin,
        # but I'm (ab)using the admin group for now because I know
        # they're set up right.
        if balance < threshold:
            recipients = get_recipients('gengo_balance')
            subject = 'Gengo account balance {0} < {1}'.format(
                balance, threshold)
            body = wrap_with_paragraphs(dedent("""\
            Dagnabit! Send more money or the translations get it!
            Don't try no funny business, neither!

            Love,

            Fjord McGengo
            """))
            if recipients:
                send_mail(
                    subject=subject,
                    message=body,
                    recipient_list=recipients,
                    from_email=settings.SERVER_EMAIL
                )

            else:
                log.info('No recipients for "%s"\n%s\n%s' % (
                    'gengo_balance', subject, body))

            return False

        return True
Example #11
0
    def run_daily_activities(self):
        # If gengosystem is disabled, we don't want to do anything.
        if not waffle.switch_is_active('gengosystem'):
            return

        gengo_api = FjordGengo()

        if not gengo_api.is_configured():
            # If Gengo isn't configured, then we drop out here rather
            # than raise a GengoConfig error.
            return

        balance = gengo_api.get_balance()
        threshold = settings.GENGO_ACCOUNT_BALANCE_THRESHOLD

        if threshold < balance < (2 * threshold):
            recipients = get_recipients('gengo_balance')
            subject = 'Warning: Gengo account balance {0} < {1}'.format(
                balance, 2 * threshold)
            body = wrap_with_paragraphs(dedent("""\
            Dear mom,

            Translations are the fab. Running low on funds. Send
            more money when you get a chance.

            Love,

            Fjord McGengo
            """))

            if recipients:
                send_mail(
                    subject=subject,
                    message=body,
                    recipient_list=recipients,
                    from_email=settings.SERVER_EMAIL
                )

            else:
                log.info('No recipients for "%s"\n%s\n%s' % (
                    'gengo_balance', subject, body))
Example #12
0
    def balance_good_to_continue(self, balance, threshold):
        """Checks whether balance is good to continue

        If it's not, this sends some mail and returns False.

        We check against a threshold that's high enough that we're
        pretty sure the next job we create will not exceed the credits
        in the account. Pretty sure if we exceed the credits in the
        account, it'll return a non-ok opstat and that'll throw an
        exception and everything will be ok data-consistency-wise.

        """
        # FIXME: This should email a different group than admin,
        # but I'm (ab)using the admin group for now because I know
        # they're set up right.
        if balance < threshold:
            recipients = get_recipients('gengo_balance')
            subject = 'Gengo account balance {0} < {1}'.format(
                balance, threshold)
            body = wrap_with_paragraphs(
                dedent("""\
            Dagnabit! Send more money or the translations get it!
            Don't try no funny business, neither!

            Love,

            Fjord McGengo
            """))
            if recipients:
                send_mail(subject=subject,
                          message=body,
                          recipient_list=recipients,
                          from_email=settings.SERVER_EMAIL)

            else:
                log.info('No recipients for "%s"\n%s\n%s' %
                         ('gengo_balance', subject, body))

            return False

        return True
Example #13
0
    def balance_check(self, balance, threshold):
        """Checks the balance and emails a warning if we're getting low

        This doesn't halt translation--just issues a warning via email.

        """
        if balance > threshold and balance < (2 * threshold):
            mail_admins(
                subject='Warning: Gengo account balance {0} < {1}'.format(
                    balance, 2 * threshold),
                message=wrap_with_paragraphs(
                    'Dear mom,'
                    '\n\n'
                    'Translations are the fab. Running low on funds. Send '
                    'more money when you get a chance.'
                    '\n\n'
                    'Love,'
                    '\n\n'
                    'Fjord McGengo'
                )
            )
Example #14
0
    def run_daily_activities(self):
        # If gengosystem is disabled, we don't want to do anything.
        if not waffle.switch_is_active('gengosystem'):
            return

        gengo_api = FjordGengo()

        if not gengo_api.is_configured():
            # If Gengo isn't configured, then we drop out here rather
            # than raise a GengoConfig error.
            return

        balance = gengo_api.get_balance()
        threshold = settings.GENGO_ACCOUNT_BALANCE_THRESHOLD

        if threshold < balance < (2 * threshold):
            recipients = get_recipients('gengo_balance')
            subject = 'Warning: Gengo account balance {0} < {1}'.format(
                balance, 2 * threshold)
            body = wrap_with_paragraphs(
                dedent("""\
            Dear mom,

            Translations are the fab. Running low on funds. Send
            more money when you get a chance.

            Love,

            Fjord McGengo
            """))

            if recipients:
                send_mail(subject=subject,
                          message=body,
                          recipient_list=recipients,
                          from_email=settings.SERVER_EMAIL)

            else:
                log.info('No recipients for "%s"\n%s\n%s' %
                         ('gengo_balance', subject, body))
Example #15
0
    def test_edge_cases(self):
        test_data = [(None, 72, None), ("abcdefghijkl\nfoo bar", 8, "abcdefgh\nijkl\nfoo bar")]

        for arg, width, expected in test_data:
            eq_(wrap_with_paragraphs(arg, width), expected)