예제 #1
0
 def test_worker_award_with_cancelled_lot(self, gevent_sleep):
     gevent_sleep.side_effect = custom_sleep
     self.client.request.return_value = ResponseMock(
         {'X-Request-ID': self.request_ids[0]},
         munchify({'prev_page': {'offset': '123'},
                   'next_page': {'offset': '1234'},
                   'data': {'status': tender_status,
                            'id': self.tender_id,
                            'procurementMethodType': 'aboveThresholdEU',
                            'lots': [{'status': 'cancelled', 'id': '123456789'},
                                     {'status': 'active', 'id': '12345678'}],
                            'awards': [{'id': self.award_ids[0],
                                        'bid_id': self.bid_ids[0],
                                        'status': AWARD_STATUS,
                                        'suppliers': [{'identifier': {'scheme': 'UA-EDR', 'id': CODES[0],
                                                                      "legalName": "company_name"}}],
                                        'lotID': '12345678'},
                                       {'id': self.award_ids[1],
                                        'bid_id': self.bid_ids[1],
                                        'status': 'cancelled',
                                        'suppliers': [{'identifier': {'scheme': 'UA-EDR', 'id': CODES[1],
                                                                      "legalName": "company_name"}}],
                                        'lotID': '123456789'}]}}))
     data = Data(self.tender_id, self.award_ids[0], CODES[0], "company_name",
                 {"meta": {"sourceRequests": [self.request_ids[0]]}})
     self.assertEqual(self.edrpou_codes_queue.get(), data)
     self.assertItemsEqual(self.process_tracker.processing_items.keys(),
                           [item_key(self.tender_id, self.award_ids[0])])
예제 #2
0
 def test_award_not_valid_identifier_id(self, gevent_sleep):
     gevent_sleep.side_effect = custom_sleep
     self.client.request.return_value = ResponseMock(
         {'X-Request-ID': self.request_ids[0]},
         munchify({'prev_page': {'offset': '123'},
                   'next_page': {'offset': '1234'},
                   'data': {'status': tender_status,
                            'id': self.tender_id,
                            'procurementMethodType': 'aboveThresholdEU',
                            'awards': [self.awards(0, 0, AWARD_STATUS, '')]}}))
     sleep(1)
     self.assertEqual(self.edrpou_codes_queue.qsize(), 0)
     self.assertItemsEqual(self.process_tracker.processing_items, {})
예제 #3
0
 def test_request_failed(self, gevent_sleep):
     gevent_sleep.side_effect = custom_sleep
     self.client.request.side_effect = [
         RequestFailed(http_code=401, msg=RequestFailed()),
         ResponseMock({'X-Request-ID': self.request_ids[0]},
                      munchify({'prev_page': {'offset': '123'},
                                'next_page': {'offset': '1234'},
                                'data': {'status': tender_status,
                                         'id': self.tender_id,
                                         'procurementMethodType': 'aboveThresholdEU',
                                         'awards': [self.awards(0, 0, AWARD_STATUS, '')]}}))]
     sleep(1)
     self.assertEqual(self.client.request.call_count, 2)
     self.assertEqual(self.edrpou_codes_queue.qsize(), 0)
     self.assertItemsEqual(self.process_tracker.processing_items, {})
예제 #4
0
 def test_worker_dead(self, gevent_sleep):
     """ Test that worker will process tender after exception  """
     gevent_sleep.side_effect = custom_sleep
     self.filtered_tender_ids_queue.put(self.tender_id)
     self.client.request.side_effect = [
         ResponseMock({'X-Request-ID': self.request_ids[i]},
                      munchify({'prev_page': {'offset': '123'},
                                'next_page': {'offset': '1234'},
                                'data': {
                                    'status': tender_status,
                                    'id': self.tender_id,
                                    'procurementMethodType': 'aboveThresholdEU',
                                    'awards': [self.awards(i, i, AWARD_STATUS, CODES[0])]}})) for i in range(2)]
     for i in range(2):
         data = Data(self.tender_id, self.award_ids[i], CODES[0], "company_name",
                     {"meta": {"sourceRequests": [self.request_ids[i]]}})
         self.assertEqual(self.edrpou_codes_queue.get(), data)
     self.worker.immortal_jobs['prepare_data'].kill(timeout=1)
     self.assertItemsEqual(self.process_tracker.processing_items.keys(),
                           [item_key(self.tender_id, self.award_ids[i]) for i in range(2)])
예제 #5
0
 def test_worker_restart(self, gevent_sleep):
     """ Process tender after catch Unauthorized exception """
     gevent_sleep.side_effect = custom_sleep
     self.client.request.side_effect = [
         Unauthorized(http_code=403),
         Unauthorized(http_code=403),
         Unauthorized(http_code=403),
         ResponseMock({'X-Request-ID': self.request_ids[0]},
                      munchify({'prev_page': {'offset': '123'},
                                'next_page': {'offset': '1234'},
                                'data': {'status': tender_status,
                                         'id': self.tender_id,
                                         'procurementMethodType': 'aboveThresholdEU',
                                         'awards': [self.awards(0, 0, AWARD_STATUS, CODES[0]),
                                                    self.awards(1, 1, 'unsuccessful', CODES[2])]}}))]
     data = Data(self.tender_id, self.award_ids[0], CODES[0], "company_name",
                 {"meta": {"sourceRequests": [self.request_ids[0]]}})
     self.assertEqual(self.edrpou_codes_queue.get(), data)
     self.assertItemsEqual(self.process_tracker.processing_items.keys(),
                           [item_key(self.tender_id, self.award_ids[0])])
예제 #6
0
 def test_worker_award(self, gevent_sleep):
     gevent_sleep.side_effect = custom_sleep
     self.client.request.side_effect = [
         ResponseMock({'X-Request-ID': self.request_ids[0]},
                      munchify({'prev_page': {'offset': '123'},
                                'next_page': {'offset': '1234'},
                                'data': {'status': "active.pre-qualification",
                                         'id': self.tender_id,
                                         'procurementMethodType': 'aboveThresholdEU',
                                         'awards': [
                                             self.awards(0, 0, AWARD_STATUS, CODES[0]),
                                             self.awards(3, 3, 'unsuccessful', CODES[2]),
                                             {'id': self.bid_ids[4],
                                              'tenderers': [{'identifier': {
                                                  'scheme': 'UA-ED',
                                                  'id': CODES[2],
                                                  "name": "company_name"}}]}]}}))]
     data = Data(self.tender_id, self.award_ids[0], CODES[0], "company_name",
                 {"meta": {"sourceRequests": [self.request_ids[0]]}})
     self.assertEqual(self.edrpou_codes_queue.get(), data)
     self.assertItemsEqual(self.process_tracker.processing_items.keys(),
                           [item_key(self.tender_id, self.award_ids[0])])
예제 #7
0
 def setUp(self):
     self.filtered_tender_ids_queue = Queue(10)
     self.edrpou_codes_queue = Queue(10)
     self.process_tracker = ProcessTracker()
     self.tender_id = uuid.uuid4().hex
     self.filtered_tender_ids_queue.put(self.tender_id)
     self.sleep_change_value = APIRateController()
     self.client = MagicMock()
     self.sna = event.Event()
     self.sna.set()
     self.worker = FilterTenders.spawn(self.client, self.filtered_tender_ids_queue, self.edrpou_codes_queue,
                                       self.process_tracker, self.sna, self.sleep_change_value)
     self.bid_ids = [uuid.uuid4().hex for _ in range(5)]
     self.qualification_ids = [uuid.uuid4().hex for _ in range(5)]
     self.award_ids = [uuid.uuid4().hex for _ in range(5)]
     self.request_ids = [generate_request_id() for _ in range(2)]
     self.response = ResponseMock({'X-Request-ID': self.request_ids[0]},
                                  munchify({'prev_page': {'offset': '123'},
                                            'next_page': {'offset': '1234'},
                                            'data': {'status': tender_status,
                                                     'id': self.tender_id,
                                                     'procurementMethodType': 'aboveThresholdEU',
                                                     'awards': [self.awards(0, 0, AWARD_STATUS, CODES[0])]}}))