Example #1
0
    def test_simple_case(self):
        ''' Make sure that we start the test in the simplest case '''

        #
        # In this case we want to make sure that if we pass a known
        # test name and we don't request for streaming:
        #
        # 1. RUNNER_CORE.run() is invoked;
        #
        # 2. the HTTP response is OK.
        #

        #
        # We need to override the run() function of RUNNER_CORE
        # because we just want to test that it was invoked using
        # the right parameters, not to invoke it.
        #
        run_invoked = [0]

        def on_run_invoked(test, callback, auto_discover, ctx):
            ''' Convenience function to notify that run was invoked '''
            # pylint: disable=W0613
            run_invoked[0] += 1

        # Prerequisites (we will restore original funcs later)
        RUNNER_TESTS.avail = {'bittorrent': 'foo'}
        saved_run = RUNNER_CORE.run
        RUNNER_CORE.run = on_run_invoked

        # Invoke runner_api() for an known test
        stream = RegressionTestStream()
        runner_api(stream, None, 'test=bittorrent')

        # Undo prerequisites
        RUNNER_CORE.run = saved_run
        RUNNER_TESTS.avail = {}

        #
        # We must make sure that run() was invoked and that
        # the response contains precisely what we expect.
        #

        # Make sure that run() was invoked
        self.assertTrue(run_invoked[0])

        # Check response
        self.assertEqual(stream.response.code, '200')
        self.assertEqual(stream.response.reason, 'Ok')
        self.assertEqual(stream.response['content-type'], 'application/json')
        self.assertEqual(stream.response['content-length'], '2')
        self.assertEqual(stream.response.body, '{}')
Example #2
0
    def test_simple_case(self):
        ''' Make sure that we start the test in the simplest case '''

        #
        # In this case we want to make sure that if we pass a known
        # test name and we don't request for streaming:
        #
        # 1. runner_core.run() is invoked;
        #
        # 2. the HTTP response is OK.
        #

        #
        # We need to override the run() function of runner_core
        # because we just want to test that it was invoked using
        # the right parameters, not to invoke it.
        #
        run_invoked = [0]
        def on_run_invoked(test, uri, callback):
            ''' Convenience function to notify that run was invoked '''
            # pylint: disable=W0613
            run_invoked[0] += 1

        # Prerequisites (we will restore original funcs later)
        RUNNER_LST.avail = {'bittorrent': 'foo'}
        saved_run = runner_core.run
        runner_core.run = on_run_invoked

        # Invoke runner_api() for an known test
        stream = RegressionTestStream()
        runner_api(stream, None, 'test=bittorrent')

        # Undo prerequisites
        runner_core.run = saved_run
        RUNNER_LST.avail = {}

        #
        # We must make sure that run() was invoked and that
        # the response contains precisely what we expect.
        #

        # Make sure that run() was invoked
        self.assertTrue(run_invoked[0])

        # Check response
        self.assertEqual(stream.response.code, '200')
        self.assertEqual(stream.response.reason, 'Ok')
        self.assertEqual(stream.response['content-type'], 'application/json')
        self.assertEqual(stream.response['content-length'], '2')
        self.assertEqual(stream.response.body, '{}')
Example #3
0
    def test_no_query(self):
        ''' Make sure we return an empty response when there is no query '''

        #
        # Basically invoke the API without a query and make
        # sure that common response fields are as expected
        #

        stream = RegressionTestStream()
        runner_api(stream, None, '')

        self.assertEqual(stream.response.code, '200')
        self.assertEqual(stream.response.reason, 'Ok')
        self.assertEqual(stream.response['content-type'], 'application/json')
        self.assertEqual(stream.response['content-length'], '2')
        self.assertEqual(stream.response.body, '{}')
Example #4
0
    def test_no_query(self):
        ''' Make sure we return an empty response when there is no query '''

        #
        # Basically invoke the API without a query and make
        # sure that common response fields are as expected
        #

        stream = RegressionTestStream()
        runner_api(stream, None, '')

        self.assertEqual(stream.response.code, '200')
        self.assertEqual(stream.response.reason, 'Ok')
        self.assertEqual(stream.response['content-type'],
                         'application/json')
        self.assertEqual(stream.response['content-length'], '2')
        self.assertEqual(stream.response.body, '{}')
Example #5
0
    def test_streaming_case(self):
        ''' Make sure streaming case works as expected '''

        #
        # In this case we want to make sure that if we pass a known
        # test name and we request for streaming:
        #
        # 1. runner_core.run() is invoked;
        #
        # 2. the HTTP response is OK;
        #
        # 3. LOG.start_streaming() is invoked.
        #

        #
        # We need to override the run() function of runner_core
        # and start_streaming of LOG because we just want to
        # test that they were invoked using the right parameters,
        # not to invoke them.
        #
        start_streaming_invoked = [0]
        def on_start_streaming_invoked(stream):
            ''' Convenience function to notify that start_streaming
                was invoked '''
            # pylint: disable=W0613
            start_streaming_invoked[0] += 1

        run_invoked = [0]
        def on_run_invoked(test, uri, callback):
            ''' Convenience function to notify that run was invoked '''
            # pylint: disable=W0613
            run_invoked[0] += 1

        # Prerequisites (we will restore everything later)
        RUNNER_LST.avail = {'bittorrent': 'foo'}
        saved_run = runner_core.run
        saved_start_streaming = LOG.start_streaming
        runner_core.run = on_run_invoked
        LOG.start_streaming = on_start_streaming_invoked

        # Invoke runner_api()
        stream = RegressionTestStream()
        runner_api(stream, None, 'test=bittorrent&streaming=1')

        # Undo prerequisites
        runner_core.run = saved_run
        RUNNER_LST.avail = {}
        LOG.start_streaming = saved_start_streaming

        #
        # We must make sure that run() was invoked, that LOG's
        # start_streaming was invoked and that the response
        # contains precisely what we expect.
        #

        # Make sure that start_streaming() was invoked
        self.assertTrue(start_streaming_invoked[0])

        # Make sure that run() was invoked
        self.assertTrue(run_invoked[0])

        # Check response
        self.assertEqual(stream.response.code, '200')
        self.assertEqual(stream.response.reason, 'Ok')
        self.assertEqual(stream.response['content-type'], 'text/plain')
        self.assertEqual(stream.response['content-length'], '')
        self.assertEqual(stream.response.body.tell(), 0)
Example #6
0
    def test_streaming_case(self):
        ''' Make sure streaming case works as expected '''

        #
        # In this case we want to make sure that if we pass a known
        # test name and we request for streaming:
        #
        # 1. RUNNER_CORE.run() is invoked;
        #
        # 2. the HTTP response is OK;
        #
        # 3. STREAMING_LOG.start_streaming() is invoked.
        #

        #
        # We need to override the run() function of RUNNER_CORE
        # and start_streaming of STREAMING_LOG because we just want to
        # test that they were invoked using the right parameters,
        # not to invoke them.
        #
        start_streaming_invoked = [0]

        def on_start_streaming_invoked(stream):
            ''' Convenience function to notify that start_streaming
                was invoked '''
            # pylint: disable=W0613
            start_streaming_invoked[0] += 1

        run_invoked = [0]

        def on_run_invoked(test, callback, auto_discover, ctx):
            ''' Convenience function to notify that run was invoked '''
            # pylint: disable=W0613
            run_invoked[0] += 1

        # Prerequisites (we will restore everything later)
        RUNNER_TESTS.avail = {'bittorrent': 'foo'}
        saved_run = RUNNER_CORE.run
        saved_start_streaming = STREAMING_LOG.start_streaming
        RUNNER_CORE.run = on_run_invoked
        STREAMING_LOG.start_streaming = on_start_streaming_invoked

        # Invoke runner_api()
        stream = RegressionTestStream()
        runner_api(stream, None, 'test=bittorrent&streaming=1')

        # Undo prerequisites
        RUNNER_CORE.run = saved_run
        RUNNER_TESTS.avail = {}
        STREAMING_LOG.start_streaming = saved_start_streaming

        #
        # We must make sure that run() was invoked, that STREAMING_LOG's
        # start_streaming was invoked and that the response
        # contains precisely what we expect.
        #

        # Make sure that start_streaming() was invoked
        self.assertTrue(start_streaming_invoked[0])

        # Make sure that run() was invoked
        self.assertTrue(run_invoked[0])

        # Check response
        self.assertEqual(stream.response.code, '200')
        self.assertEqual(stream.response.reason, 'Ok')
        self.assertEqual(stream.response['content-type'], 'text/plain')
        self.assertEqual(stream.response['content-length'], '')
        self.assertEqual(stream.response.body.tell(), 0)