from pmxbot import logging


class TestMongoDBLogging:
	def setup_logging(self, mongodb_uri):
		mongodb_uri = mongodb_uri + '/pmxbot_test'
		self.logger = logging.Logger.from_URI(mongodb_uri)
		return self.logger

	def teardown_method(self, method):
		if hasattr(self, 'logger'):
			self.logger.db.drop()
			self.logger.db.database.recent.drop()

	def test_message(self, mongodb_uri):
		self.setup_logging(mongodb_uri)
		l = self.logger
		l.message('#channel5', 'nik', 'something great happened today - the test passed')
		assert l.db.count() == 1
		assert 'test passed' in l.db.find_one()['message']

	def test_get_random_logs(self, mongodb_uri):
		l = self.setup_logging(mongodb_uri)
		l.message('#inane', 'nik', 'message one')
		l.message('#inane', 'nik', 'message two')
		messages = list(l.get_random_logs(2))
		assert len(messages) == 2
		assert set(messages) == set(['message one', 'message two'])

	def test_list_channels(self, mongodb_uri):
		l = self.setup_logging(mongodb_uri)
		l.message('#inane', 'nik', 'message one')
		l.message('#inane', 'sam', 'message two')
		l.message('#bar', 'nik', 'in walk two olives')
		channels = l.list_channels()
		assert len(channels) == 2
		assert set(channels) == set(['bar', 'inane'])

	def test_search(self, mongodb_uri):
		l = self.setup_logging(mongodb_uri)
		l.search("foo")

@@ -1241,16 +1241,21 @@
 t_search
+_miss
 (self, m
@@ -1307,16 +1307,176 @@
 _uri)%0A%09%09
+assert not l.search(%22foo%22)%0A%0A%09def test_search_hit(self, mongodb_uri):%0A%09%09l = self.setup_logging(mongodb_uri)%0A%09%09l.message('#inane', 'joe', %22who da foo?%22)%0A%09%09assert 
 l.search

Split test into hit and miss