def setUp(self):
        session.commit()
        drop_all()
        create_all()

        session.add(Host(id=1)) # Contains alerts 1,2,4
        session.add(Host(id=2)) # Contains alert 6,7

        for i in range(1,8):
            session.add(Alert(id=i, name=i))

        session.add(HostGroup(id=1))
        session.add(HostGroup(id=2))
        session.add(HostGroupAssignment(member_host_id=1, host_group_id=1))

        session.add(Service(id=1))
        session.add(Service(id=2))
        session.add(Service(id=3))
        session.add(ServiceDependency(host_id=1, service_id=1))
        session.add(RedundancyGroup(id=1, service_id=3))
        session.add(RedundancyGroupComponent(host_id=2, redundancy_group_id=1))
        session.add(ServiceDependency(redundancy_group_id=1, service_id=3))

        session.add(AlertCheckEntity(host_id=1, alert_id=1))
        session.add(AlertCheckEntity(host_group_id=1, alert_id=2))
        session.add(AlertCheckEntity(host_group_id=2, alert_id=3))
        session.add(AlertCheckEntity(service_id=1, alert_id=4))
        session.add(AlertCheckEntity(service_id=2, alert_id=5))
        session.add(AlertCheckEntity(host_id=2, alert_id=6))
        session.add(AlertCheckEntity(service_id=3, alert_id=7))

        session.commit()
    def setUp(self):
        session.commit()
        drop_all()
        create_all()

        session.add(Host(id=1))  # Contains alerts 1,2,4
        session.add(Host(id=2))  # Contains alert 6,7

        for i in range(1, 8):
            session.add(Alert(id=i, name=i))

        session.add(HostGroup(id=1))
        session.add(HostGroup(id=2))
        session.add(HostGroupAssignment(member_host_id=1, host_group_id=1))

        session.add(Service(id=1))
        session.add(Service(id=2))
        session.add(Service(id=3))
        session.add(ServiceDependency(host_id=1, service_id=1))
        session.add(RedundancyGroup(id=1, service_id=3))
        session.add(RedundancyGroupComponent(host_id=2, redundancy_group_id=1))
        session.add(ServiceDependency(redundancy_group_id=1, service_id=3))

        session.add(AlertCheckEntity(host_id=1, alert_id=1))
        session.add(AlertCheckEntity(host_group_id=1, alert_id=2))
        session.add(AlertCheckEntity(host_group_id=2, alert_id=3))
        session.add(AlertCheckEntity(service_id=1, alert_id=4))
        session.add(AlertCheckEntity(service_id=2, alert_id=5))
        session.add(AlertCheckEntity(host_id=2, alert_id=6))
        session.add(AlertCheckEntity(service_id=3, alert_id=7))

        session.commit()
    def setUp(self):
        session.commit()
        drop_all()
        create_all()

        session.add(Alert(id=1))
        session.add(Alert(id=2))
        session.add(Check(id=1))
        session.add(Plugin(id=1))

        session.add(AlertRestrictToEntity(alert_id=1, plugin_id=1))
        session.add(AlertRestrictToEntity(alert_id=1, check_id=1))

        session.commit()
    def setUp(self):
        session.commit()
        drop_all()
        create_all()

        session.add(Alert(id=1))
        session.add(Alert(id=2))
        session.add(Check(id=1))
        session.add(Plugin(id=1))

        session.add(AlertRestrictToEntity(alert_id=1, plugin_id=1))
        session.add(AlertRestrictToEntity(alert_id=1, check_id=1))

        session.commit()
    def setUp(self):
        session.commit()
        drop_all()
        create_all()

        # Add Hosts
        for i in range(1,5):
            session.add(Host(id=i, name="Host {}".format(i)))

        # Add Groups
        for i in range(1,9):
            session.add(HostGroup(id=i, name="Group {}".format(i)))

        session.flush()

        # Assign hosts to groups
        session.add(HostGroupAssignment(member_host_id=1, host_group_id=1))
        session.add(HostGroupAssignment(member_host_id=1, host_group_id=2))
        session.add(HostGroupAssignment(member_host_id=2, host_group_id=1))
        session.add(HostGroupAssignment(member_host_id=2, host_group_id=2))
        session.add(HostGroupAssignment(member_host_id=2, host_group_id=3))
        session.add(HostGroupAssignment(member_host_id=3, host_group_id=2))
        session.add(HostGroupAssignment(member_host_id=3, host_group_id=3))
        session.add(HostGroupAssignment(member_host_id=3, host_group_id=5))
        session.add(HostGroupAssignment(member_host_id=4, host_group_id=2))
        session.add(HostGroupAssignment(member_host_id=4, host_group_id=6))
        session.add(HostGroupAssignment(member_host_id=4, host_group_id=5))

        # Assign groups to groups
        session.add(HostGroupAssignment(member_host_group_id=4,
            host_group_id=5))
        session.add(HostGroupAssignment(member_host_group_id=3,
            host_group_id=4))
        session.add(HostGroupAssignment(member_host_group_id=6,
            host_group_id=7))
        session.add(HostGroupAssignment(member_host_group_id=7,
            host_group_id=8))
        session.add(HostGroupAssignment(member_host_group_id=8,
            host_group_id=6))

        session.commit()
    def setUp(self):
        session.commit()
        drop_all()
        create_all()

        # Add Hosts
        for i in range(1, 5):
            session.add(Host(id=i, name="Host {}".format(i)))

        # Add Groups
        for i in range(1, 9):
            session.add(HostGroup(id=i, name="Group {}".format(i)))

        session.flush()

        # Assign hosts to groups
        session.add(HostGroupAssignment(member_host_id=1, host_group_id=1))
        session.add(HostGroupAssignment(member_host_id=1, host_group_id=2))
        session.add(HostGroupAssignment(member_host_id=2, host_group_id=1))
        session.add(HostGroupAssignment(member_host_id=2, host_group_id=2))
        session.add(HostGroupAssignment(member_host_id=2, host_group_id=3))
        session.add(HostGroupAssignment(member_host_id=3, host_group_id=2))
        session.add(HostGroupAssignment(member_host_id=3, host_group_id=3))
        session.add(HostGroupAssignment(member_host_id=3, host_group_id=5))
        session.add(HostGroupAssignment(member_host_id=4, host_group_id=2))
        session.add(HostGroupAssignment(member_host_id=4, host_group_id=6))
        session.add(HostGroupAssignment(member_host_id=4, host_group_id=5))

        # Assign groups to groups
        session.add(
            HostGroupAssignment(member_host_group_id=4, host_group_id=5))
        session.add(
            HostGroupAssignment(member_host_group_id=3, host_group_id=4))
        session.add(
            HostGroupAssignment(member_host_group_id=6, host_group_id=7))
        session.add(
            HostGroupAssignment(member_host_group_id=7, host_group_id=8))
        session.add(
            HostGroupAssignment(member_host_group_id=8, host_group_id=6))

        session.commit()
    def setUp(self):
        session.commit()
        drop_all()
        create_all()
        # Insert all plugins
        for letter in ["A", "B", "C"]:
            session.add(Plugin(id=letter, name=letter))

        # Insert all hosts
        for number in range(1,9):
            session.add(Host(name=number))

        # Mock the assigned_plugins method
        Host.assigned_plugins = property(lambda s: Plugin.query.all())

        # All plugins OK
        session.add(PluginResult(host_id=1, plugin_id="A",
            health_status="ok"))
        session.add(PluginResult(host_id=1, plugin_id="B",
            health_status="ok"))
        session.add(PluginResult(host_id=1, plugin_id="C",
            health_status="ok"))

        # All plugins critical
        session.add(PluginResult(host_id=2, plugin_id="A",
            health_status="critical"))
        session.add(PluginResult(host_id=2, plugin_id="B",
            health_status="critical"))
        session.add(PluginResult(host_id=2, plugin_id="C",
            health_status="critical"))

        # All plugins unknown
        session.add(PluginResult(host_id=3, plugin_id="A",
            health_status="unknown"))
        session.add(PluginResult(host_id=3, plugin_id="B",
            health_status="unknown"))
        session.add(PluginResult(host_id=3, plugin_id="C",
            health_status="unknown"))

        # One plugin critical
        session.add(PluginResult(host_id=4, plugin_id="A",
            health_status="ok"))
        session.add(PluginResult(host_id=4, plugin_id="B",
            health_status="critical"))
        session.add(PluginResult(host_id=4, plugin_id="C",
            health_status="ok"))

        # One plugin unknown
        session.add(PluginResult(host_id=5, plugin_id="A",
            health_status="ok"))
        session.add(PluginResult(host_id=5, plugin_id="B",
            health_status="ok"))
        session.add(PluginResult(host_id=5, plugin_id="C",
            health_status="unknown"))

        # All plugins no_data (Host 6)

        # One plugin no data
        session.add(PluginResult(host_id=7, plugin_id="A",
            health_status="ok"))
        session.add(PluginResult(host_id=7, plugin_id="C",
            health_status="minor"))

        # Mixed results
        session.add(PluginResult(host_id=8, plugin_id="A",
            health_status="ok"))
        session.add(PluginResult(host_id=8, plugin_id="B",
            health_status="major"))
        session.add(PluginResult(host_id=8, plugin_id="C",
            health_status="minor"))

        session.commit()
    def setUp(self):
        session.commit()
        drop_all()
        create_all()
        session.add(Plugin(id="Plugin", name="Plugin"))

        # Insert all hosts
        for number in range(1,7):
            session.add(Host(name=number))

        # Mock the assigned_plugins method
        Host.assigned_plugins = property(lambda s: Plugin.query.all())

        session.add(PluginResult(host_id=1, plugin_id="Plugin",
            health_status="ok"))
        session.add(PluginResult(host_id=2, plugin_id="Plugin",
            health_status="minor"))
        session.add(PluginResult(host_id=3, plugin_id="Plugin",
            health_status="major"))
        session.add(PluginResult(host_id=4, plugin_id="Plugin",
            health_status="critical"))
        session.add(PluginResult(host_id=5, plugin_id="Plugin",
            health_status="unknown"))
        # Host ID 6 has no data

        session.add(HostGroup(id=1))
        session.add(HostGroupAssignment(host_group_id=1, member_host_id=1))
        session.add(HostGroupAssignment(host_group_id=1, member_host_id=4))

        for number in range(1,11):
            session.add(Service(id=number, name=number))

        # test_failed_dependency
        session.add(ServiceDependency(service_id=1, host_id=1))
        session.add(ServiceDependency(service_id=1, host_id=1))
        session.add(ServiceDependency(service_id=1, host_id=3))

        # test_ok_dependency
        session.add(ServiceDependency(service_id=2, host_id=1))
        session.add(ServiceDependency(service_id=2, host_id=1))
        session.add(ServiceDependency(service_id=2, host_id=1))

        # test_failure_in_redundancy_group
        session.add(RedundancyGroup(id=1, service_id=3))
        session.add(RedundancyGroupComponent(redundancy_group_id=1, host_id=1))
        session.add(RedundancyGroupComponent(redundancy_group_id=1, host_id=1))
        session.add(RedundancyGroupComponent(redundancy_group_id=1, host_id=4))
        session.add(ServiceDependency(service_id=3, redundancy_group_id=1))

        # test_failed_redundancy_group
        session.add(RedundancyGroup(id=2, service_id=4))
        session.add(RedundancyGroupComponent(redundancy_group_id=2, host_id=2))
        session.add(RedundancyGroupComponent(redundancy_group_id=2, host_id=2))
        session.add(RedundancyGroupComponent(redundancy_group_id=2, host_id=4))
        session.add(ServiceDependency(service_id=4, redundancy_group_id=2))

        # redundancy_group_ok
        session.add(RedundancyGroup(id=3, service_id=5))
        session.add(RedundancyGroupComponent(redundancy_group_id=3, host_id=1))
        session.add(RedundancyGroupComponent(redundancy_group_id=3, host_id=1))
        session.add(RedundancyGroupComponent(redundancy_group_id=3, host_id=1))
        session.add(ServiceDependency(service_id=5, redundancy_group_id=3))

        # test_failed_dependency_with_redundancy_group
        session.add(RedundancyGroup(id=4, service_id=6))
        session.add(RedundancyGroupComponent(redundancy_group_id=4, host_id=1))
        session.add(RedundancyGroupComponent(redundancy_group_id=4, host_id=1))
        session.add(RedundancyGroupComponent(redundancy_group_id=4, host_id=1))
        session.add(ServiceDependency(service_id=6, redundancy_group_id=4))
        session.add(ServiceDependency(service_id=6, host_id=3))

        # test_all_dependency_failed
        session.add(ServiceDependency(service_id=7, host_id=3))
        session.add(ServiceDependency(service_id=7, host_id=3))
        session.add(ServiceDependency(service_id=7, host_id=4))

        # test_no_data
        session.add(ServiceDependency(service_id=8, host_id=1))
        session.add(ServiceDependency(service_id=8, host_id=1))
        session.add(ServiceDependency(service_id=8, host_id=6))

        # test_host_group_dependency
        session.add(ServiceDependency(service_id=9, host_group_id=1))

        # test_host_group_redundancy
        session.add(RedundancyGroup(id=5, service_id=10))
        session.add(RedundancyGroupComponent(redundancy_group_id=5,
            host_group_id=1))
        session.add(ServiceDependency(service_id=10, redundancy_group_id=5))

        session.commit()
    def setUp(self):
        session.commit()
        drop_all()
        create_all()
        # Insert all plugins
        for letter in ["A", "B", "C"]:
            session.add(Plugin(id=letter, name=letter))

        # Insert all hosts
        for number in range(1, 9):
            session.add(Host(name=number))

        # Mock the assigned_plugins method
        Host.assigned_plugins = property(lambda s: Plugin.query.all())

        # All plugins OK
        session.add(PluginResult(host_id=1, plugin_id="A", health_status="ok"))
        session.add(PluginResult(host_id=1, plugin_id="B", health_status="ok"))
        session.add(PluginResult(host_id=1, plugin_id="C", health_status="ok"))

        # All plugins critical
        session.add(
            PluginResult(host_id=2, plugin_id="A", health_status="critical"))
        session.add(
            PluginResult(host_id=2, plugin_id="B", health_status="critical"))
        session.add(
            PluginResult(host_id=2, plugin_id="C", health_status="critical"))

        # All plugins unknown
        session.add(
            PluginResult(host_id=3, plugin_id="A", health_status="unknown"))
        session.add(
            PluginResult(host_id=3, plugin_id="B", health_status="unknown"))
        session.add(
            PluginResult(host_id=3, plugin_id="C", health_status="unknown"))

        # One plugin critical
        session.add(PluginResult(host_id=4, plugin_id="A", health_status="ok"))
        session.add(
            PluginResult(host_id=4, plugin_id="B", health_status="critical"))
        session.add(PluginResult(host_id=4, plugin_id="C", health_status="ok"))

        # One plugin unknown
        session.add(PluginResult(host_id=5, plugin_id="A", health_status="ok"))
        session.add(PluginResult(host_id=5, plugin_id="B", health_status="ok"))
        session.add(
            PluginResult(host_id=5, plugin_id="C", health_status="unknown"))

        # All plugins no_data (Host 6)

        # One plugin no data
        session.add(PluginResult(host_id=7, plugin_id="A", health_status="ok"))
        session.add(
            PluginResult(host_id=7, plugin_id="C", health_status="minor"))

        # Mixed results
        session.add(PluginResult(host_id=8, plugin_id="A", health_status="ok"))
        session.add(
            PluginResult(host_id=8, plugin_id="B", health_status="major"))
        session.add(
            PluginResult(host_id=8, plugin_id="C", health_status="minor"))

        session.commit()
    def setUp(self):
        session.commit()
        drop_all()
        create_all()
        session.add(Plugin(id="Plugin", name="Plugin"))

        # Insert all hosts
        for number in range(1, 7):
            session.add(Host(name=number))

        # Mock the assigned_plugins method
        Host.assigned_plugins = property(lambda s: Plugin.query.all())

        session.add(
            PluginResult(host_id=1, plugin_id="Plugin", health_status="ok"))
        session.add(
            PluginResult(host_id=2, plugin_id="Plugin", health_status="minor"))
        session.add(
            PluginResult(host_id=3, plugin_id="Plugin", health_status="major"))
        session.add(
            PluginResult(host_id=4,
                         plugin_id="Plugin",
                         health_status="critical"))
        session.add(
            PluginResult(host_id=5,
                         plugin_id="Plugin",
                         health_status="unknown"))
        # Host ID 6 has no data

        session.add(HostGroup(id=1))
        session.add(HostGroupAssignment(host_group_id=1, member_host_id=1))
        session.add(HostGroupAssignment(host_group_id=1, member_host_id=4))

        for number in range(1, 11):
            session.add(Service(id=number, name=number))

        # test_failed_dependency
        session.add(ServiceDependency(service_id=1, host_id=1))
        session.add(ServiceDependency(service_id=1, host_id=1))
        session.add(ServiceDependency(service_id=1, host_id=3))

        # test_ok_dependency
        session.add(ServiceDependency(service_id=2, host_id=1))
        session.add(ServiceDependency(service_id=2, host_id=1))
        session.add(ServiceDependency(service_id=2, host_id=1))

        # test_failure_in_redundancy_group
        session.add(RedundancyGroup(id=1, service_id=3))
        session.add(RedundancyGroupComponent(redundancy_group_id=1, host_id=1))
        session.add(RedundancyGroupComponent(redundancy_group_id=1, host_id=1))
        session.add(RedundancyGroupComponent(redundancy_group_id=1, host_id=4))
        session.add(ServiceDependency(service_id=3, redundancy_group_id=1))

        # test_failed_redundancy_group
        session.add(RedundancyGroup(id=2, service_id=4))
        session.add(RedundancyGroupComponent(redundancy_group_id=2, host_id=2))
        session.add(RedundancyGroupComponent(redundancy_group_id=2, host_id=2))
        session.add(RedundancyGroupComponent(redundancy_group_id=2, host_id=4))
        session.add(ServiceDependency(service_id=4, redundancy_group_id=2))

        # redundancy_group_ok
        session.add(RedundancyGroup(id=3, service_id=5))
        session.add(RedundancyGroupComponent(redundancy_group_id=3, host_id=1))
        session.add(RedundancyGroupComponent(redundancy_group_id=3, host_id=1))
        session.add(RedundancyGroupComponent(redundancy_group_id=3, host_id=1))
        session.add(ServiceDependency(service_id=5, redundancy_group_id=3))

        # test_failed_dependency_with_redundancy_group
        session.add(RedundancyGroup(id=4, service_id=6))
        session.add(RedundancyGroupComponent(redundancy_group_id=4, host_id=1))
        session.add(RedundancyGroupComponent(redundancy_group_id=4, host_id=1))
        session.add(RedundancyGroupComponent(redundancy_group_id=4, host_id=1))
        session.add(ServiceDependency(service_id=6, redundancy_group_id=4))
        session.add(ServiceDependency(service_id=6, host_id=3))

        # test_all_dependency_failed
        session.add(ServiceDependency(service_id=7, host_id=3))
        session.add(ServiceDependency(service_id=7, host_id=3))
        session.add(ServiceDependency(service_id=7, host_id=4))

        # test_no_data
        session.add(ServiceDependency(service_id=8, host_id=1))
        session.add(ServiceDependency(service_id=8, host_id=1))
        session.add(ServiceDependency(service_id=8, host_id=6))

        # test_host_group_dependency
        session.add(ServiceDependency(service_id=9, host_group_id=1))

        # test_host_group_redundancy
        session.add(RedundancyGroup(id=5, service_id=10))
        session.add(
            RedundancyGroupComponent(redundancy_group_id=5, host_group_id=1))
        session.add(ServiceDependency(service_id=10, redundancy_group_id=5))

        session.commit()