4
# Copyright 2014 Canonical Ltd.
5
# This program is free software: you can redistribute it and/or modify it
6
# under the terms of the GNU Affero General Public License version 3, as
7
# published by the Free Software Foundation.
9
# This program is distributed in the hope that it will be useful, but
10
# WITHOUT ANY WARRANTY; without even the implied warranties of
11
# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
12
# PURPOSE. See the GNU Affero General Public License for more details.
14
# You should have received a copy of the GNU Affero General Public License
15
# along with this program. If not, see <http://www.gnu.org/licenses/>.
18
from mock import patch, MagicMock
21
import xml.etree.ElementTree as etree
23
from ci_utils.testing.fixtures import FakeDataStore
24
from ci_utils.amqp_worker import AMQPWorker
26
CURDIR = os.path.dirname(__file__)
29
class CoverageRetrieverWorkerTestCase(unittest.TestCase):
32
super(CoverageRetrieverWorkerTestCase, self).setUp()
33
create_data_store_patch = patch.object(
34
AMQPWorker, '_create_data_store')
35
create_data_store = create_data_store_patch.start()
36
self.addCleanup(create_data_store_patch.stop)
37
self.fake_data_store = FakeDataStore('fake_ticket_id')
38
self.addCleanup(self.fake_data_store.delete)
39
create_data_store.return_value = self.fake_data_store
40
self.fake_logger = MagicMock(spec=logging.Logger)
41
# we'll need this for a couple of tests
42
with open(os.path.join(CURDIR, 'build.log'), 'r') as f:
43
self.build_log_text = f.read()
45
def put_fake_build_log(self):
46
"""Put a fake log in our fake data store.
48
Find this log at filename build.log, depends on finding
49
build.log in tests dir.
51
self.fake_data_store.put_file(
54
content_type='text/plain')
56
def validate_coverage_xml(self, coverage_xml):
57
"""Parse and verify our retrieved coverage.xml."""
58
root_coverage_node = etree.fromstring(coverage_xml)
59
self.assertAlmostEqual(
61
float(root_coverage_node.attrib['line-rate']))