Exemplo n.º 1
0
def test_add_test_record():
    test_run = mock.MagicMock()
    obj_cache = {
        'test_run': test_run,
        'user': '******',
    }
    with mock.patch.dict('betelgeuse.OBJ_CACHE', obj_cache):
        with mock.patch.multiple(
                'betelgeuse',
                TestCase=mock.DEFAULT,
                datetime=mock.DEFAULT,
        ) as patches:
            test_case = mock.MagicMock()
            patches['TestCase'].query.return_value = [test_case]
            add_test_record({
                'classname': 'NameTestCase',
                'message': u'Test failed because it not worked',
                'name': 'test_name',
                'status': 'failure',
                'time': '3.1415',
            })
            test_run.add_test_record_by_fields.assert_called_once_with(
                duration=3.1415,
                executed=patches['datetime'].datetime.now(),
                executed_by='testuser',
                test_case_id=test_case.work_item_id,
                test_comment='Test failed because it not worked',
                test_result='failed'
            )
Exemplo n.º 2
0
def test_add_test_record_unexpected_exception():
    """Check if test record creation reraise unexpected exceptions."""
    class UnexpectedException(Exception):
        """Some unexpected exception."""
        pass

    test_run = mock.MagicMock()
    test_run.add_test_record_by_fields.side_effect = UnexpectedException(
        'UnexpectedException')
    obj_cache = {
        'test_run': test_run,
        'user': '******',
        'testcases': {
            'module.NameTestCase.test_name':
            'caffa7b0-fb9e-430b-903f-3f37fa28e0da',
        },
    }
    with mock.patch.dict('betelgeuse.OBJ_CACHE', obj_cache):
        with mock.patch.multiple(
                'betelgeuse',
                TestCase=mock.DEFAULT,
                datetime=mock.DEFAULT,
                testimony=mock.DEFAULT,
        ) as patches:
            test_case = mock.MagicMock()
            patches['TestCase'].query.return_value = [test_case]
            testimony_test_function = mock.MagicMock()
            testimony_test_function.testmodule = 'module.py'
            testimony_test_function.parent_class = 'NameTestCase'
            testimony_test_function.name = 'test_name'
            patches['testimony'].get_testcases.return_value = {
                'module.py': [testimony_test_function],
            }
            with pytest.raises(UnexpectedException) as excinfo:
                add_test_record({
                    'classname': 'module.NameTestCase',
                    'message': u'Test failed because it not worked',
                    'name': 'test_name',
                    'status': 'failure',
                    'time': '3.1415',
                })
            assert excinfo.value.message == 'UnexpectedException'
Exemplo n.º 3
0
def test_add_test_record():
    """Check if test record creation works."""
    test_run = mock.MagicMock()
    obj_cache = {
        'test_run': test_run,
        'user': '******',
        'testcases': {
            'module.NameTestCase.test_name':
            'caffa7b0-fb9e-430b-903f-3f37fa28e0da',
        },
    }
    with mock.patch.dict('betelgeuse.OBJ_CACHE', obj_cache):
        with mock.patch.multiple(
                'betelgeuse',
                TestCase=mock.DEFAULT,
                datetime=mock.DEFAULT,
                testimony=mock.DEFAULT,
        ) as patches:
            test_case = mock.MagicMock()
            patches['TestCase'].query.return_value = [test_case]
            testimony_test_function = mock.MagicMock()
            testimony_test_function.testmodule = 'module.py'
            testimony_test_function.parent_class = 'NameTestCase'
            testimony_test_function.name = 'test_name'
            patches['testimony'].get_testcases.return_value = {
                'module.py': [testimony_test_function],
            }
            add_test_record({
                'classname': 'module.NameTestCase',
                'message': u'Test failed because it not worked',
                'name': 'test_name',
                'status': 'failure',
                'time': '3.1415',
            })
            test_run.add_test_record_by_fields.assert_called_once_with(
                duration=3.1415,
                executed=patches['datetime'].datetime.now(),
                executed_by='testuser',
                test_case_id=test_case.work_item_id,
                test_comment='Test failed because it not worked',
                test_result='failed'
            )
Exemplo n.º 4
0
def test_add_test_record():
    """Check if test record creation works."""
    test_run = mock.MagicMock()
    obj_cache = {
        'test_run': test_run,
        'user': '******',
        'testcases': {
            'module.NameTestCase.test_name':
            'caffa7b0-fb9e-430b-903f-3f37fa28e0da',
        },
    }
    with mock.patch.dict('betelgeuse.OBJ_CACHE', obj_cache):
        with mock.patch.multiple(
                'betelgeuse',
                TestCase=mock.DEFAULT,
                datetime=mock.DEFAULT,
                testimony=mock.DEFAULT,
        ) as patches:
            test_case = mock.MagicMock()
            patches['TestCase'].query.return_value = [test_case]
            testimony_test_function = mock.MagicMock()
            testimony_test_function.testmodule = 'module.py'
            testimony_test_function.parent_class = 'NameTestCase'
            testimony_test_function.name = 'test_name'
            patches['testimony'].get_testcases.return_value = {
                'module.py': [testimony_test_function],
            }
            add_test_record({
                'classname': 'module.NameTestCase',
                'message': u'Test failed because it not worked',
                'name': 'test_name',
                'status': 'failure',
                'time': '3.1415',
            })
            test_run.add_test_record_by_fields.assert_called_once_with(
                duration=3.1415,
                executed=patches['datetime'].datetime.now(),
                executed_by='testuser',
                test_case_id=test_case.work_item_id,
                test_comment='Test failed because it not worked',
                test_result='failed')
Exemplo n.º 5
0
def test_add_test_record_unexpected_exception():
    """Check if test record creation reraise unexpected exceptions."""

    class UnexpectedException(Exception):
        """Some unexpected exception."""

        pass

    test_run = mock.MagicMock()
    test_run.add_test_record_by_fields.side_effect = UnexpectedException("UnexpectedException")
    obj_cache = {
        "test_run": test_run,
        "user": "******",
        "testcases": {"module.NameTestCase.test_name": "caffa7b0-fb9e-430b-903f-3f37fa28e0da"},
    }
    with mock.patch.dict("betelgeuse.OBJ_CACHE", obj_cache):
        with mock.patch.multiple(
            "betelgeuse", TestCase=mock.DEFAULT, datetime=mock.DEFAULT, testimony=mock.DEFAULT
        ) as patches:
            test_case = mock.MagicMock()
            patches["TestCase"].query.return_value = [test_case]
            testimony_test_function = mock.MagicMock()
            testimony_test_function.testmodule = "module.py"
            testimony_test_function.parent_class = "NameTestCase"
            testimony_test_function.name = "test_name"
            patches["testimony"].get_testcases.return_value = {"module.py": [testimony_test_function]}
            with pytest.raises(UnexpectedException) as excinfo:
                add_test_record(
                    {
                        "classname": "module.NameTestCase",
                        "message": u"Test failed because it not worked",
                        "name": "test_name",
                        "status": "failure",
                        "time": "3.1415",
                    }
                )
            assert excinfo.value.message == "UnexpectedException"
Exemplo n.º 6
0
def test_add_test_record():
    """Check if test record creation works."""
    test_run = mock.MagicMock()
    obj_cache = {
        "test_run": test_run,
        "user": "******",
        "testcases": {"module.NameTestCase.test_name": "caffa7b0-fb9e-430b-903f-3f37fa28e0da"},
    }
    with mock.patch.dict("betelgeuse.OBJ_CACHE", obj_cache):
        with mock.patch.multiple(
            "betelgeuse", TestCase=mock.DEFAULT, datetime=mock.DEFAULT, testimony=mock.DEFAULT
        ) as patches:
            test_case = mock.MagicMock()
            patches["TestCase"].query.return_value = [test_case]
            testimony_test_function = mock.MagicMock()
            testimony_test_function.testmodule = "module.py"
            testimony_test_function.parent_class = "NameTestCase"
            testimony_test_function.name = "test_name"
            patches["testimony"].get_testcases.return_value = {"module.py": [testimony_test_function]}
            add_test_record(
                {
                    "classname": "module.NameTestCase",
                    "message": u"Test failed because it not worked",
                    "name": "test_name",
                    "status": "failure",
                    "time": "3.1415",
                }
            )
            test_run.add_test_record_by_fields.assert_called_once_with(
                duration=3.1415,
                executed=patches["datetime"].datetime.now(),
                executed_by="testuser",
                test_case_id=test_case.work_item_id,
                test_comment="Test failed because it not worked",
                test_result="failed",
            )