def send_mails(news): from the_tale.post_service.prototypes import MessagePrototype as PostServiceMessagePrototype from the_tale.post_service.message_handlers import NewsHandler PostServiceMessagePrototype.create(NewsHandler(news_id=news.id)) news.emailed = relations.EMAILED_STATE.EMAILED save_news(news)
def send_mails(news): from the_tale.post_service.prototypes import MessagePrototype as PostServiceMessagePrototype from the_tale.post_service.message_handlers import NewsHandler PostServiceMessagePrototype.create(NewsHandler(news_id=news.id)) news.emailed = relations.EMAILED_STATE.EMAILED save_news(news)
def create(cls, subcategory, caption, author, text, markup_method=MARKUP_METHOD.POSTMARKUP, technical=False): from the_tale.post_service.prototypes import MessagePrototype from the_tale.post_service.message_handlers import ForumThreadHandler if isinstance(subcategory, int): subcategory = SubCategoryPrototype.get_by_id(subcategory) thread_model = Thread.objects.create(subcategory=subcategory._model, caption=caption, author=author._model, last_poster=author._model, technical=technical, posts_count=0) Post.objects.create(thread=thread_model, author=author._model, markup_method=markup_method, technical=technical, text=text, created_at_turn=TimePrototype.get_current_turn_number(), state=POST_STATE.DEFAULT) prototype = cls(model=thread_model) subcategory.update() MessagePrototype.create(ForumThreadHandler(thread_id=prototype.id)) return prototype
def request_email_confirmation(self): from the_tale.post_service.prototypes import MessagePrototype from the_tale.post_service.message_handlers import ChangeEmailNotificationHandler if self._model.new_email is None: raise exceptions.NewEmailNotSpecifiedError() MessagePrototype.create(ChangeEmailNotificationHandler(task_id=self.id), now=True)
def notify_post_service(answer, recipients_ids): from the_tale.post_service.prototypes import MessagePrototype from the_tale.post_service.message_handlers import PersonalMessageHandler for recipient_id in recipients_ids: MessagePrototype.create( PersonalMessageHandler(message_id=answer.message_id, account_id=recipient_id))
def request_email_confirmation(self): from the_tale.post_service.prototypes import MessagePrototype from the_tale.post_service.message_handlers import ChangeEmailNotificationHandler if self._model.new_email is None: raise exceptions.NewEmailNotSpecifiedError() MessagePrototype.create(ChangeEmailNotificationHandler(task_id=self.id), now=True)
def create(cls, account): from the_tale.post_service.prototypes import MessagePrototype from the_tale.post_service.message_handlers import ResetPasswordHandler model = cls._model_class.objects.create(account=account._model, uuid=uuid.uuid4().hex) prototype = cls(model=model) MessagePrototype.create(ResetPasswordHandler(account_id=account.id, task_uuid=prototype.uuid), now=True) return prototype
def test_get_priority_message_no_messages(self): message_1 = MessagePrototype.create(handler=TestHandler()) message_2 = MessagePrototype.create(handler=TestHandler()) message_1._model.state = MESSAGE_STATE.PROCESSED message_1.save() message_2._model.state = MESSAGE_STATE.ERROR message_2.save() self.assertEqual(MessagePrototype.get_priority_message(), None)
def test_get_priority_message_no_messages(self): message_1 = MessagePrototype.create(handler=TestHandler()) message_2 = MessagePrototype.create(handler=TestHandler()) message_1._model.state = MESSAGE_STATE.PROCESSED message_1.save() message_2._model.state = MESSAGE_STATE.ERROR message_2.save() self.assertEqual(MessagePrototype.get_priority_message(), None)
def create(cls, account): from the_tale.post_service.prototypes import MessagePrototype from the_tale.post_service.message_handlers import ResetPasswordHandler model = cls._model_class.objects.create(account=account._model, uuid=uuid.uuid4().hex) prototype = cls(model=model) MessagePrototype.create(ResetPasswordHandler(account_id=account.id, task_uuid=prototype.uuid), now=True) return prototype
def create(cls, sender, recipient, text): from the_tale.post_service.prototypes import MessagePrototype as PostServiceMessagePrototype from the_tale.post_service.message_handlers import PersonalMessageHandler model = Message.objects.create(recipient=recipient._model, sender=sender._model, text=text) recipient.increment_new_messages_number() prototype = cls(model=model) PostServiceMessagePrototype.create(PersonalMessageHandler(message_id=prototype.id)) return prototype
def create(cls, sender, recipient, text): from the_tale.post_service.prototypes import MessagePrototype as PostServiceMessagePrototype from the_tale.post_service.message_handlers import PersonalMessageHandler model = Message.objects.create(recipient=recipient._model, sender=sender._model, text=text) recipient.increment_new_messages_number() prototype = cls(model=model) PostServiceMessagePrototype.create( PersonalMessageHandler(message_id=prototype.id)) return prototype
def setUp(self): super(MessageSenderTests, self).setUp() self.message = MessagePrototype.create(TestHandler()) environment.deinitialize() environment.initialize() self.worker = environment.workers.message_sender
def setUp(self): super(MessageSenderTests, self).setUp() self.message = MessagePrototype.create(TestHandler()) environment.deinitialize() environment.initialize() self.worker = environment.workers.message_sender
def test_remove_old_messages(self): message_1 = MessagePrototype.create(handler=TestHandler()) message_1._model.state = MESSAGE_STATE.PROCESSED message_1.save() message_2 = MessagePrototype.create(handler=TestHandler()) message_2._model.created_at -= datetime.timedelta(seconds=post_service_settings.MESSAGE_LIVE_TIME) message_2._model.state = MESSAGE_STATE.PROCESSED message_2.save() message_3 = MessagePrototype.create(handler=TestHandler()) message_3._model.created_at -= datetime.timedelta(seconds=post_service_settings.MESSAGE_LIVE_TIME) message_3.save() MessagePrototype.remove_old_messages() self.assertEqual(MessagePrototype._db_count(), 2) self.assertEqual(MessagePrototype._db_get_object(0).id, message_1.id) self.assertEqual(MessagePrototype._db_get_object(1).id, message_3.id)
def test_remove_old_messages(self): message_1 = MessagePrototype.create(handler=TestHandler()) message_1._model.state = MESSAGE_STATE.PROCESSED message_1.save() message_2 = MessagePrototype.create(handler=TestHandler()) message_2._model.created_at -= datetime.timedelta( seconds=post_service_settings.MESSAGE_LIVE_TIME) message_2._model.state = MESSAGE_STATE.PROCESSED message_2.save() message_3 = MessagePrototype.create(handler=TestHandler()) message_3._model.created_at -= datetime.timedelta( seconds=post_service_settings.MESSAGE_LIVE_TIME) message_3.save() MessagePrototype.remove_old_messages() self.assertEqual(MessagePrototype._db_count(), 2) self.assertEqual(MessagePrototype._db_get_object(0).id, message_1.id) self.assertEqual(MessagePrototype._db_get_object(1).id, message_3.id)
def create(cls, thread, author, text, technical=False): from the_tale.post_service.prototypes import MessagePrototype from the_tale.post_service.message_handlers import ForumPostHandler post = Post.objects.create(thread=thread._model, author=author._model, text=text, technical=technical, markup_method=MARKUP_METHOD.POSTMARKUP, created_at_turn=TimePrototype.get_current_turn_number(), state=POST_STATE.DEFAULT) thread.update() thread.subcategory.update() prototype = cls(post) MessagePrototype.create(ForumPostHandler(post_id=prototype.id)) return prototype
def test_create_with_now(self): with mock.patch( 'the_tale.post_service.workers.message_sender.Worker.cmd_send_now' ) as cmd_send_now: message = MessagePrototype.create(TestHandler(), now=True) self.assertEqual(cmd_send_now.call_args, mock.call(message.id))
def test_create_without_now(self): with mock.patch('the_tale.post_service.workers.message_sender.Worker.cmd_send_now') as cmd_send_now: MessagePrototype.create(TestHandler()) self.assertEqual(cmd_send_now.call_count, 0)
def test_create_with_now(self): with mock.patch('the_tale.post_service.workers.message_sender.Worker.cmd_send_now') as cmd_send_now: message = MessagePrototype.create(TestHandler(), now=True) self.assertEqual(cmd_send_now.call_args, mock.call(message.id))
def test_create_without_now(self): with mock.patch( 'the_tale.post_service.workers.message_sender.Worker.cmd_send_now' ) as cmd_send_now: MessagePrototype.create(TestHandler()) self.assertEqual(cmd_send_now.call_count, 0)