Ejemplo n.º 1
0
def test_test_run(cli_runner):
    with cli_runner.isolated_filesystem():
        with open('junit_report.xml', 'w') as handler:
            handler.write(JUNIT_XML)
        with mock.patch.multiple(
                'betelgeuse',
                TestRun=mock.DEFAULT,
                multiprocessing=mock.DEFAULT,
                testimony=mock.DEFAULT
        ) as patches:
            pool = mock.MagicMock()
            patches['multiprocessing'].Pool.return_value = pool

            result = cli_runner.invoke(
                cli,
                ['test-run', '--path', 'junit_report.xml', 'PROJECT']
            )
            assert result.exit_code == 0
            patches['TestRun'].session.tx_begin.assert_called_once_with()
            patches['TestRun'].session.tx_commit.assert_called_once_with()
            pool.map.assert_called_once_with(
                betelgeuse.add_test_record,
                parse_junit('junit_report.xml')
            )
            pool.close.assert_called_once_with()
            pool.join.assert_called_once_with()
Ejemplo n.º 2
0
def test_test_run_new_test_run(cli_runner):
    """Check if test run command works for a new test run."""
    with cli_runner.isolated_filesystem():
        with open("junit_report.xml", "w") as handler:
            handler.write(JUNIT_XML)
        with mock.patch.multiple(
            "betelgeuse", TestRun=mock.DEFAULT, multiprocessing=mock.DEFAULT, testimony=mock.DEFAULT
        ) as patches:
            pool = mock.MagicMock()
            patches["multiprocessing"].Pool.return_value = pool
            patches["TestRun"].side_effect = PylarionLibException

            result = cli_runner.invoke(
                cli,
                [
                    "test-run",
                    "--path",
                    "junit_report.xml",
                    "--test-run-id",
                    "testrunid",
                    "--custom-fields",
                    '{"arch": "x86_64", "isautomated": true}',
                    "PROJECT",
                ],
            )
            assert result.exit_code == 0
            patches["TestRun"].create.assert_called_once_with(
                "PROJECT", "testrunid", "Empty", arch="x86_64", isautomated=True, type="buildacceptance"
            )
            patches["TestRun"].session.tx_begin.assert_called_once_with()
            patches["TestRun"].session.tx_commit.assert_called_once_with()
            pool.map.assert_called_once_with(betelgeuse.add_test_record, parse_junit("junit_report.xml"))
            pool.close.assert_called_once_with()
            pool.join.assert_called_once_with()
Ejemplo n.º 3
0
def test_test_run_new_test_run(cli_runner):
    """Check if test run command works for a new test run."""
    with cli_runner.isolated_filesystem():
        with open('junit_report.xml', 'w') as handler:
            handler.write(JUNIT_XML)
        with mock.patch.multiple('betelgeuse',
                                 TestRun=mock.DEFAULT,
                                 multiprocessing=mock.DEFAULT,
                                 testimony=mock.DEFAULT) as patches:
            pool = mock.MagicMock()
            patches['multiprocessing'].Pool.return_value = pool
            patches['TestRun'].side_effect = PylarionLibException

            result = cli_runner.invoke(cli, [
                'test-run', '--path', 'junit_report.xml', '--test-run-id',
                'testrunid', '--custom-fields',
                '{"arch": "x86_64", "isautomated": true}', 'PROJECT'
            ])
            assert result.exit_code == 0
            patches['TestRun'].create.assert_called_once_with(
                'PROJECT',
                'testrunid',
                'Empty',
                arch='x86_64',
                isautomated=True,
                type='buildacceptance',
            )
            patches['TestRun'].session.tx_begin.assert_called_once_with()
            patches['TestRun'].session.tx_commit.assert_called_once_with()
            pool.map.assert_called_once_with(betelgeuse.add_test_record,
                                             parse_junit('junit_report.xml'))
            pool.close.assert_called_once_with()
            pool.join.assert_called_once_with()
Ejemplo n.º 4
0
def test_parse_junit():
    """Check if jUnit parsing works."""
    junit_xml = StringIO(JUNIT_XML)
    assert parse_junit(junit_xml) == [{
        'classname': 'foo1',
        'name': 'test_passed',
        'status': 'passed',
        'line': '8',
        'file': 'source.py'
    }, {
        'classname': 'foo2',
        'message': 'Skipped message',
        'name': 'test_skipped',
        'status': 'skipped'
    }, {
        'classname': 'foo3',
        'name': 'test_failure',
        'message': 'Failure message',
        'status': 'failure',
        'type': 'Type'
    }, {
        'classname': 'foo4',
        'name': 'test_error',
        'message': 'Error message',
        'status': 'error',
        'type': 'ExceptionName'
    }]
    junit_xml.close()
Ejemplo n.º 5
0
def test_parse_junit():
    junit_xml = StringIO(JUNIT_XML)
    assert parse_junit(junit_xml) == [
        {'classname': 'foo1', 'name': 'test_passed', 'status': 'passed'},
        {'classname': 'foo2', 'message': 'Skipped message',
         'name': 'test_skipped', 'status': 'skipped'},
        {'classname': 'foo3', 'name': 'test_failure',
         'message': 'Failure message', 'status': 'failure', 'type': 'Type'},
        {'classname': 'foo4', 'name': 'test_error', 'message': 'Error message',
         'status': 'error', 'type': 'ExceptionName'}
    ]
    junit_xml.close()
Ejemplo n.º 6
0
def test_test_run_new_test_run(cli_runner):
    """Check if test run command works for a new test run."""
    with cli_runner.isolated_filesystem():
        with open('junit_report.xml', 'w') as handler:
            handler.write(JUNIT_XML)
        with mock.patch.multiple(
                'betelgeuse',
                TestRun=mock.DEFAULT,
                multiprocessing=mock.DEFAULT,
                testimony=mock.DEFAULT
        ) as patches:
            pool = mock.MagicMock()
            patches['multiprocessing'].Pool.return_value = pool
            patches['TestRun'].side_effect = PylarionLibException

            result = cli_runner.invoke(
                cli,
                [
                    'test-run',
                    '--path',
                    'junit_report.xml',
                    '--test-run-id',
                    'testrunid',
                    '--custom-fields',
                    '{"arch": "x86_64", "isautomated": true}',
                    'PROJECT'
                ]
            )
            assert result.exit_code == 0
            patches['TestRun'].create.assert_called_once_with(
                'PROJECT',
                'testrunid',
                'Empty',
                arch='x86_64',
                isautomated=True,
                type='buildacceptance',
            )
            patches['TestRun'].session.tx_begin.assert_called_once_with()
            patches['TestRun'].session.tx_commit.assert_called_once_with()
            pool.map.assert_called_once_with(
                betelgeuse.add_test_record,
                parse_junit('junit_report.xml')
            )
            pool.close.assert_called_once_with()
            pool.join.assert_called_once_with()
Ejemplo n.º 7
0
def test_test_run(cli_runner):
    """Check if test run command works."""
    with cli_runner.isolated_filesystem():
        with open("junit_report.xml", "w") as handler:
            handler.write(JUNIT_XML)
        with mock.patch.multiple(
            "betelgeuse", TestRun=mock.DEFAULT, multiprocessing=mock.DEFAULT, testimony=mock.DEFAULT
        ) as patches:
            pool = mock.MagicMock()
            patches["multiprocessing"].Pool.return_value = pool

            result = cli_runner.invoke(cli, ["test-run", "--path", "junit_report.xml", "PROJECT"])
            assert result.exit_code == 0
            patches["TestRun"].session.tx_begin.assert_called_once_with()
            patches["TestRun"].session.tx_commit.assert_called_once_with()
            pool.map.assert_called_once_with(betelgeuse.add_test_record, parse_junit("junit_report.xml"))
            pool.close.assert_called_once_with()
            pool.join.assert_called_once_with()
Ejemplo n.º 8
0
def test_test_run(cli_runner):
    """Check if test run command works."""
    with cli_runner.isolated_filesystem():
        with open('junit_report.xml', 'w') as handler:
            handler.write(JUNIT_XML)
        with mock.patch.multiple('betelgeuse',
                                 TestRun=mock.DEFAULT,
                                 multiprocessing=mock.DEFAULT,
                                 testimony=mock.DEFAULT) as patches:
            pool = mock.MagicMock()
            patches['multiprocessing'].Pool.return_value = pool

            result = cli_runner.invoke(
                cli, ['test-run', '--path', 'junit_report.xml', 'PROJECT'])
            assert result.exit_code == 0
            patches['TestRun'].session.tx_begin.assert_called_once_with()
            patches['TestRun'].session.tx_commit.assert_called_once_with()
            pool.map.assert_called_once_with(betelgeuse.add_test_record,
                                             parse_junit('junit_report.xml'))
            pool.close.assert_called_once_with()
            pool.join.assert_called_once_with()
Ejemplo n.º 9
0
def test_parse_junit():
    """Check if jUnit parsing works."""
    junit_xml = StringIO(JUNIT_XML)
    assert parse_junit(junit_xml) == [
        {"classname": "foo1", "name": "test_passed", "status": "passed", "line": "8", "file": "source.py"},
        {"classname": "foo2", "message": "Skipped message", "name": "test_skipped", "status": "skipped"},
        {
            "classname": "foo3",
            "name": "test_failure",
            "message": "Failure message",
            "status": "failure",
            "type": "Type",
        },
        {
            "classname": "foo4",
            "name": "test_error",
            "message": "Error message",
            "status": "error",
            "type": "ExceptionName",
        },
    ]
    junit_xml.close()