def test_tagdb_autocomplete(self): self.maxDiff = None db = LocalDatabaseTagDB() self._test_autocomplete( db, 'graphite.tags.localdatabase.LocalDatabaseTagDB.find_series')
def test_find_series_cached(self): mockCache = Mock() mockCache.get.return_value = ['test.a;blah=blah;hello=tiger'] result = LocalDatabaseTagDB(settings, cache=mockCache).find_series(['name=test.a','hello=tiger']) self.assertEqual(mockCache.get.call_count, 1) self.assertEqual(mockCache.get.call_args[0][0], 'TagDB.find_series:hello=tiger:name=test.a') self.assertEqual(result, ['test.a;blah=blah;hello=tiger'])
def test_find_series_cached(self): def mock_cache_get(cacheKey): if cacheKey != 'TagDB.find_series:hello=tiger:name=test.a': raise Exception('Unexpected cacheKey %s' % cacheKey) return ['test.a;blah=blah;hello=tiger'] with patch('django.core.cache.cache.get', mock_cache_get): result = LocalDatabaseTagDB().find_series(['name=test.a','hello=tiger']) self.assertEqual(result, ['test.a;blah=blah;hello=tiger'])
def test_tagdb_cached(self, cache_get, log_info): cache_get.return_value = [] result = LocalDatabaseTagDB().find_series(['tag2=value2', 'tag1=value1']) self.assertEqual(cache_get.call_count, 1) self.assertEqual(cache_get.call_args[0][0], 'TagDB.find_series:tag1=value1:tag2=value2') self.assertEqual(result, []) self.assertEqual(log_info.call_count, 1) self.assertRegexpMatches( log_info.call_args[0][0], 'graphite\.tags\.localdatabase\.LocalDatabaseTagDB\.find_series :: completed \(cached\) in [-.e0-9]+s' )
def test_tagdb_cached(self): mockCache = Mock() mockCache.get.return_value = [] mockLog = Mock() result = LocalDatabaseTagDB(settings, cache=mockCache, log=mockLog).find_series(['tag2=value2', 'tag1=value1']) self.assertEqual(mockCache.get.call_count, 1) self.assertEqual(mockCache.get.call_args[0][0], 'TagDB.find_series:tag1=value1:tag2=value2') self.assertEqual(result, []) self.assertEqual(mockLog.info.call_count, 1) self.assertRegexpMatches( mockLog.info.call_args[0][0], r'graphite\.tags\.localdatabase\.LocalDatabaseTagDB\.find_series :: completed \(cached\) in [-.e0-9]+s' )
def test_local_tagdb(self): return self._test_tagdb(LocalDatabaseTagDB(settings))