Ejemplo n.º 1
0
 def test_retry_upload_to_doc_service_queue_loop_exit(
         self, mrequest, gevent_sleep):
     """ Test LoopExit for retry_upload_to_doc_service_queue """
     gevent_sleep.side_effect = custom_sleep
     mrequest.post(self.url, [{
         'json': self.stat_200(),
         'status_code': 200
     } for _ in range(2)])
     self.client._create_tender_resource_item.side_effect = [
         self.get_tender() for _ in range(2)
     ]
     self.process_tracker.set_item(self.tender_id, self.award_id, 2)
     self.worker.retry_upload_to_doc_service_queue = MagicMock()
     self.worker.retry_upload_to_doc_service_queue.peek.side_effect = generate_answers(
         answers=[LoopExit(), self.data, self.data], default=LoopExit())
     self.worker.start()
     sleep(1)
     self.worker.shutdown()
     self.assertEqual(self.upload_to_tender_queue.qsize(), 0,
                      'Queue should be empty')
     self.assertEqual(self.process_tracker.processing_items, {})
     self.assertIsNotNone(
         self.client.request_history[0].headers['X-Client-Request-ID'])
     self.assertIsNotNone(
         self.client.request_history[1].headers['X-Client-Request-ID'])
     self.assertEqual(self.client._create_tender_resource_item.call_count,
                      2)  # check that processed just 1 request
Ejemplo n.º 2
0
 def test_upload_to_doc_service_queue_loop_exit(self, mrequest,
                                                gevent_sleep):
     """ Test LoopExit for upload_to_doc_service_queue """
     gevent_sleep.side_effect = custom_sleep
     self.process_tracker.set_item(self.tender_id, self.award_id, 2)
     self.worker.upload_to_doc_service_queue = MagicMock()
     self.worker.upload_to_doc_service_queue.peek.side_effect = generate_answers(
         answers=[LoopExit(), self.data, self.data], default=LoopExit())
     mrequest.post(self.url, [{
         'json': self.stat_200(),
         'status_code': 200
     } for _ in range(2)])
     self.worker.start()
     sleep(1)
     self.assertEqual(self.upload_to_tender_queue.get(), self.data)
     self.assertIsNotNone(
         mrequest.request_history[0].headers['X-Client-Request-ID'])
     self.assertIsNotNone(
         mrequest.request_history[1].headers['X-Client-Request-ID'])
     self.assertEqual(self.process_tracker.processing_items,
                      {item_key(self.tender_id, self.award_id): 2})
 def test_retry_upload_to_tender_queue_loop_exit(self, gevent_sleep):
     """ Test LoopExit for retry_upload_to_tender_queue """
     gevent_sleep.side_effect = custom_sleep
     self.client._create_tender_resource_item.side_effect = [
         self.get_tender() for _ in range(2)
     ]
     self.worker.retry_upload_to_tender_queue = MagicMock()
     self.worker.retry_upload_to_tender_queue.peek.side_effect = generate_answers(
         answers=[LoopExit(), self.datum(),
                  self.datum()],
         default=LoopExit())
     self.process_tracker.set_item(self.tender_id, self.award_id, 2)
     self.worker.start()
     sleep(1)
     self.worker.shutdown()
     self.assertEqual(self.process_tracker.processing_items, {})
     self.assertIsNotNone(
         self.client.request_history[0].headers['X-Client-Request-ID'])
     self.assertIsNotNone(
         self.client.request_history[1].headers['X-Client-Request-ID'])
     self.assertEqual(self.client._create_tender_resource_item.call_count,
                      2)  # check that processed just 1 request
Ejemplo n.º 4
0
 def test_upload_to_tender_queue_loop_exit(self, mrequest, gevent_sleep):
     """ Test LoopExit for upload_to_tender_queue """
     gevent_sleep.side_effect = custom_sleep
     self.client._create_tender_resource_item.side_effect = [
         self.get_tender() for _ in range(2)
     ]
     self.process_tracker.set_item(self.tender_id, self.award_id, 2)
     self.worker.upload_to_doc_service_queue = Queue(1)
     self.worker.upload_to_tender_queue = MagicMock()
     self.worker.upload_to_tender_queue.peek.side_effect = generate_answers(
         answers=[LoopExit()] + [
             Data(
                 tender_id=self.tender_id,
                 item_id=self.award_id,
                 code='123',
                 item_name='awards',
                 file_content={
                     u'meta': {
                         u'id': self.document_id
                     },
                     u'url':
                     u'http://docs-sandbox.openprocurement.org/get/8ccbfde0c6804143b119d9168452cb6f',
                     u'format': u'application/yaml',
                     u'hash': u'md5:9a0364b9e99bb480dd25e1f0284c8555',
                     u'title': file_name
                 }) for _ in range(2)
         ],
         default=LoopExit())
     self.worker.start()
     sleep(1)
     self.worker.shutdown()
     self.assertEqual(self.process_tracker.processing_items, {})
     self.assertIsNotNone(
         self.client.request_history[0].headers['X-Client-Request-ID'])
     self.assertIsNotNone(
         self.client.request_history[1].headers['X-Client-Request-ID'])
     self.assertEqual(self.client._create_tender_resource_item.call_count,
                      2)  # check that processed just 1 request