Exemplo n.º 1
0
    def test_file_is_written(self):
        tmpdir = tempfile.mkdtemp()
        try:
            output = FileOutput(mock.sentinel.test_result,
                                {'output_file_filename': '%s/loads' % tmpdir})
            output.push('something', 1, 2, method='GET')
            output.flush()

            with open('%s/loads' % tmpdir) as f:
                self.assertEquals('something - {"method": "GET"}', f.read())

        finally:
            shutil.rmtree(tmpdir)
Exemplo n.º 2
0
    def test_file_is_written(self):

        # Create a fake test result object
        test_result = FakeTestResult()

        tmpdir = tempfile.mkdtemp()
        try:
            output = FunkloadOutput(
                test_result,
                {'output_funkload_filename': '%s/funkload.xml' % tmpdir,
                 'fqn': 'my_test_module.MyTestCase.test_mytest',
                 'hits': 200, 'users': [1, 2, 5], 'duration': '1'})

            # Drive the observer with some tests and hits
            output.push('startTestRun', when=TIME1)

            test_case, state = FakeTestCase('test_mytest_foo'), [1, 2, 3, 4]
            output.push('startTest', test_case, state)
            output.push('add_hit', state, started=TIME1, elapsed=_1,
                        url='http://example.local/foo', method='GET',
                        status=200)
            output.push('addSuccess', test_case, state)
            output.push('stopTest', test_case, state)

            test_case, state = FakeTestCase('test_mytest_bar'), [1, 2, 3, 4]
            output.push('startTest', test_case, state)
            output.push('add_hit', state, started=TIME1, elapsed=_1,
                        url='http://example.local/bar', method='GET',
                        status=500)
            output.push(
                'addFailure', test_case, (
                    Exception, Exception('Mock Exception'),
                    ['mock', 'traceback']),
                state)
            output.push('stopTest', test_case, [1, 2, 3, 4])

            output.flush()

            with open('%s/funkload.xml' % tmpdir) as f:
                content = f.read()
                test = (
                    '<response\n    cycle="001" cvus="002" thread="004" '
                    'suite="" name=""\n    step="001" number="001" '
                    'type="get" result="Successful" '
                    'url="http://example.local/foo"\n    code="200" '
                    'description="" time="1368492668" duration="1.0" />',)
                for t in test:
                    self.assertIn(t, content)

                test = (
                    '<testResult\n    cycle="001" cvus="002" thread="004" '
                    'suite="FakeTestCase"\n    name="test_mytest_foo" ',
                    'result="Successful" steps="1"\n',
                    'connection_duration="0" requests="1"\n    pages="1" '
                    'xmlrpc="0" redirects="0" images="0" links="0"\n    />')
                for t in test:
                    self.assertIn(t, content)

                test = (
                    '<response\n    cycle="001" cvus="002" thread="004" '
                    'suite="" name=""\n    step="001" number="001" '
                    'type="get" result="Successful" '
                    'url="http://example.local/bar"\n    code="500" '
                    'description="" time="1368492668" duration="1.0" />',)
                for t in test:
                    self.assertIn(t, content)

                test = (
                    '<testResult\n    cycle="001" cvus="002" thread="004" '
                    'suite="FakeTestCase"\n    name="test_mytest_foo" ',
                    'result="Failure" steps="1"\n',
                    'connection_duration="0" requests="1"\n    pages="1" '
                    'xmlrpc="0" redirects="0" images="0" links="0"\n'
                    '    traceback="mock&#10;traceback"/>')
                for t in test:
                    self.assertIn(t, content)

        finally:
            shutil.rmtree(tmpdir)
Exemplo n.º 3
0
 def test_api_works(self):
     output = NullOutput(mock.sentinel.test_result, mock.sentinel.args)
     output.push('something')
     output.flush()