Esempio n. 1
0
 def __iter__(self):
     try:
         # Reset the session.
         LaunchpadLayer.resetSessionDb()
         # Yield control to asyncore for a second, just to be a
         # little bit nice.  We could be even nicer by moving this
         # whole teardown/setup dance to a thread and waiting for
         # it to be done, but there's not a (known) compelling need
         # for that right now, and doing it this way is slightly
         # simpler.
         yield ''
         DatabaseLayer.testSetUp()
         yield ''
         # Reset the librarian.
         LibrarianLayer.testTearDown()
         yield ''
         # Reset the database.
         DatabaseLayer.testTearDown()
         yield ''
         LibrarianLayer.testSetUp()
     except (SystemExit, KeyboardInterrupt):
         raise
     except:
         print "Hm, serious error when trying to clean up the test."
         traceback.print_exc()
     # We're done, so we can yield the body.
     yield '\n'
Esempio n. 2
0
    def testHideLibrarian(self):
        # First perform a successful upload:
        client = LibrarianClient()
        data = 'foo'
        client.remoteAddFile('foo', len(data), StringIO(data), 'text/plain')
        # The database was committed to, but not by this process, so we need
        # to ensure that it is fully torn down and recreated.
        DatabaseLayer.force_dirty_database()

        # Hide the librarian, and show that the upload fails:
        LibrarianLayer.hide()
        self.assertRaises(UploadFailed, client.remoteAddFile, 'foo', len(data),
                          StringIO(data), 'text/plain')

        # Reveal the librarian again, allowing uploads:
        LibrarianLayer.reveal()
        client.remoteAddFile('foo', len(data), StringIO(data), 'text/plain')
Esempio n. 3
0
 def test_librarian_is_reset(self):
     # Add a file. We use remoteAddFile because it does not need the CA
     # loaded to work.
     client = LibrarianClient()
     LibrarianTestCase.url = client.remoteAddFile(
         self.sample_data, len(self.sample_data),
         StringIO(self.sample_data), 'text/plain')
     self.failUnlessEqual(
         urlopen(LibrarianTestCase.url).read(), self.sample_data)
     # Perform the librarian specific between-test code:
     LibrarianLayer.testTearDown()
     LibrarianLayer.testSetUp()
     # Which should have nuked the old file.
     # XXX: StuartBishop 2006-06-30 Bug=51370:
     # We should get a DownloadFailed exception here.
     data = urlopen(LibrarianTestCase.url).read()
     self.failIfEqual(data, self.sample_data)
Esempio n. 4
0
 def setup():
     # This code needs to be run after other zcml setup happens in
     # runlaunchpad, so it is passed in as a callable.  We set up layers
     # here because we need to control fixtures within this process, and
     # because we want interactive tests to be as similar as possible to
     # tests run in the testrunner.
     # Note that this changes the config instance-name, with the result
     # that the configuration of utilities may become invalidated.
     # XXX Robert Collins, bug=883980: In short, we should derive the
     # other services from the test runner, rather than duplicating
     # the work of test setup within the slave appserver. That will
     # permit reuse of the librarian, DB, rabbit etc, and
     # correspondingly easier assertions and inspection of interactions
     # with other services. That would mean we do not need to set up rabbit
     # or the librarian here: the test runner would control and take care
     # of that.
     BaseLayer.setUp()
     teardowns.append(BaseLayer.tearDown)
     RabbitMQLayer.setUp()
     teardowns.append(RabbitMQLayer.tearDown)
     # We set up the database here even for the test suite because we want
     # to be able to control the database here in the subprocess.  It is
     # possible to do that when setting the database up in the parent
     # process, but it is messier.  This is simple.
     installFakeConnect()
     teardowns.append(uninstallFakeConnect)
     DatabaseLayer.setUp()
     teardowns.append(DatabaseLayer.tearDown)
     # The Librarian needs access to the database, so setting it up here
     # where we are setting up the database makes the most sense.
     LibrarianLayer.setUp()
     teardowns.append(LibrarianLayer.tearDown)
     # Switch to the appserver config.
     fixture = ConfigUseFixture(BaseLayer.appserver_config_name)
     fixture.setUp()
     teardowns.append(fixture.cleanUp)
     # Interactive tests always need this.  We let functional tests use
     # a local one too because of simplicity.
     LayerProcessController.startSMTPServer()
     teardowns.append(LayerProcessController.stopSMTPServer)
     if interactive_tests:
         root_url = config.appserver_root_url()
         print '*' * 70
         print 'In a few seconds, go to ' + root_url + '/+yuitest'
         print '*' * 70
    def testHideLibrarian(self):
        # First perform a successful upload:
        client = LibrarianClient()
        data = 'foo'
        client.remoteAddFile(
            'foo', len(data), StringIO(data), 'text/plain')
        # The database was committed to, but not by this process, so we need
        # to ensure that it is fully torn down and recreated.
        DatabaseLayer.force_dirty_database()

        # Hide the librarian, and show that the upload fails:
        LibrarianLayer.hide()
        self.assertRaises(UploadFailed, client.remoteAddFile,
                          'foo', len(data), StringIO(data), 'text/plain')

        # Reveal the librarian again, allowing uploads:
        LibrarianLayer.reveal()
        client.remoteAddFile(
            'foo', len(data), StringIO(data), 'text/plain')
 def test_librarian_is_reset(self):
     # Add a file. We use remoteAddFile because it does not need the CA
     # loaded to work.
     client = LibrarianClient()
     LibrarianTestCase.url = client.remoteAddFile(
             self.sample_data, len(self.sample_data),
             StringIO(self.sample_data), 'text/plain'
             )
     self.failUnlessEqual(
             urlopen(LibrarianTestCase.url).read(), self.sample_data
             )
     # Perform the librarian specific between-test code:
     LibrarianLayer.testTearDown()
     LibrarianLayer.testSetUp()
     # Which should have nuked the old file.
     # XXX: StuartBishop 2006-06-30 Bug=51370:
     # We should get a DownloadFailed exception here.
     data = urlopen(LibrarianTestCase.url).read()
     self.failIfEqual(data, self.sample_data)