예제 #1
0
    def test_safety_net(self):
        ''' Verify run_queue() safety net works '''

        #
        # The whole point of this test is to make sure
        # that and error is printed and "testdone" is
        # published when a new test is started and the
        # test name is bad.
        #

        # We need to ensure logging.error() is invoked
        log_error = [0]

        def on_log_error(message, *args):
            ''' Register logging.error() invokation '''
            # pylint: disable=W0613
            log_error[0] += 1

        # Setup (we will restore that later)
        saved_log_error = logging.error
        logging.error = on_log_error

        CONFIG.conf['privacy.can_publish'] = 1
        CONFIG.conf['privacy.informed'] = 1
        CONFIG.conf['privacy.can_collect'] = 1
        core = RunnerCore()
        core.queue.append(('foo', Deferred(), None))
        core.run_queue()

        # Restore
        logging.error = saved_log_error

        # Worked as expected?
        self.assertTrue(log_error[0])
        self.assertFalse(NOTIFIER.is_subscribed("testdone"))
예제 #2
0
    def test_wrong_privacy(self):
        ''' Verify run_queue() behavior when privacy is wrong '''

        #
        # The whole point of this test is to make sure
        # that privacy.complain() is invoked and "testdone"
        # is published when privacy settings are not OK
        # and a test is started.
        #

        # We need to ensure privacy.complain() is invoked
        privacy_complain = [0]

        def on_privacy_complain():
            ''' Register privacy.complain() invokation '''
            privacy_complain[0] += 1

        # Setup (we will restore that later)
        saved_complain = privacy.complain
        privacy.complain = on_privacy_complain

        CONFIG.conf['privacy.informed'] = 0
        core = RunnerCore()
        core.queue.append(('foo', Deferred(), None))
        core.run_queue()

        # Restore
        privacy.complain = saved_complain

        # Worked as expected?
        self.assertTrue(privacy_complain[0])
        self.assertFalse(NOTIFIER.is_subscribed("testdone"))
예제 #3
0
    def test_wrong_privacy(self):
        ''' Verify run_queue() behavior when privacy is wrong '''

        #
        # The whole point of this test is to make sure
        # that privacy.complain() is invoked and "testdone"
        # is published when privacy settings are not OK
        # and a test is started.
        #

        # We need to ensure privacy.complain() is invoked
        privacy_complain = [0]
        def on_privacy_complain():
            ''' Register privacy.complain() invokation '''
            privacy_complain[0] += 1

        # Setup (we will restore that later)
        saved_complain = privacy.complain
        privacy.complain = on_privacy_complain

        CONFIG.conf['privacy.informed'] = 0
        core = RunnerCore()
        core.queue.append(('foo', '/', lambda: None))
        core.run_queue()

        # Restore
        privacy.complain = saved_complain

        # Worked as expected?
        self.assertTrue(privacy_complain[0])
        self.assertFalse(NOTIFIER.is_subscribed("testdone"))
예제 #4
0
    def test_safety_net(self):
        ''' Verify run_queue() safety net works '''

        #
        # The whole point of this test is to make sure
        # that and error is printed and "testdone" is
        # published when a new test is started and the
        # test name is bad.
        #

        # We need to ensure LOG.error() is invoked
        log_error = [0]
        def on_log_error(message, *args):
            ''' Register LOG.error() invokation '''
            # pylint: disable=W0613
            log_error[0] += 1

        # Setup (we will restore that later)
        saved_log_error = LOG.error
        LOG.error = on_log_error

        CONFIG.conf['privacy.can_publish'] = 1
        CONFIG.conf['privacy.informed'] = 1
        CONFIG.conf['privacy.can_collect'] = 1
        core = RunnerCore()
        core.queue.append(('foo', '/', lambda: None))
        core.run_queue()

        # Restore
        LOG.error = saved_log_error

        # Worked as expected?
        self.assertTrue(log_error[0])
        self.assertFalse(NOTIFIER.is_subscribed("testdone"))
예제 #5
0
    def test_bittorrent_invokation_bad(self):
        ''' Verify run_queue() behavior when bittorrent is invoked
            and there is NOT a URI for bittorrent '''

        #
        # The whole point of this test is to make sure that
        # the callback() is invoked and the "testdone" event
        # has been fired, when we try to run a bittorrent
        # test and we don't have a registered URI for such
        # test.
        #

        # We need to ensure callback() is invoked
        callback = [0]
        def on_callback():
            ''' Register callback() invokation '''
            # pylint: disable=W0613
            callback[0] += 1

        CONFIG.conf['privacy.can_publish'] = 1
        CONFIG.conf['privacy.informed'] = 1
        CONFIG.conf['privacy.can_collect'] = 1
        core = RunnerCore()
        core.queue.append(('bittorrent', on_callback, None))
        core.run_queue()

        # Worked as expected?
        self.assertTrue(callback[0])
        self.assertFalse(NOTIFIER.is_subscribed("testdone"))
예제 #6
0
 def test_smpl(self):
     ''' Check behavior is correct when empty '''
     #
     # The most basic test, just make sure that at the
     # beginning the state is consistent and that running
     # the empty queue does not have side effects.
     #
     core = RunnerCore()
     self.assertEqual(core.test_is_running(), False)
     core.run_queue()
예제 #7
0
 def test_smpl(self):
     ''' Check behavior is correct when empty '''
     #
     # The most basic test, just make sure that at the
     # beginning the state is consistent and that running
     # the empty queue does not have side effects.
     #
     core = RunnerCore()
     self.assertEqual(core.test_is_running(), False)
     core.run_queue()
예제 #8
0
 def test_when_queue_empty(self):
     ''' Verify run_queue() behavior when queue is empty '''
     #
     # It should not run when the queue is empty,
     # if I'm wrong and it runs and it does not
     # crash (unlikely), the self.running attribute
     # would be true.
     #
     core = RunnerCore()
     core.run_queue()
     self.assertFalse(core.running)
예제 #9
0
 def test_when_queue_empty(self):
     ''' Verify run_queue() behavior when queue is empty '''
     #
     # It should not run when the queue is empty,
     # if I'm wrong and it runs and it does not
     # crash (unlikely), the self.running attribute
     # would be true.
     #
     core = RunnerCore()
     core.run_queue()
     self.assertFalse(core.running)
예제 #10
0
    def test_bittorrent_invokation_good(self):
        ''' Verify run_queue() behavior when bittorrent is invoked
            and there is a URI for bittorrent '''

        #
        # The whole point of this test is to make sure that
        # bittorrent.run() is invoked when privacy is OK and
        # we have a negotiate URI.  We also want to check that
        # the "testdone" event is subscribed after run_queue(),
        # i.e. that someone is waiting for the event that
        # signals the end of the test.
        #

        # We need to ensure bittorrent.run() is invoked
        bittorrent_run = [0]

        def on_bittorrent_run(poller, conf):
            ''' Register bittorrent.run() invokation '''
            # pylint: disable=W0613
            bittorrent_run[0] += 1

        # Setup (we will restore that later)
        saved_run = bittorrent.run
        bittorrent.run = on_bittorrent_run
        RUNNER_TESTS.update({'bittorrent': '/'})

        CONFIG.conf['privacy.can_publish'] = 1
        CONFIG.conf['privacy.informed'] = 1
        CONFIG.conf['privacy.can_collect'] = 1
        core = RunnerCore()
        core.queue.append(('bittorrent', Deferred(), None))
        core.run_queue()

        # Restore
        bittorrent.run = saved_run
        RUNNER_TESTS.update({})

        # Worked as expected?
        self.assertTrue(bittorrent_run[0])
        self.assertTrue(NOTIFIER.is_subscribed("testdone"))

        #
        # Clear the "testdone" because otherwise it will
        # screw up other tests and we don't want that
        #
        NOTIFIER.publish("testdone")
예제 #11
0
    def test_bittorrent_invokation_good(self):
        ''' Verify run_queue() behavior when bittorrent is invoked
            and there is a URI for bittorrent '''

        #
        # The whole point of this test is to make sure that
        # bittorrent.run() is invoked when privacy is OK and
        # we have a negotiate URI.  We also want to check that
        # the "testdone" event is subscribed after run_queue(),
        # i.e. that someone is waiting for the event that
        # signals the end of the test.
        #

        # We need to ensure bittorrent.run() is invoked
        bittorrent_run = [0]
        def on_bittorrent_run(poller, conf):
            ''' Register bittorrent.run() invokation '''
            # pylint: disable=W0613
            bittorrent_run[0] += 1

        # Setup (we will restore that later)
        saved_run = bittorrent.run
        bittorrent.run = on_bittorrent_run
        RUNNER_TESTS.update({'bittorrent': '/'})

        CONFIG.conf['privacy.can_publish'] = 1
        CONFIG.conf['privacy.informed'] = 1
        CONFIG.conf['privacy.can_collect'] = 1
        core = RunnerCore()
        core.queue.append(('bittorrent', Deferred(), None))
        core.run_queue()

        # Restore
        bittorrent.run = saved_run
        RUNNER_TESTS.update({})

        # Worked as expected?
        self.assertTrue(bittorrent_run[0])
        self.assertTrue(NOTIFIER.is_subscribed("testdone"))

        #
        # Clear the "testdone" because otherwise it will
        # screw up other tests and we don't want that
        #
        NOTIFIER.publish("testdone")