Exemplo n.º 1
0
 def test_fill_input_queue(self):
     bridge = EdgeDataBridge(self.config)
     return_value = [
         {'id': uuid.uuid4().hex,
          'dateModified': datetime.datetime.utcnow().isoformat()}
     ]
     bridge.feeder.get_resource_items = MagicMock(return_value=return_value)
     self.assertEqual(bridge.input_queue.qsize(), 0)
     bridge.fill_input_queue()
     self.assertEqual(bridge.input_queue.qsize(), 1)
     self.assertEqual(bridge.input_queue.get(), return_value[0])
Exemplo n.º 2
0
    def test_fill_input_queue(self):
        bridge = EdgeDataBridge(self.config)
        bridge.workers_config['historical'] = True
        mock_api_client = MagicMock()
        client_dict = {
            'id': uuid.uuid4().hex,
            'request_interval': 0.02,
            'client': mock_api_client
        }
        bridge.api_clients_queue.put(client_dict)
        return_value = [{
            'id': uuid.uuid4().hex,
            'dateModified': datetime.datetime.utcnow().isoformat()
        }]
        resource_item_return_value = {
            'id': return_value[0]['id'],
            'x_revision_n': randint(10, 99)
        }

        mock_api_client.get_resource_item_historical.return_value = resource_item_return_value
        bridge.feeder.get_resource_items = MagicMock(return_value=return_value)
        self.assertEqual(bridge.input_queue.qsize(), 0)
        bridge.fill_input_queue()
        self.assertEqual(bridge.resource_items_queue.qsize(),
                         resource_item_return_value['x_revision_n'])

        bridge.resource_items_queue = Queue()
        mock_api_client.get_resource_item_historical.side_effect = RequestFailed(
            munchify({'status_code': 429}))
        bridge.fill_input_queue()
        self.assertEqual(bridge.resource_items_queue.qsize(), 0)

        bridge = EdgeDataBridge(self.config)
        return_value = [{
            'id': uuid.uuid4().hex,
            'dateModified': datetime.datetime.utcnow().isoformat()
        }]
        bridge.feeder.get_resource_items = MagicMock(return_value=return_value)
        self.assertEqual(bridge.input_queue.qsize(), 0)
        bridge.fill_input_queue()
        self.assertEqual(bridge.input_queue.qsize(), 1)
        self.assertEqual(bridge.input_queue.get(), return_value[0])