def setUp(self): from bot.lib.material import create_material from bot.lib.maker import create_maker maker, created = create_maker(sender_id='1') material = create_material(sender_id=maker.sender_id, url="http://via.placeholder.com/350x150", file_type='image') material_2 = create_material(sender_id=maker.sender_id, url='http://via.placeholder.com/350x150', file_type='image') self.material = material
def test_create_new_material(self): from bot.lib.material import create_material from bot.models import Material, MaterialFile create_material(sender_id=self.sender_id, url=self.material_url, file_type=self.material_type) self.assertEqual( Material.objects.filter(maker__sender_id=self.sender_id).count(), 1) self.assertEqual( MaterialFile.objects.filter( material__maker__sender_id=self.sender_id).count(), 1)
def setUp(self): from bot.lib.maker import create_maker from bot.lib.project import create_project, update_project from bot.lib.material import create_material from bot.lib.pattern import create_pattern self.sender_id = '1' self.pattern_url = 'http://via.placeholder.com/350x150' self.pattern_type = 'image' self.material_url = 'http://via.placeholder.com/350x150' self.material_type = 'image' self.project_name = 'test_project' self.due_date = '2018-01-01' self.tags = ['1', '2', '3'] self.update_url = 'http://via.placeholder.com/350x150' self.update_type = 'image' create_maker(sender_id=self.sender_id) project, created = create_project(sender_id=self.sender_id, name=self.project_name) self.project = project self.material = create_material(sender_id=self.sender_id, url=self.material_url, file_type=self.material_type) self.pattern = create_pattern(sender_id=self.sender_id, url=self.pattern_url, file_type=self.pattern_type) update_project(sender_id=self.sender_id, project_id=str(self.project.id), date_string=self.due_date, material_id=str(self.material.id), pattern_id=str(self.pattern.id), tags=self.tags)
def setUp(self): from bot.lib.maker import create_maker from bot.lib.pattern import create_pattern from bot.lib.material import create_material from bot.lib.project import create_project, update_project self.sender_id = '108886223055545' create_maker(sender_id=self.sender_id) project, created = create_project(sender_id=self.sender_id, name='Test_project') self.pattern = create_pattern(sender_id=self.sender_id, url='http://via.placeholder.com/350x150', file_type='image') self.material = create_material( sender_id=self.sender_id, url='http://via.placeholder.com/350x150', file_type='image') update_project(sender_id=self.sender_id, project_id=str(project.id), material_id=str(self.material.id), pattern_id=str(self.pattern.id), date_string='2300-10-30') self.project = project project_2, created = create_project(sender_id=self.sender_id, name='Test_project_2')
def respond(sender_id, message_text, attachment_type, attachment_url, postback, quick_reply, context): """Takes in ``sender_id``, ``attachment_type``= photo,``attachment_url``= url, ``context`` = project id and updates project and sends a reponse. :param str sender_id: The unique id created by facebook and the current facebook's sender's ID :param str attachment_type: dentifies attachment type i.e photo :param str attachment_url: The location of the attachment :param dict context: attributes sent between conversation in the case project_id :param str message_text: Any text written in the chat interface (optional, defaults to None) :param str postback: a reponse sent from the user clicking a button (optional, defaults to None) :param str quick_reply: an automatic reply (optional, defaults to None) :returns: ``reponse``a dict with the next message to move the conversation ``new_context`` same context as before, and ``coverstation`` dict containing the next stage and task for the the bot """ from bot.lib.material import create_material from bot.lib.project import update_project from .utilities import send_date_picker material = create_material(sender_id=sender_id, url=attachment_url, file_type=attachment_type) update_project(sender_id=sender_id, project_id=context["project_id"], material_id=str(material.id)) new_context = context conversation = dict(name='create_project', stage='add_due_date') response = send_date_picker(sender_id=sender_id) return response, new_context, conversation
def setUp(self): from bot.lib.maker import create_maker from bot.lib.material import create_material self.sender_id = '1' create_maker(sender_id=self.sender_id) self.material_url = 'http://via.placeholder.com/350x150' self.material_type = 'image' self.tags = ['1', '2', '3'] material = create_material(sender_id=self.sender_id, url=self.material_url, file_type=self.material_type) self.material_id = str(material.id)
def test_update_project_with_projects(self): from bot.tasks import route_message from bot.lib.conversation import get_conversation_stage_id from bot.models import Maker from bot.lib.maker import create_maker from bot.lib.project import create_project, update_project from bot.lib.material import create_material from bot.lib.pattern import create_pattern self.sender_id = '1' self.pattern_url = 'http://via.placeholder.com/350x150' self.pattern_type = 'image' self.material_url = 'http://via.placeholder.com/350x150' self.material_type = 'image' self.project_name = 'test_project' self.due_date = '2017-01-01' self.tags = ['1', '2', '3'] self.update_url = 'http://via.placeholder.com/350x150' self.update_type = 'image' create_maker(sender_id=self.sender_id) project, created = create_project(sender_id=self.sender_id, name=self.project_name) self.project = project self.material = create_material(sender_id=self.sender_id, url=self.material_url, file_type=self.material_type) self.pattern = create_pattern(sender_id=self.sender_id, url=self.pattern_url, file_type=self.pattern_type) update_project(sender_id=self.sender_id, project_id=str(self.project.id), date_string=self.due_date, material_id=str(self.material.id), pattern_id=str(self.pattern.id), tags=self.tags) route_message(sender_id=self.sender_id, message_text=None, quick_reply=None, postback='UPDATE_PROJECT_PAYLOAD', attachment_type=None, attachment_url=None) self.assertNotEqual( Maker.objects.get(sender_id=self.sender_id).conversation_stage_id, get_conversation_stage_id(conversation_name='menu', stage_name='menu'))
def respond(sender_id, message_text, attachment_type, attachment_url, postback, quick_reply, context): from bot.lib.material import create_material from bot.lib.pattern import create_pattern """Takes in ``sender_id``, ``attachment_type``= photo,``attachment_url``= url, ``context`` = supply id and creates supply and sends a reponse. :param str sender_id: The unique id created by facebook and the current facebook's sender's ID :param str attachment_type: dentifies attachment type i.e photo :param str attachment_url: The location of the attachment :param dict context: attributes sent between conversation in the case project_id :param str message_text: Any text written in the chat interface (optional, defaults to None) :param str postback: a reponse sent from the user clicking a button (optional, defaults to None) :param str quick_reply: an automatic reply (optional, defaults to None) :returns: ``reponse``a dict with the next message to move the conversation ``new_context`` dict with context type and id, and ``coverstation`` dict containing the next stage and task for the the bot """ if context['type'] == 'material': supply = create_material(sender_id=sender_id, url=attachment_url, file_type=attachment_type) else: supply = create_pattern(sender_id=sender_id, url=attachment_url, file_type=attachment_type) new_context = { 'type': context['type'], '{0}_id'.format(context['type']): str(supply.id) } conversation = dict(name='create_supplies', stage='add_context') response = dict( message_text= "Awesome! That's all I need. Or you can upload another photo or add some hashtags" ) return response, new_context, conversation