Example #1
0
class ImageFormDescriptionTestCase(BaseFormTestCase):
    form_class = ImageForm
    request = testing.DummyRequest()
    image = Mock()
    image.description = '{{ 1 + 2 }}'
    form = form_class(request, image=image)

    def test_angular_expression_escaping_on_image_update_form(self):
        self.assertNotEqual(self.form.description.data, '{{ 1 + 2 }}')
        self.assertEqual(self.form.description.data,
                         '{{ 1 + 2 }}')
Example #2
0
    def cursor(self):
        cursor = Mock()

        def fetchone():
            return []

        def execute(what):
            self.executes.append(what)

        cursor.execute = execute
        cursor.fetchone = fetchone
        return cursor
Example #3
0
    def resource(self,
                 service_name,
                 region_name=None,
                 api_version=None,
                 use_ssl=True,
                 verify=None,
                 endpoint_url=None,
                 aws_access_key_id=None,
                 aws_secret_access_key=None,
                 aws_session_token=None,
                 config=None):
        resource = Mock()
        setattr(resources, service_name, resource)

        def queue(QueueName):
            q = Mock()
            if QueueName not in resources.sqs_messages:
                resources.sqs_messages.update({QueueName: []})

            def send_message(MessageBody, MessageGroupId):
                resources.sqs_messages[QueueName].append(
                    QueueMessage(MessageGroupId, MessageBody, QueueName))

            def receive_messages(**kwargs):
                for item in resources.sqs_messages[QueueName]:
                    item.attributes['ApproximateReceiveCount'] += 1
                    yield item

            q.receive_messages = receive_messages
            q.send_message = send_message
            return q

        def dynamo_table(name):
            table = Mock()
            table.name = name

            def query(**kwargs):
                if table.name in resources.dynamo:
                    if 'KeyConditionExpression' in kwargs:
                        return {
                            'Items':
                            filter_dynamo(kwargs['KeyConditionExpression'],
                                          resources.dynamo[table.name])
                        }
                return {'Items': []}

            def scan(**kwargs):
                if table.name in resources.dynamo:
                    if 'FilterExpression' in kwargs:
                        return {
                            'Items':
                            list(
                                filter(
                                    lambda x: x[kwargs['FilterExpression'].name
                                                ]['S'] == kwargs[
                                                    'FilterExpression'].value,
                                    resources.dynamo[table.name]))
                        }
                return {'Items': []}

            table.query = query
            table.scan = scan
            return table

        resource.get_queue_by_name = queue
        resource.Table = dynamo_table
        return resource
Example #4
0
from boto3 import Session as _Session

from tests import Mock
from flask_mail import Message as _Message, Mail as _Mail

resources = Mock()
resources.buckets = {}
resources.sqs_messages = {}
resources.queries = []
resources.dynamo = {}
resources.mails = []
resources.socketio = []
resources.requests = []


class Session(_Session):
    def __init__(self, **kwargs):
        self.parent = super(Session, self)
        self.parent.__init__(**kwargs)
        for key, value in kwargs.items():
            setattr(resources, key, value)

    def resource(self,
                 service_name,
                 region_name=None,
                 api_version=None,
                 use_ssl=True,
                 verify=None,
                 endpoint_url=None,
                 aws_access_key_id=None,
                 aws_secret_access_key=None,
#
# Distributed under the terms of the MIT license.
#
from __future__ import absolute_import, unicode_literals

import pywikibot
from pywikibot import site, Page, i18n

from scripts.redirect import RedirectRobot

from tests import Mock, patch
from tests.aspects import DefaultSiteTestCase


# To make `self.site.logged_in(sysop=True)` always return False
@patch.object(site.APISite, 'logged_in', new=Mock(return_value=False))
@patch.object(Page, 'exists', new=Mock(return_value=True))
class TestGetSDTemplateNoSysop(DefaultSiteTestCase):
    """Test the get_sd_template method of the RedirectRobot class."""
    def test_with_delete_and_existing_sdtemplate(self):
        """Test with delete and existing sdtemplate."""
        options = {'delete': True, 'sdtemplate': '{{t}}'}
        bot = RedirectRobot('broken', **options)
        self.assertEqual(bot.sdtemplate, '{{t}}')

    @patch.object(i18n, 'twhas_key', new=Mock(return_value=True))
    @patch.object(i18n, 'twtranslate', new=Mock(return_value='{{sd_title}}'))
    def test_with_delete_and_i18n_sd(self):
        """Test with delete and i18n template."""
        bot = RedirectRobot('broken', delete=True)
        self.assertEqual(bot.sdtemplate, '{{sd_title}}')
Example #6
0
    unittest,
    TestCase,
    DefaultDrySiteTestCase,
    WikibaseTestCase,
    ScriptMainTestCase,
)
from tests.bot_tests import TWNBotTestCase

if StdNumValidationError:
    AnyIsbnValidationException = (StdNumValidationError, IsbnExc)
else:
    AnyIsbnValidationException = IsbnExc


# Suppress ImportWarning: package stdnum.isbn not found; using scripts.isbn
@patch('pywikibot.cosmetic_changes.warn', Mock())
class TestCosmeticChangesISBN(DefaultDrySiteTestCase):
    """Test CosmeticChanges ISBN fix."""
    def test_valid_isbn(self):
        """Test ISBN."""
        cc = CosmeticChangesToolkit(self.site, namespace=0)

        text = cc.fix_ISBN(' ISBN 097522980x ')
        self.assertEqual(text, ' ISBN 0-9752298-0-X ')

        text = cc.fix_ISBN(' ISBN 9780975229804 ')
        self.assertEqual(text, ' ISBN 978-0-9752298-0-4 ')

    @unittest.expectedFailure  # T144288
    def test_valid_isbn_failing(self):
        """Test ISBN.