def setUp(self): self.storage = ElasticSearchStorage() self.storage.es.indices.delete(index='logstash-*', ignore=[400, 404]) self.storage.es.indices.delete(index='objects', ignore=[400, 404]) call([os.path.join(pwd, 'start.sh'), basedir]) time.sleep(1)
class TestBonnieFunctional(unittest.TestCase): attempts = 12 def setUp(self): self.storage = ElasticSearchStorage() self.storage.es.indices.delete(index='logstash-*', ignore=[400, 404]) self.storage.es.indices.delete(index='objects', ignore=[400, 404]) call([os.path.join(pwd, 'start.sh'), basedir]) time.sleep(1) def tearDown(self): call([os.path.join(pwd, 'stop.sh')]) time.sleep(2) def query_log(self, query): attempts = self.attempts while attempts > 0: attempts -= 1 res = self.storage.select(query, index='logstash-*', doctype='logs', sortby='@timestamp:desc') if res and res['total'] > 0: return res['hits'] time.sleep(1) # print "query retry", attempts return None def storage_get(self, key, index, doctype): attempts = self.attempts while attempts > 0: attempts -= 1 res = self.storage.get(key, index=index, doctype=doctype) if res is not None: return res time.sleep(1) # print "get retry", attempts return None
def test_001_notificaton2folder(self): notification = { "event": "MailboxCreate", "uri": "imap://[email protected]@kolab.example.org/Calendar/Subcal;UIDVALIDITY=12345", "metadata": { "/shared/vendor/cmu/cyrus-imapd/partition": "default", "/shared/vendor/cmu/cyrus-imapd/lastupdate": "23-Sep-2014 11:55:15 -0400", "/shared/vendor/cmu/cyrus-imapd/duplicatedeliver": "false", "/shared/vendor/cmu/cyrus-imapd/pop3newuidl": "true", "/shared/vendor/cmu/cyrus-imapd/size": "0", "/shared/vendor/cmu/cyrus-imapd/sharedseen": "false", "/shared/vendor/kolab/folder-type": "event", "/shared/vendor/cmu/cyrus-imapd/uniqueid": "28614de9-3614-422d-be5d-5716605ef0fc", }, "acl": {"*****@*****.**": "lrswipkxtecdan", "anyone": "lrs"}, } storage = ElasticSearchStorage() folder = storage.notificaton2folder(notification) folder_id = folder["id"] self.assertTrue(folder.has_key("body")) self.assertEqual(folder["body"]["uniqueid"], notification["folder_uniqueid"]) self.assertEqual(folder["body"]["server"], "kolab.example.org") self.assertEqual(folder["body"]["owner"], "*****@*****.**") self.assertEqual(folder["body"]["uri"], "imap://[email protected]@kolab.example.org/Calendar/Subcal") # check changes in ignored metadata notification["metadata"]["/shared/vendor/cmu/cyrus-imapd/lastupdate"] = "24-Sep-2014 16:21:19 -0400" notification["metadata"]["/shared/vendor/cmu/cyrus-imapd/size"] = "88" notification["acl"] = {"anyone": "lrs", "*****@*****.**": "lrswipkxtecdan"} notification["uri"] = "imap://[email protected]@kolab.example.org/Calendar/RENAMED;UIDVALIDITY=123456" folder = storage.notificaton2folder(notification) self.assertEqual(folder["id"], folder_id) # detect ACL changes notification["acl"] = {"*****@*****.**": "lrswipkxtecdan", "anyone": "lrswd"} folder = storage.notificaton2folder(notification) self.assertNotEqual(folder["id"], folder_id)