Example #1
0
    def __new__(cls, name, bases, attrs):
        for attr_name, attr_value in attrs.items():
            if "test" in attr_name and callable(attr_value):
                attrs[attr_name] = show_on_error(attr_value, clsname=name)

        for attr in commands.__all__:
            if attr in ("find", "go", "notfind", "url"):
                attr_name = "_" + attr
            else:
                attr_name = attr

            attrs.update({attr_name: staticmethod(getattr(commands, attr))})

        attrs.update({"check_links": staticmethod(check_links)})

        super_new = super(HttpTestCaseMetaclass, cls).__new__
        return super_new(cls, name, bases, attrs)
Example #2
0
    def __new__(cls, name, bases, attrs):
        for attr_name, attr_value in attrs.items():
            if 'test' in attr_name and callable(attr_value):
                attrs[attr_name] = show_on_error(attr_value, clsname=name)

        for attr in commands.__all__:
            if attr in ('find', 'go', 'notfind', 'url'):
                attr_name = '_' + attr
            else:
                attr_name = attr

            attrs.update({attr_name: staticmethod(getattr(commands, attr))})

        attrs.update({'check_links': staticmethod(check_links)})

        super_new = super(HttpTestCaseMetaclass, cls).__new__
        return super_new(cls, name, bases, attrs)
Example #3
0
    def __new__(cls, name, bases, attrs):
        for attr_name, attr_value in attrs.items():
            if 'test' in attr_name and callable(attr_value):
                attrs[attr_name] = show_on_error(attr_value, clsname=name)

        # Add twill commands to testcase as staticmethods
        for attr in commands.__all__:
            if attr in ('find', 'go', 'notfind', 'run', 'url'):
                attr_name = '_' + attr
            else:
                attr_name = attr

            attrs.update({attr_name: staticmethod(getattr(commands, attr))})

        attrs.update({'call_command': staticmethod(call_command)})
        attrs.update({'check_links': staticmethod(check_links)})

        # Add ``delete``, ``get``, ``head``, ``options``, ``post``, ``put``
        # methods from Django test client to ``TestCase``
        for attr_name in ('delete', 'get', 'head', 'options', 'post', 'put'):
            attrs.update({attr_name: django_request(attr_name)})
            attrs.update({'%s200' % attr_name: django_request(attr_name, 200)})

        # Use ``datadiff_assert_equal`` instead of ``assert_equal`` function
        # if necessary
        if getattr(settings, 'TDDSPRY_USE_DATADIFF', False):
            attrs['use_datadiff'] = True

        # Dirty hack to convert django testcase camelcase method names to
        # name with underscores
        attr_names = filter(lambda item: item.startswith('assert'),
                            dir(DjangoTestCase))

        for attr_name in attr_names:
            attrs.update({attr_name: getattr(DjangoTestCase, attr_name)})

        super_new = super(TestCaseMetaclass, cls).__new__
        return super_new(cls, name, bases, attrs)