import ceph_medic
from ceph_medic import runner
from ceph_medic.tests import base_metadata


class TestRunner(object):

    def setup(self):
        # clear metadata
        ceph_medic.metadata = base_metadata
        runner.metadata = base_metadata

    def teardown(self):
        # clear metadata
        ceph_medic.metadata = base_metadata
        runner.metadata = base_metadata

    def test_calculate_total_hosts_is_0(self):
        run = runner.Runner()
        assert run.total_hosts == 0

    def test_calculate_hosts_single_daemon_type(self):
        ceph_medic.metadata['nodes']['osds'] = [{'host': 'node1'},{'host': 'node2'}]
        runner.metadata = ceph_medic.metadata
        run = runner.Runner()
        assert run.total_hosts == 2

    def test_count_from_different_daemon_types(self):
        ceph_medic.metadata['nodes']['osds'] = [{'host': 'node1'},{'host': 'node2'}]
        ceph_medic.metadata['nodes']['mons'] = [{'host': 'node3'},{'host': 'node4'}]
        runner.metadata = ceph_medic.metadata
        run = runner.Runner()
        assert run.total_hosts == 4

@@ -1081,8 +1081,1140 @@
 ts == 4%0A
+%0A%0Aclass FakeWriter(object):%0A%0A    def __init__(self):%0A        self.calls = %5B%5D%0A%0A    def raw(self, string):%0A        self.calls.append(string)%0A%0A%0Aclass TestReport(object):%0A%0A    def setup(self):%0A        # clear metadata%0A        ceph_medic.metadata = base_metadata%0A        runner.metadata = base_metadata%0A        runner.metadata%5B'nodes'%5D = %7B%7D%0A        self.results = runner.Runner()%0A%0A    def teardown(self):%0A        # clear metadata%0A        ceph_medic.metadata = base_metadata%0A        runner.metadata = base_metadata%0A        runner.metadata%5B'nodes'%5D = %7B%7D%0A%0A    def test_reports_errors(self, monkeypatch):%0A        fake_writer = FakeWriter()%0A        monkeypatch.setattr(runner.terminal, 'write', fake_writer)%0A        self.results.errors = %5B'I am an error'%5D%0A        runner.report(self.results)%0A        assert 'While running checks, ceph-medic had unhandled errors' in fake_writer.calls%5B-1%5D%0A%0A    def test_reports_no_errors(self, monkeypatch):%0A        fake_writer = FakeWriter()%0A        monkeypatch.setattr(runner.terminal, 'write', fake_writer)%0A        runner.report(self.results)%0A        assert fake_writer.calls%5B0%5D == '%5Cn0 passed, on 0 hosts'%0A

add tests for reporting warnings