1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
|
#!/usr/bin/env python
# Copyright (c) 2017 Orange and others.
#
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Apache License, Version 2.0
# which accompanies this distribution, and is available at
# http://www.apache.org/licenses/LICENSE-2.0
# pylint: disable=missing-docstring
import logging
import unittest
import mock
from functest.core import feature
from functest.core import testcase
from functest.utils import constants
class FeatureInitTesting(unittest.TestCase):
logging.disable(logging.CRITICAL)
@unittest.skip("JIRA: FUNCTEST-780")
def test_init_with_wrong_repo(self):
with self.assertRaises(ValueError):
feature.Feature(repo='foo')
def test_init(self):
barometer = feature.Feature(repo='dir_repo_barometer')
self.assertEqual(barometer.project_name, "functest")
self.assertEqual(barometer.case_name, "")
self.assertEqual(
barometer.repo,
constants.CONST.__getattribute__('dir_repo_barometer'))
class FeatureTesting(unittest.TestCase):
logging.disable(logging.CRITICAL)
def setUp(self):
self.feature = feature.Feature(repo='dir_repo_barometer')
@unittest.skip("JIRA: FUNCTEST-781")
def test_prepare_ko(self):
# pylint: disable=bad-continuation
with mock.patch.object(
self.feature, 'prepare',
return_value=testcase.TestCase.EX_RUN_ERROR) as mock_object:
self.assertEqual(self.feature.run(),
testcase.TestCase.EX_RUN_ERROR)
mock_object.assert_called_once_with()
@unittest.skip("JIRA: FUNCTEST-781")
def test_prepare_exc(self):
with mock.patch.object(self.feature, 'prepare',
side_effect=Exception) as mock_object:
self.assertEqual(self.feature.run(),
testcase.TestCase.EX_RUN_ERROR)
mock_object.assert_called_once_with()
@unittest.skip("JIRA: FUNCTEST-781")
def test_post_ko(self):
# pylint: disable=bad-continuation
with mock.patch.object(
self.feature, 'post',
return_value=testcase.TestCase.EX_RUN_ERROR) as mock_object:
self.assertEqual(self.feature.run(),
testcase.TestCase.EX_RUN_ERROR)
mock_object.assert_called_once_with()
@unittest.skip("JIRA: FUNCTEST-781")
def test_post_exc(self):
with mock.patch.object(self.feature, 'post',
side_effect=Exception) as mock_object:
self.assertEqual(self.feature.run(),
testcase.TestCase.EX_RUN_ERROR)
mock_object.assert_called_once_with()
@unittest.skip("JIRA: FUNCTEST-778")
def test_execute_ko(self):
with mock.patch.object(self.feature, 'execute',
return_value=1) as mock_object:
self.assertEqual(self.feature.run(),
testcase.TestCase.EX_RUN_ERROR)
mock_object.assert_called_once_with()
@unittest.skip("JIRA: FUNCTEST-778")
def test_execute_exc(self):
with mock.patch.object(self.feature, 'execute',
side_effect=Exception) as mock_object:
self.assertEqual(self.feature.run(),
testcase.TestCase.EX_RUN_ERROR)
mock_object.assert_called_once_with()
def test_run(self):
with mock.patch.object(self.feature, 'execute',
return_value=0) as mock_object:
self.assertEqual(self.feature.run(),
testcase.TestCase.EX_OK)
mock_object.assert_called_once_with()
if __name__ == "__main__":
unittest.main(verbosity=2)
|