~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/canonical/testing/layers.py

  • Committer: Francis J. Lacoste
  • Date: 2011-07-08 20:31:48 UTC
  • mfrom: (13397 devel)
  • mto: This revision was merged to the branch mainline in revision 13501.
  • Revision ID: francis.lacoste@canonical.com-20110708203148-mzcn7o91cn2nm830
Merge devel.

Show diffs side-by-side

added added

removed removed

Lines of Context:
571
571
    ZopelessLayer, FunctionalLayer or sublayer as they will be accessing
572
572
    memcached using a utility.
573
573
    """
574
 
    _reset_between_tests = True
575
574
 
576
575
    # A memcache.Client instance.
577
576
    client = None
640
639
    @classmethod
641
640
    @profiled
642
641
    def testSetUp(cls):
643
 
        if MemcachedLayer._reset_between_tests:
644
 
            MemcachedLayer.client.forget_dead_hosts()
645
 
            MemcachedLayer.client.flush_all()
 
642
        MemcachedLayer.client.forget_dead_hosts()
 
643
        MemcachedLayer.client.flush_all()
646
644
 
647
645
    @classmethod
648
646
    @profiled
661
659
 
662
660
class RabbitMQLayer(BaseLayer):
663
661
    """Provides tests access to a rabbitMQ instance."""
664
 
    _reset_between_tests = True
665
662
 
666
663
    rabbit = RabbitServer()
667
664
 
707
704
class DatabaseLayer(BaseLayer):
708
705
    """Provides tests access to the Launchpad sample database."""
709
706
 
710
 
    # If set to False, database will not be reset between tests. It is
711
 
    # your responsibility to set it back to True and call
712
 
    # Database.force_dirty_database() when you do so.
713
 
    _reset_between_tests = True
714
 
 
715
707
    _is_setup = False
716
708
    _db_fixture = None
717
709
    # For parallel testing, we allocate a temporary template to prevent worker
777
769
 
778
770
    @classmethod
779
771
    def _ensure_db(cls):
780
 
        if cls._reset_between_tests:
781
 
            cls._db_fixture.setUp()
 
772
        cls._db_fixture.setUp()
782
773
        # Ensure that the database is connectable. Because we might have
783
774
        # just created it, keep trying for a few seconds incase PostgreSQL
784
775
        # is taking its time getting its house in order.
802
793
        # Ensure that the database is connectable
803
794
        cls.connect().close()
804
795
 
805
 
        if cls._reset_between_tests:
806
 
            cls._db_fixture.tearDown()
 
796
        cls._db_fixture.tearDown()
807
797
 
808
798
        # Fail tests that forget to uninstall their database policies.
809
799
        from canonical.launchpad.webapp.adapter import StoreSelector
890
880
    Calls to the Librarian will fail unless there is also a Launchpad
891
881
    database available.
892
882
    """
893
 
    _reset_between_tests = True
894
883
 
895
884
    librarian_fixture = None
896
885
 
897
886
    @classmethod
898
887
    @profiled
899
888
    def setUp(cls):
900
 
        if not cls._reset_between_tests:
901
 
            raise LayerInvariantError(
902
 
                    "_reset_between_tests changed before LibrarianLayer "
903
 
                    "was actually used.")
904
889
        cls.librarian_fixture = LibrarianServerFixture(
905
890
            BaseLayer.config_fixture)
906
891
        cls.librarian_fixture.setUp()
923
908
        finally:
924
909
            librarian = cls.librarian_fixture
925
910
            cls.librarian_fixture = None
926
 
            try:
927
 
                if not cls._reset_between_tests:
928
 
                    raise LayerInvariantError(
929
 
                        "_reset_between_tests not reset before "
930
 
                        "LibrarianLayer shutdown")
931
 
            finally:
932
 
                librarian.cleanUp()
 
911
            librarian.cleanUp()
933
912
 
934
913
    @classmethod
935
914
    @profiled
947
926
                    "LibrarianLayer.reveal() where possible, and ensure "
948
927
                    "the Librarian is restarted if it absolutely must be "
949
928
                    "shutdown: " + str(e))
950
 
        if cls._reset_between_tests:
951
 
            cls.librarian_fixture.clear()
 
929
        cls.librarian_fixture.clear()
952
930
 
953
931
    @classmethod
954
932
    @profiled
1652
1630
 
1653
1631
    @classmethod
1654
1632
    @profiled
1655
 
    def resetBetweenTests(cls, flag):
1656
 
        LibrarianLayer._reset_between_tests = flag
1657
 
        DatabaseLayer._reset_between_tests = flag
1658
 
        MemcachedLayer._reset_between_tests = flag
1659
 
 
1660
 
    @classmethod
1661
 
    @profiled
1662
1633
    def setUp(cls):
1663
1634
        if os.environ.get('PROFILE_PAGETESTS_REQUESTS'):
1664
1635
            PageTestLayer.profiler = Profile()
1688
1659
        PageTestLayer.orig__call__ = (
1689
1660
                zope.app.testing.functional.HTTPCaller.__call__)
1690
1661
        zope.app.testing.functional.HTTPCaller.__call__ = my__call__
1691
 
        PageTestLayer.resetBetweenTests(True)
1692
1662
 
1693
1663
    @classmethod
1694
1664
    @profiled
1695
1665
    def tearDown(cls):
1696
 
        PageTestLayer.resetBetweenTests(True)
1697
1666
        zope.app.testing.functional.HTTPCaller.__call__ = (
1698
1667
                PageTestLayer.orig__call__)
1699
1668
        if PageTestLayer.profiler:
1702
1671
 
1703
1672
    @classmethod
1704
1673
    @profiled
1705
 
    def startStory(cls):
1706
 
        MemcachedLayer.testSetUp()
1707
 
        DatabaseLayer.testSetUp()
1708
 
        LibrarianLayer.testSetUp()
 
1674
    def testSetUp(cls):
1709
1675
        LaunchpadLayer.resetSessionDb()
1710
 
        PageTestLayer.resetBetweenTests(False)
1711
 
 
1712
 
    @classmethod
1713
 
    @profiled
1714
 
    def endStory(cls):
1715
 
        PageTestLayer.resetBetweenTests(True)
1716
 
        LibrarianLayer.testTearDown()
1717
 
        DatabaseLayer.testTearDown()
1718
 
        MemcachedLayer.testTearDown()
1719
 
 
1720
 
    @classmethod
1721
 
    @profiled
1722
 
    def testSetUp(cls):
1723
 
        pass
1724
1676
 
1725
1677
    @classmethod
1726
1678
    @profiled