def test_add_plugin_no_publish(self): pages = self.get_pages() posts = self.get_posts() post = posts[0] post.enable_liveblog = True post.save() request = self.get_request(pages[0], user=self.user, lang='en') Channel('setup').send({'connect': 1, 'reply_channel': 'reply'}) message = self.get_next_message('setup', require=True) liveblog_connect(message, self.app_config_1.namespace, 'en', post.slug) plugin = add_plugin( post.liveblog, 'LiveblogPlugin', language='en', body='live text', publish=False ) __, admin = plugin.get_plugin_instance() admin.save_model(request, plugin, None, None) result = self.get_next_message(message.reply_channel.name, require=False) self.assertIsNone(result) plugin.publish = True plugin.save() admin.save_model(request, plugin, None, None) result = self.get_next_message(message.reply_channel.name, require=True) self.assertTrue(result['text']) rendered = json.loads(result['text']) self.assertEqual(plugin.pk, rendered['id']) self.assertEqual(plugin.creation_date.strftime(DATE_FORMAT), rendered['creation_date']) self.assertEqual(plugin.changed_date.strftime(DATE_FORMAT), rendered['changed_date']) self.assertTrue(rendered['content'].find('data-post-id="{}"'.format(plugin.pk)) > -1) self.assertTrue(rendered['content'].find('live text') > -1)
def test_disconnect(self): pages = self.get_pages() posts = self.get_posts() post = posts[0] post.enable_liveblog = True post.save() request = self.get_request(pages[0], user=self.user, lang='en') Channel('setup').send({'connect': 1, 'reply_channel': 'reply'}) message = self.get_next_message('setup', require=True) liveblog_connect(message, self.app_config_1.namespace, 'en', post.slug) plugin = add_plugin( post.liveblog, 'LiveblogPlugin', language='en', body='live text', publish=True ) __, admin = plugin.get_plugin_instance() admin.save_model(request, plugin, None, None) result = self.get_next_message(message.reply_channel.name, require=True) self.assertTrue(result['text']) liveblog_disconnect(message, self.app_config_1.namespace, 'en', post.slug) plugin.body = 'modified text' plugin.save() admin.save_model(request, plugin, None, None) result = self.get_next_message(message.reply_channel.name, require=False) self.assertIsNone(result)
def test_add_plugin_no_publish(self): pages = self.get_pages() posts = self.get_posts() post = posts[0] post.enable_liveblog = True post.save() request = self.get_request(pages[0], user=self.user, lang='en') Channel('setup').send({'connect': 1, 'reply_channel': 'reply'}) message = self.get_next_message('setup', require=True) liveblog_connect(message, self.app_config_1.namespace, 'en', post.slug) result = self.get_next_message(message.reply_channel.name, require=True) self.assertTrue(result['accept']) plugin = add_plugin( post.liveblog, 'LiveblogPlugin', language='en', body='live text', publish=False ) __, admin = plugin.get_plugin_instance() admin.save_model(request, plugin, None, None) result = self.get_next_message(message.reply_channel.name, require=False) self.assertIsNone(result) plugin.publish = True plugin.save() admin.save_model(request, plugin, None, None) result = self.get_next_message(message.reply_channel.name, require=True) self.assertTrue(result['text']) rendered = json.loads(result['text']) self.assertEqual(plugin.pk, rendered['id']) self.assertEqual(plugin.creation_date.strftime(DATE_FORMAT), rendered['creation_date']) self.assertEqual(plugin.changed_date.strftime(DATE_FORMAT), rendered['changed_date']) self.assertTrue(rendered['content'].find('data-post-id="{}"'.format(plugin.pk)) > -1) self.assertTrue(rendered['content'].find('live text') > -1)
def test_disconnect(self): pages = self.get_pages() posts = self.get_posts() post = posts[0] post.enable_liveblog = True post.save() request = self.get_request(pages[0], user=self.user, lang='en') Channel('setup').send({'connect': 1, 'reply_channel': 'reply'}) message = self.get_next_message('setup', require=True) liveblog_connect(message, self.app_config_1.namespace, 'en', post.slug) result = self.get_next_message(message.reply_channel.name, require=True) self.assertTrue(result['accept']) plugin = add_plugin( post.liveblog, 'LiveblogPlugin', language='en', body='live text', publish=True ) __, admin = plugin.get_plugin_instance() admin.save_model(request, plugin, None, None) result = self.get_next_message(message.reply_channel.name, require=True) self.assertTrue(result['text']) liveblog_disconnect(message, self.app_config_1.namespace, 'en', post.slug) plugin.body = 'modified text' plugin.save() admin.save_model(request, plugin, None, None) result = self.get_next_message(message.reply_channel.name, require=False) self.assertIsNone(result)
def test_plugin_without_post(self): pages = self.get_pages() placeholder = pages[0].get_placeholders().get(slot='content') Channel('setup').send({'connect': 1, 'reply_channel': 'reply'}) message = self.get_next_message('setup', require=True) liveblog_connect(message, self.app_config_1.namespace, 'en', 'random post') self.get_next_message(message.reply_channel.name, require=True) plugin = add_plugin( placeholder, 'LiveblogPlugin', language='en', body='live text', publish=True ) self.assertIsNone(plugin.liveblog_group) result = self.get_next_message(message.reply_channel.name, require=False) self.assertIsNone(result)
def test_nopost(self): self.get_pages() Channel('setup').send({'connect': 1, 'reply_channel': 'reply'}) message = self.get_next_message('setup', require=True) liveblog_connect(message, self.app_config_1.namespace, 'en', 'random-post') result = self.get_next_message(message.reply_channel.name, require=True) self.assertTrue(result['text']) rendered = json.loads(result['text']) self.assertTrue(rendered['error'], 'no_post') liveblog_disconnect(message, self.app_config_1.namespace, 'en', 'random-post') result = self.get_next_message(message.reply_channel.name, require=True) self.assertTrue(result['text']) rendered = json.loads(result['text']) self.assertTrue(rendered['error'], 'no_post')