def test_generate_error(self, mock_elastic, mock_process, mock_stream):
     inst = ESConnection()
     try:
         inst.generateRecords('session')
     except ESError:
         pass
     self.assertRaises(ESError)
 def test_process(self, mock_elastic, mock_index, mock_retrieve):
     mock_retrieve.return_value = ['work1', 'work2', 'work3']
     with patch('lib.esManager.ESDoc.createWork') as mock_create:
         mock_dict = MagicMock()
         mock_dict.to_dict.side_effect = ['work1', 'work2', 'work3']
         mock_create.return_value = mock_dict
         inst = ESConnection()
         res = list(inst.process('session'))
         self.assertEqual(res, ['work1', 'work2', 'work3'])
예제 #3
0
def indexRecords():
    """Processes the modified database records in the given period. Records are
    retrieved from the db, transformed into the ElasticSearch model and 
    processed in batches of 100. Errors are caught and logged within the ES
    model.
    """
    logger.info('Creating connection to ElasticSearch index')
    es = ESConnection()

    logger.info('Creating postgresql session')
    session = MANAGER.createSession()

    logger.info('Loading recently updated records')
    es.generateRecords(session)

    logger.info('Close postgresql session')
    MANAGER.closeConnection()
예제 #4
0
def parseRecords(records):
    """Simple method to parse list of records and process each entry."""
    logger.debug('Parsing Queue Messages')

    esConn = ESConnection()

    updates = [parseRecord(r) for r in records]

    MANAGER.closeConnection()

    return updates
 def test_generate_failure(self, mock_elastic, mock_process, mock_stream):
     inst = ESConnection()
     inst.generateRecords('session')
     mock_stream.assert_has_calls([call(TestESManager.client_mock, 1)])
    def test_index_exists(self, mock_elastic, mock_instance, mock_work):

        inst = ESConnection()
        self.assertIsInstance(inst.client, MagicMock)
        mock_work.init.assert_not_called()
 def test_connection_err(self, mock_index, mock_instance, mock_elastic):
     with self.assertRaises(ESError):
         inst = ESConnection()
 def test_connection_create(self, mock_index, mock_instance, mock_elastic):
     inst = ESConnection()
     self.assertEqual(inst.client, 'default')
 def test_class_create(self, mock_index, mock_connection):
     inst = ESConnection()
     self.assertIsInstance(inst, ESConnection)
     self.assertEqual(inst.index, 'test')
예제 #10
0
 def test_generate_error(self, mock_elastic, mock_process, mock_stream):
     inst = ESConnection()
     with pytest.raises(ESError):
         inst.generateRecords('session')
예제 #11
0
 def test_index_create(self, mock_elastic, mock_instance, mock_work):
     
     inst = ESConnection()
     assert isinstance(inst.client, MagicMock)
     mock_work.init.assert_called_once()
예제 #12
0
 def test_connection_create(self, mock_index, mock_instance, mock_elastic):
     inst = ESConnection()
     assert inst.client == 'default'
예제 #13
0
 def test_class_create(self, mock_index, mock_connection):
     inst = ESConnection()
     assert isinstance(inst, ESConnection)
     assert inst.index == 'test'