Exemplo n.º 1
0
def test_update(app, es_clear, operation_log_data, monkeypatch):
    """Test update log."""
    operation_log = OperationLog.create(deepcopy(operation_log_data),
                                        index_refresh='wait_for')

    log_data = OperationLog.get_record(operation_log.id)
    assert log_data['record']['value'] == 'item4'

    # Update OK
    log_data['record']['value'] = '1234'
    OperationLog.update(log_data.id, log_data['date'], log_data)
    log_data = OperationLog.get_record(operation_log.id)
    assert log_data['record']['value'] == '1234'

    # Update KO
    monkeypatch.setattr(
        'elasticsearch_dsl.Document.update', lambda *args, **kwargs: 'error')
    with pytest.raises(Exception) as exception:
        OperationLog.update(log_data.id, log_data['date'], log_data)
        assert str(exception) == 'Operation log cannot be updated.'
Exemplo n.º 2
0
def test_operation_create(client, es_clear, operation_log_data):
    """Test operation logs creation."""
    oplg = OperationLog.create(operation_log_data, index_refresh='wait_for')
    assert oplg
    assert oplg.id
    # need to compare with dumps as it has resolve $refs
    data = OperationLog.get_record(oplg.id)
    del data['_created']
    del data['_updated']
    assert data == OperationLog(operation_log_data).dumps()
    tmp = deepcopy(operation_log_data)
    tmp['date'] = '2020-01-21T09:51:52.879533+00:00'
    oplg2 = OperationLog.create(tmp, index_refresh='wait_for')
    assert OperationLog.get_indices() == set((
        'operation_logs-2020',
        f'operation_logs-{datetime.now().year}'
    ))
    assert OperationLog.get_record(oplg.id)
    assert OperationLog.get_record(oplg2.id)
    # clean up the index
    assert OperationLog.delete_indices()