Пример #1
0
 def test_sync_posts_error_post_number(self):
     """Test that number of post in DB > number of post in VK"""
     self.create_post(Post.Status.ERROR_PARSE,
                      'text',
                      date=timezone.now() -
                      timedelta(days=5, milliseconds=1))
     with self.assertRaises(RuntimeError):
         with patch('app.services.vk_api_service.get_wall_posts') as gi:
             gi.return_value = {'count': 0, 'items': []}
             sync_service.sync_posts()
Пример #2
0
 def test_sync_posts_need_sync(self, ts, us, gwp):
     """Test that _sync_block_posts calls 2 times"""
     gwp.return_value = {'count': 1}
     ts.return_value = True
     with patch('app.services.sync_service._sync_block_posts') as sbp:
         sbp.side_effect = [0, 1]
         sync_service.sync_posts()
         self.assertEqual(gwp.call_count, 2)
         self.assertEqual(ts.call_count, 1)
         self.assertEqual(us.call_count, 1)
         self.assertEqual(sbp.call_count, 2)
Пример #3
0
 def test_transactional_sync_posts(self):
     """Test that sync post runs in transaction"""
     items = [
         self.create_vk_post(5, '18+4=22'),
         self.create_vk_post('a', '18+4=22'),
     ]
     with patch('app.services.vk_api_service.get_wall_posts') as gwp:
         gwp.return_value = {'count': len(items), 'items': items}
         try:
             sync_service.sync_posts()
         except ValueError:
             pass
         self.assertEqual(Post.objects.count(), 0)
Пример #4
0
def sync_posts_task():
    logger.info('--- Sync posts task started ---')

    if not Config.objects.get().sync_posts:
        msg = 'Sync posts task is disabled'
        logger.info(f'>> {msg}')
        return msg

    sync_service.sync_posts()

    msg = 'Sync posts task successfully finished'
    logger.info(f'--- {msg} ---')
    return msg
Пример #5
0
 def test_sync_posts_many_blocks(self):
     sync_service.DOWNLOAD_POST_COUNT = 1
     items = [
         self.create_vk_post(2, '18+4=22'),
         self.create_vk_post(1, '18+4=22'),
     ]
     with patch('app.services.vk_api_service.get_wall_posts'
                ) as get_wall_posts:
         get_wall_posts.side_effect = [{
             'count': len(items),
             'items': items[1:2]
         }, {
             'count': len(items),
             'items': items[1:2]
         }, {
             'count': len(items),
             'items': items
         }, {
             'count': len(items),
             'items': items
         }]
         sync_service.sync_posts()
         self.assertEqual(get_wall_posts.call_count, 2 * 2)
Пример #6
0
 def sync(self, request):
     sync_service.sync_posts()
     return Response(status=status.HTTP_204_NO_CONTENT)
Пример #7
0
 def test_sync_posts(self):
     """Test that sync_posts call get_wall_posts 2 times"""
     with patch('app.services.vk_api_service.get_wall_posts') as gi:
         gi.return_value = {'count': 0, 'items': []}
         sync_service.sync_posts()
         self.assertEqual(gi.call_count, 2)