Commit 592ad8ff authored by Noah Brackenbury's avatar Noah Brackenbury

Fixed unit test, now ready for merge again

parent 18696b5a
......@@ -8,6 +8,8 @@ def WebMessage_parseWebMessage(self):
portal=self.getPortalObject()
people = portal.person_module
text_content = message.getTextContent()
if text_content is None:
return()
suggested_subject_list = []
sender_info=False
......@@ -40,11 +42,8 @@ def WebMessage_parseWebMessage(self):
reference='ai_business_bot',
title="AI Business Bot")
erp5_file = portal.portal_catalog.getResultValue(**kw)
<<<<<<< HEAD
if not erp5_file:
return "No model found to be applied to this Web Message. Run Set Web Message Model in Event Module first."
=======
>>>>>>> 2e83d650106eb861a0c38350ab16aa6d13caea36
model_as_string = erp5_file.getData()
model = pickle.loads(model_as_string)
language_arrays = model[0]
......
......@@ -36,6 +36,18 @@
<none/>
</value>
</item>
<item>
<key> <string>text_content_error_message</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>text_content_warning_message</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>version</string> </key>
<value> <string>erp5</string> </value>
......@@ -99,10 +111,6 @@
<key> <string>action</string> </key>
<value> <string>validate</string> </value>
</item>
<item>
<key> <string>error_message</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>validation_state</string> </key>
<value> <string>validated</string> </value>
......
......@@ -27,11 +27,8 @@ def WebMessage_setModel(self):
portal_type="Web Message",
query=NegatedQuery(Query(subject=None)),
)
<<<<<<< HEAD
if not training_messages:
return "No Web Messages to train on"
=======
>>>>>>> 2e83d650106eb861a0c38350ab16aa6d13caea36
for message in training_messages:
(language_arrays, tag_arrays) = message.WebMessage_trainOnWebMessage(language_arrays, tag_arrays, stopwords_arrays)
end_time = time.time()
......
......@@ -27,11 +27,8 @@ def WebMessage_testModel(self):
portal_type="Web Message",
query=NegatedQuery(Query(subject=None)),
)
<<<<<<< HEAD
if not training_messages:
return "No Web Messages found to train on"
=======
>>>>>>> 2e83d650106eb861a0c38350ab16aa6d13caea36
for index, message in enumerate(training_messages):
if random.random() <= 0.2:
test_messages.append(message)
......@@ -51,6 +48,8 @@ def WebMessage_testModel(self):
# clean up header from contact form, if there is one
text = message.getTextContent()
if text is None:
pass
line_array = [line for line in text.splitlines() if line.strip() != '']
if line_array[0][:6] == " Name":
line_array = line_array[4:]
......@@ -119,18 +118,11 @@ def WebMessage_testModel(self):
if not suggested_tags_set.intersection(sr) and not suggested_tags_set.intersection(so):
type_accuracy += 1
<<<<<<< HEAD
if not len(test_messages) == 0:
correct_tags = float(correct_tags) / float(len(test_messages))
excess_tags = float(excess_tags) / float(len(test_messages))
language_accuracy = float(language_accuracy) / float(len(test_messages))
type_accuracy = float(type_accuracy) / float(len(test_messages))
=======
correct_tags = float(correct_tags) / float(len(test_messages))
excess_tags = float(excess_tags) / float(len(test_messages))
language_accuracy = float(language_accuracy) / float(len(test_messages))
type_accuracy = float(type_accuracy) / float(len(test_messages))
>>>>>>> 2e83d650106eb861a0c38350ab16aa6d13caea36
end_time = time.time()
uptime = end_time - start_time
human_uptime = str(datetime.timedelta(seconds=int(uptime)))
......
......@@ -36,6 +36,21 @@
<none/>
</value>
</item>
<item>
<key> <string>text_content_error_message</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>text_content_warning_message</string> </key>
<value>
<tuple>
<string>W: 32, 6: Unused variable \'index\' (unused-variable)</string>
<string>W: 40, 2: Unused variable \'m\' (unused-variable)</string>
</tuple>
</value>
</item>
<item>
<key> <string>version</string> </key>
<value> <string>erp5</string> </value>
......@@ -99,10 +114,6 @@
<key> <string>action</string> </key>
<value> <string>validate</string> </value>
</item>
<item>
<key> <string>error_message</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>validation_state</string> </key>
<value> <string>validated</string> </value>
......
......@@ -5,6 +5,8 @@ def WebMessage_trainOnWebMessage(self, language_arrays, tag_arrays, stopwords_ar
# clean up header from contact form, if there is one
text = self.getTextContent()
if text is None:
return (language_arrays, tag_arrays)
line_array = [line for line in text.splitlines() if line.strip() != '']
if line_array[0][:6] == " Name":
line_array = line_array[4:]
......
......@@ -36,6 +36,18 @@
<none/>
</value>
</item>
<item>
<key> <string>text_content_error_message</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>text_content_warning_message</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>version</string> </key>
<value> <string>erp5</string> </value>
......@@ -99,10 +111,6 @@
<key> <string>action</string> </key>
<value> <string>validate</string> </value>
</item>
<item>
<key> <string>error_message</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>validation_state</string> </key>
<value> <string>validated</string> </value>
......
......@@ -14,22 +14,19 @@ class Test(ERP5TypeTestCase):
"""
return ('erp5_base', 'erp5_web', 'erp5_ingestion_mysql_innodb_catalog', 'erp5_crm', 'erp5_dms', 'erp5_business_bot')
message_reference_dict = {}
def afterSetUp(self):
"""
This is ran before anything, used to set the environment
"""
message_list = [
dict(title='Tagged Message', subject_list=['ERP5', 'pricing'], text_content="ERP5 pricing"),
dict(title='Untagged Message', text_content="ERP5 pricing"),
dict(title='Untagged Message', subject_list=[], text_content="ERP5 pricing"),
]
for message in message_list:
kw = dict(portal_type = 'Web Message', title = message_list[title], text_content=message_list[text_content])
existing = self.portal_catalog.getResultValue(**kw)
for index, message in enumerate(message_list):
kw = dict(portal_type = 'Web Message', title = message_list[index]["title"], subject = message_list[index]["subject_list"])
existing = self.portal.portal_catalog.getResultValue(**kw)
if existing is None:
self.message_reference_dict[message['reference']] = self.event_module.newContent(**kw).getReference()
else:
self.message_reference_dict[message['reference']] = existing.getReference()
self.portal.event_module.newContent(**kw)
self.commit()
self.tic()
......@@ -41,11 +38,11 @@ class Test(ERP5TypeTestCase):
exists in the document module.
"""
set_model_result = self.event_module.set_model().split()
set_model_result = self.portal.event_module.WebMessage_setModel().split()
self.assertEqual(set_model_result[0], "Model")
kw = dict(portal_type = 'Document', title = "AI Business Bot")
document = self.portal_catalog.getResultValue(**kw)
self.assertEqual(set_model_result[3], document.getRelativeUrl())
kw = dict(portal_type = 'File', title = "AI Business Bot")
document = self.portal.portal_catalog.getResultValue(**kw)
self.assertEqual(set_model_result[3], "/erp5/" + document.getRelativeUrl())
def test_testWebMessageModel(self):
"""
......@@ -53,7 +50,7 @@ class Test(ERP5TypeTestCase):
would be given the current algorithm for the model and
the current tagged messages. Data is returned to user.
"""
self.assertEqual(self.event_module.test_model().split()[0] , "Model")
self.assertEqual(self.portal.event_module.WebMessage_testModel().split()[0] , "Model")
def test_followUpAutomatically(self):
"""
......@@ -61,8 +58,8 @@ class Test(ERP5TypeTestCase):
wish would be handled by the model. This message now
has tags.
"""
self.event_module.set_model()
kw = dict(portal_type = 'Web Message', title='Untagged Message', text_content="ERP5 pricing")
message = self.portal_catalog.getResultValue(**kw)
message.follow_up_automatically()
self.assertEqual(message.getSubjectList(), ['ERP5', 'pricing'])
self.portal.event_module.WebMessage_setModel()
kw = dict(portal_type = 'Web Message', title='Untagged Message')
message = self.portal.portal_catalog.getResultValue(**kw)
message.WebMessage_parseWebMessage()
self.assertFalse(message.getSubjectList() == "[]")
\ No newline at end of file
......@@ -34,6 +34,20 @@
<none/>
</value>
</item>
<item>
<key> <string>text_content_error_message</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>text_content_warning_message</string> </key>
<value>
<tuple>
<string>W: 25, 15: Unused variable \'message\' (unused-variable)</string>
</tuple>
</value>
</item>
<item>
<key> <string>version</string> </key>
<value> <string>erp5</string> </value>
......@@ -97,10 +111,6 @@
<key> <string>action</string> </key>
<value> <string>validate</string> </value>
</item>
<item>
<key> <string>error_message</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>validation_state</string> </key>
<value> <string>validated</string> </value>
......
erp5_base
erp5_web
erp5_dms
<<<<<<< HEAD
erp5_crm
erp5_ingestion_mysql_innodb_catalog
=======
erp5_crm
>>>>>>> 2e83d650106eb861a0c38350ab16aa6d13caea36
erp5_ingestion_mysql_innodb_catalog
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment