class TestQuery(unittest.TestCase):

    def setUp(self):

        self.begin_at = datetime(2016, 1, 1)
        self.end_at = datetime(2016, 1, 2)
        self.rcq = RequestCountQuery(self.begin_at, self.end_at)

        self.mock_get_es()

    def mock_get_es(self):

        self.rcq.get_es = MagicMock()
        self.rcq.get_es.return_value = self.mock_es = MagicMock()
        self.mock_es.count.return_value = {'count': 1}

    def test_call(self):

        self.assertEqual(self.rcq.query(), 1)

        trc = TimeRangeClause(begin_time=self.begin_at, end_time=self.end_at)
        self.mock_es.count.assert_called_with(
            index='logstash-2016.01.01',
            body={'filter': trc.get_clause()}
        )
Exemple #2
0
    def get_request_count(self):

        if self._request_count is not None:
            return self._request_count

        rcq = RequestCountQuery(self.begin_at, self.end_at)
        self._request_count = rcq.query()

        return self._request_count
    def get_request_count(self):

        if self._request_count is not None:
            return self._request_count

        rcq = RequestCountQuery(self.begin_at, self.end_at)
        self._request_count = rcq.query()

        return self._request_count
Exemple #4
0
class TestQuery(unittest.TestCase):
    def setUp(self):

        self.begin_at = datetime(2016, 1, 1)
        self.end_at = datetime(2016, 1, 2)
        self.rcq = RequestCountQuery(self.begin_at, self.end_at)

        self.mock_get_es()

    def mock_get_es(self):

        self.rcq.get_es = MagicMock()
        self.rcq.get_es.return_value = self.mock_es = MagicMock()
        self.mock_es.count.return_value = {'count': 1}

    def test_call(self):

        self.assertEqual(self.rcq.query(), 1)
        self.mock_es.count.assert_called_with(
            index='logstash-2016.01.01',
            body={
                'query': {
                    'bool': {
                        'filter': [{
                            'range': {
                                'timestamp': {
                                    'gte': 1451606400000,
                                    'lt': 1451692800000
                                }
                            }
                        }, {
                            'exists': {
                                'field': 'rails.controller#action'
                            }
                        }, {
                            'term': {
                                'domain_name': 'api.thekono.com'
                            }
                        }, {
                            'range': {
                                'backend_processing_time': {
                                    'gte': 0
                                }
                            }
                        }]
                    }
                }
            })