def test_from_document(self): data1 = {'_id': 666, 'groupid': 'groupid', 'pattern': 'pattern', 'template': 'template', 'that': 'that', 'topic': 'topic', 'userid': 'userid'} category1 = Category.from_document(data1) self.assertIsNotNone(category1) data2 = {'groupid': 'groupid', 'pattern': 'pattern', 'template': 'template', 'that': 'that', 'topic': 'topic', 'userid': 'userid'} category2 = Category.from_document(data2) self.assertIsNotNone(category2)
def save_learnf(self, client_context, category): YLogger.debug( self, "Storing learnf category in Mongo [%s] [%s] [%s] [%s] [%s] [%s]", client_context.client.id, client_context.userid, category.pattern, category.topic, category.that, category.template) #pattern = category.pattern #topic = category.topic #that = category.that #template = category.template # Changes pattern = category.pattern.text topic = category.topic.text that = category.that.text template = category.template.resolve(client_context) # End Changes groupid = "LEARNF" userid = client_context.userid category = Category(groupid=groupid, userid=userid, pattern=pattern, topic=topic, that=that, template=template) return self.add_document(category)
def _load_documents(self, documents, parser): for doc in documents: category = Category.from_document(doc) YLogger.debug(self, "Loading category [%s] [%s] [%s] [%s] [%s]", category.groupid, category.pattern, category.topic, category.that, category.template) self._load_category(category.groupid, category.pattern, category.topic, category.that, category.template, parser)
def store_category(self, groupid, userid, topic, that, pattern, template): YLogger.debug(self, "Storing category in Mongo [%s] [%s] [%s] [%s] [%s]", groupid, pattern, topic, that, template) category = Category(groupid=groupid, userid=userid, topic=topic, that=that, pattern=pattern, template=template) return self.add_document(category)
def test_init(self): category1 = Category("groupid", "userid", "topic", "that", "pattern", "template") self.assertIsNotNone(category1) self.assertEqual("<Category(id='n/a', groupid='groupid', userid='userid', topic='topic', that='that', pattern='pattern', template='template'>", str(category1)) doc1 = category1.to_document() self.assertIsNotNone(doc1) self.assertEqual({'groupid': 'groupid', 'pattern': 'pattern', 'template': 'template', 'that': 'that', 'topic': 'topic', 'userid': 'userid'}, doc1) category2 = Category("groupid", "userid", "topic", "that", "pattern", "template", categoryid=None) self.assertIsNotNone(category2) self.assertEqual("<Category(id='n/a', groupid='groupid', userid='userid', topic='topic', that='that', pattern='pattern', template='template'>", str(category2)) doc2 = category1.to_document() self.assertIsNotNone(doc2) self.assertEqual({'groupid': 'groupid', 'pattern': 'pattern', 'template': 'template', 'that': 'that', 'topic': 'topic', 'userid': 'userid'}, doc2) category3 = Category("groupid", "userid", "topic", "that", "pattern", "template", categoryid=666) self.assertIsNotNone(category3) self.assertEqual("<Category(id='666', groupid='groupid', userid='userid', topic='topic', that='that', pattern='pattern', template='template'>", str(category3)) doc3 = category3.to_document() self.assertIsNotNone(doc3) self.assertEqual({'_id': 666, 'groupid': 'groupid', 'pattern': 'pattern', 'template': 'template', 'that': 'that', 'topic': 'topic', 'userid': 'userid'}, doc3)
def save_learnf(self, client_context, category): YLogger.debug(self, "Storing learnf category in Mongo [%s] [%s] [%s] [%s] [%s] [%s]", client_context.client.id, client_context.userid, category.pattern, category.topic, category.that, category.template) pattern = category.pattern topic = category.topic that = category.that template = category.template groupid = "LEARNF" userid = client_context.userid category = Category(groupid=groupid, userid=userid, pattern=pattern, topic=topic, that=that, template=template) self.add_document(category)