~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/lp/testing/__init__.py

  • Committer: Gary Poster
  • Date: 2011-09-20 22:33:07 UTC
  • mto: This revision was merged to the branch mainline in revision 14015.
  • Revision ID: gary.poster@canonical.com-20110920223307-zt1kr1px2ixjg9mn
Add yui xhr integration test support.

Show diffs side-by-side

added added

removed removed

Lines of Context:
8
8
 
9
9
__metaclass__ = type
10
10
__all__ = [
 
11
    'AbstractYUITestCase',
11
12
    'ANONYMOUS',
12
13
    'anonymous_logged_in',
13
14
    'api_url',
863
864
        "([#!$%&()+,./:;?@~|^{}\\[\\]`*\\\'\\\"])", r"\\\\\1", expression)
864
865
 
865
866
 
866
 
class YUIUnitTestCase(TestCase):
 
867
class AbstractYUITestCase(TestCase):
867
868
 
868
869
    layer = None
869
870
    suite_name = ''
870
871
    js_timeout = 30000
 
872
    html_uri = None
 
873
    test_path = None
871
874
 
872
875
    TIMEOUT = object()
873
876
    MISSING_REPORT = object()
874
877
 
875
878
    _yui_results = None
876
879
 
877
 
    def __init__(self):
 
880
    def __init__(self, methodName=None):
878
881
        """Create a new test case without a choice of test method name.
879
882
 
880
883
        Preventing the choice of test method ensures that we can safely
881
884
        provide a test ID based on the file path.
882
885
        """
883
 
        super(YUIUnitTestCase, self).__init__("checkResults")
884
 
 
885
 
    def initialize(self, test_path):
886
 
        self.test_path = test_path
 
886
        if methodName is None:
 
887
            methodName = self._testMethodName
 
888
        else:
 
889
            assert methodName == self._testMethodName
 
890
        super(AbstractYUITestCase, self).__init__(methodName)
887
891
 
888
892
    def id(self):
889
893
        """Return an ID for this test based on the file path."""
890
894
        return os.path.relpath(self.test_path, config.root)
891
895
 
892
896
    def setUp(self):
893
 
        super(YUIUnitTestCase, self).setUp()
 
897
        super(AbstractYUITestCase, self).setUp()
894
898
        # html5browser imports from the gir/pygtk stack which causes
895
899
        # twisted tests to break because of gtk's initialize.
896
900
        import html5browser
897
901
        client = html5browser.Browser()
898
 
        html_uri = 'file://%s' % os.path.join(
899
 
            config.root, 'lib', self.test_path)
900
 
        page = client.load_page(html_uri, timeout=self.js_timeout)
 
902
        page = client.load_page(self.html_uri, timeout=self.js_timeout)
901
903
        if page.return_code == page.CODE_FAIL:
902
904
            self._yui_results = self.TIMEOUT
903
905
            return
944
946
        self.assertEqual([], failures, '\n'.join(failures))
945
947
 
946
948
 
 
949
class YUIUnitTestCase(AbstractYUITestCase):
 
950
 
 
951
    _testMethodName = 'checkResults'
 
952
 
 
953
    def initialize(self, test_path):
 
954
        # The path is a .html file.
 
955
        self.test_path = test_path
 
956
        self.html_uri = 'file://%s' % os.path.join(
 
957
            config.root, 'lib', self.test_path)
 
958
 
 
959
 
947
960
def build_yui_unittest_suite(app_testing_path, yui_test_class):
948
961
    suite = unittest.TestSuite()
949
962
    testing_path = os.path.join(config.root, 'lib', app_testing_path)