class CassandraDriverTest(unittest.TestCase):
    @classmethod
    def setUpClass(cls):
        cls.check_uuid = str(uuid4())
        cls.trigger_uuid = str(uuid4())

    @patch('alamo_alerter.backend.cassandra.Cluster')
    @patch('alamo_alerter.backend.cassandra.PlainTextAuthProvider')
    def setUp(self, auth_mock, cluster_mock):
        session_mock = MagicMock()
        cluster_mock.connect = MagicMock(return_value=session_mock)
        self.trigger = dict(
            id=self.trigger_uuid,
            uuid=str(uuid4()),
            severity='WARNING',
            enabled=True,
            result=dict(status=0, message='')
        )

        self.driver = CassandraDriver(
            contact_points=[''],
            username='******',
            password='******',
            keyspace='test'
        )

    def test_prepared_statements(self):
        expected_calls = [call(SELECT_QUERY), call(INSERT_QUERY),
                          call(INSERT_SERVICE_QUERY)]
        self.driver._session.prepare.assert_has_calls(
            expected_calls, any_order=True
        )

    def test_get_result_method(self):
        self.driver.get_result(self.check_uuid, self.trigger_uuid, 10)

        self.driver._session.execute.assert_called_once_with(
            self.driver._save_query_stmt,
            (UUID(self.check_uuid), UUID(self.trigger_uuid), 10)
        )

    def test_save_result_method(self):
        _now = datetime.now()
        self.driver.save_result(
            self.check_uuid, self.trigger, _now, _now, _now, False, '999'
        )

        self.assertTrue(self.driver._session.execute.called)
    def setUp(self, auth_mock, cluster_mock):
        session_mock = MagicMock()
        cluster_mock.connect = MagicMock(return_value=session_mock)
        self.trigger = dict(
            id=self.trigger_uuid,
            uuid=str(uuid4()),
            severity='WARNING',
            enabled=True,
            result=dict(status=0, message='')
        )

        self.driver = CassandraDriver(
            contact_points=[''],
            username='******',
            password='******',
            keyspace='test'
        )