def setUp(self): self.begin_at = datetime(2016, 1, 1) self.end_at = datetime(2016, 1, 2) self.sccq = StatusCodeCountQuery(self.begin_at, self.end_at, 200) self.mock_get_es()
def get_http_status_code_count(self, status_code_class): sccq = StatusCodeCountQuery( self.begin_at, self.end_at, status_code_class ) return sccq.query()
class TestQuery(unittest.TestCase): def setUp(self): self.begin_at = datetime(2016, 1, 1) self.end_at = datetime(2016, 1, 2) self.sccq = StatusCodeCountQuery(self.begin_at, self.end_at, 200) self.mock_get_es() def mock_get_es(self): self.sccq.get_es = MagicMock() self.sccq.get_es.return_value = self.mock_es = MagicMock() self.mock_es.count.return_value = {'count': 1} def test_call(self): self.assertEqual(self.sccq.query(), 1) trc = TimeRangeClause(begin_time=self.begin_at, end_time=self.end_at) rc = RangeClause('backend_status_code', min_val=200, max_val=300) self.mock_es.count.assert_called_with( index='logstash-2016.01.01', body={ 'filter': { 'bool': {'filter': [trc.get_clause(), rc.get_clause()]} } } )
class TestQuery(unittest.TestCase): def setUp(self): self.begin_at = datetime(2016, 1, 1) self.end_at = datetime(2016, 1, 2) self.sccq = StatusCodeCountQuery(self.begin_at, self.end_at, 200) self.mock_get_es() def mock_get_es(self): self.sccq.get_es = MagicMock() self.sccq.get_es.return_value = self.mock_es = MagicMock() self.mock_es.count.return_value = {'count': 1} def test_call(self): field = 'backend_status_code' self.assertEqual(self.sccq.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 } } }, { 'range': { field: { 'gte': 200, 'lt': 300 } } }] } } })
def get_http_status_code_count(self, status_code_class): sccq = StatusCodeCountQuery(self.begin_at, self.end_at, status_code_class) return sccq.query()