Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_add_quote(self):
"""
Try adding a quote
"""
quote = "And then she said %s" % str(uuid.uuid4())
res = quotes.quote("add %s" % quote)
assert res == "Quote added!"
cursor = logging.Logger.store.db.cursor()
cursor.execute(
"select count(*) from quotes where library = 'pmx' and quote = ?", (quote,)
)
numquotes = cursor.fetchone()[0]
assert numquotes == 1
def setup_logging(self, mongodb_uri):
mongodb_uri = mongodb_uri + '/pmxbot_test'
self.logger = logging.Logger.from_URI(mongodb_uri)
return self.logger
def setup_class(cls):
path = os.path.dirname(os.path.abspath(__file__))
configfile = os.path.join(path, 'testconf.yaml')
config = pmxbot.dictlib.ConfigDict.from_yaml(configfile)
cls.bot = core.initialize(config)
logging.Logger.store.message("logged", "testrunner", "some text")
def default(self, channel):
page = jenv.get_template('channel.html')
db = pmxbot.logging.Logger.store
context = get_context()
contents = db.get_channel_days(channel)
months = {}
for fn in sorted(contents, reverse=True):
mon_des, day = fn.rsplit('-', 1)
months.setdefault(pmon(mon_des), []).append((pday(fn), fn))
context['months'] = sorted(months.items(), key=self.by_date, reverse=True)
context['channel'] = channel
return page.render(**context).encode('utf-8')
def _build_log_id_map(self):
from . import logging
if not hasattr(logging.Logger, 'log_id_map'):
log_db = self.db.database.logs
logging.Logger.log_id_map = dict(
(logging.MongoDBLogger.extract_legacy_id(rec['_id']), rec['_id'])
for rec in log_db.find(projection=[])
)
return logging.Logger.log_id_map
def _build_log_id_map(self):
from . import logging
if not hasattr(logging.Logger, 'log_id_map'):
log_db = self.db.database.logs
logging.Logger.log_id_map = dict(
(logging.MongoDBLogger.extract_legacy_id(rec['_id']), rec['_id'])
for rec in log_db.find(projection=[])
)
return logging.Logger.log_id_map
@contains('pmxbot', channels=logging.UnloggedChannels(), rate=0.3)
def rand_bot(channel, nick, rest):
log.debug('I was mentioned in %s: %s', channel, rest)
default_commands = [
'featurecreep',
'insult',
'motivate',
'compliment',
'cheer',
'golfclap',
'nastygram',
'curse',
'bless',
'job',
'hire',
'oregontrail',
'chain',
import logging
import pytz
from jaraco.context import ExceptionTrap
from more_itertools import chunked
import pmxbot
from . import storage
from . import core
from pmxbot.core import command, NoLog
first = operator.itemgetter(0)
_log = logging.getLogger(__name__)
class Logger(storage.SelectableStorage):
"Base Logger class"
@classmethod
def initialize(cls):
cls.store = cls.from_URI()
tmpl = "Logging with {cls.store.__class__.__name__}"
_log.info(tmpl.format_map(locals()))
cls._finalizers.append(cls.finalize)
@classmethod
def finalize(cls):
del cls.store
def log(self, nick, channel, change):
self.db.ensure_index(
[
('datetime.d', storage.pymongo.DESCENDING),
('channel', storage.pymongo.ASCENDING),
]
)
now = datetime.datetime.utcnow()
doc = dict(
channel=channel,
nick=nick,
change=change,
datetime=logging.MongoDBLogger._fmt_date(now),
)
self.db.insert(doc)