<commit_before>from doct import Document
import time as ttime
import pytest
from conftrak.testing import conftrak_setup, conftrak_teardown
from conftrak.client.api import ConfigurationReference
from requests.exceptions import HTTPError, RequestException
from conftrak.testing import TESTING_CONFIG

import uuid

configs_uids = []
document_insertion_times = []


@pytest.fixture(scope='function')
def config_ref():
    c = ConfigurationReference()
    c.host = TESTING_CONFIG['host']
    c.port = TESTING_CONFIG['port']
    return c


def teardown():
    conftrak_teardown()


def test_configuration_constructor():
    c2 = ConfigurationReference()


def test_connection_switch():
    c = ConfigurationReference()
    c.host = 'blah'
    pytest.raises(RequestException, c.create, 'test_beamline')
    c.host = TESTING_CONFIG['host']
    c.create(beamline_id='lix')


def test_configuration_create(config_ref):
    c1 = config_ref.create(beamline_id='test')
    c2 = config_ref.create(beamline_id='test', uid=str(uuid.uuid4()))
    c_kwargs = dict(key='detector', params={'model':'Pilatus1M',
                                            'vendor':'Dectris'})
    c3 = config_ref.create(beamline_id='test', **c_kwargs)


def test_configuration_find(config_ref):
    config_data = dict(beamline_id='test_bl', uid=str(uuid.uuid4()),
                       active=True, time= ttime.time(),key='test_config',
                       params=dict(param1='test1', param2='test2'))

    config_ref.create(**config_data)
    c_ret = next(config_ref.find(uid=config_data['uid'], as_document=True))
    assert c_ret == Document('Configuration', config_data)


def test_configuration_update(config_ref):
    config_data = dict(beamline_id='test_bl', uid=str(uuid.uuid4()),
                       active=True, time= ttime.time(),key='test_config',
                       params=dict(param1='test1', param2='test2'))
    config_ref.create(**config_data)
    config_ref.update(query={'uid': config_data['uid']},
                      update={'key': 'updated_key'})
    updated_conf = next(config_ref.find(uid=config_data['uid']))
    assert updated_conf['key'] == 'updated_key'

def test_configuration_delete(config_ref):
    assert False


def test_configuration_find_all(config_ref):
    assert False

<commit_msg>Finished adding tests.<commit_after>from doct import Document
import time as ttime
import pytest
from conftrak.testing import conftrak_setup, conftrak_teardown
from conftrak.client.api import ConfigurationReference
from requests.exceptions import HTTPError, RequestException
from conftrak.testing import TESTING_CONFIG

import uuid

configs_uids = []
document_insertion_times = []


@pytest.fixture(scope='function')
def config_ref():
    c = ConfigurationReference()
    c.host = TESTING_CONFIG['host']
    c.port = TESTING_CONFIG['port']
    return c


def teardown():
    conftrak_teardown()


def test_configuration_constructor():
    c2 = ConfigurationReference()


def test_connection_switch():
    c = ConfigurationReference()
    c.host = 'blah'
    pytest.raises(RequestException, c.create, 'test_beamline')
    c.host = TESTING_CONFIG['host']
    c.create(beamline_id='lix')


def test_configuration_create(config_ref):
    c1 = config_ref.create(beamline_id='test')
    c2 = config_ref.create(beamline_id='test', uid=str(uuid.uuid4()))
    c_kwargs = dict(key='detector', params={'model':'Pilatus1M',
                                            'vendor':'Dectris'})
    c3 = config_ref.create(beamline_id='test', **c_kwargs)


def test_configuration_find(config_ref):
    config_data = dict(beamline_id='test_bl', uid=str(uuid.uuid4()),
                       active=True, time= ttime.time(),key='test_config',
                       params=dict(param1='test1', param2='test2'))

    config_ref.create(**config_data)
    c_ret = next(config_ref.find(uid=config_data['uid'], as_document=True))
    assert c_ret == Document('Configuration', config_data)


def test_configuration_update(config_ref):
    config_data = dict(beamline_id='test_bl', uid=str(uuid.uuid4()),
                       active=True, time= ttime.time(),key='test_config',
                       params=dict(param1='test1', param2='test2'))
    config_ref.create(**config_data)
    config_ref.update(query={'uid': config_data['uid']},
                      update={'key': 'updated_key'})
    updated_conf = next(config_ref.find(uid=config_data['uid']))
    assert updated_conf['key'] == 'updated_key'


def test_configuration_delete(config_ref):
    config_data = dict(beamline_id='test_bl', uid=str(uuid.uuid4()),
                       active=True, time= ttime.time(),key='test_config',
                       params=dict(param1='test1', param2='test2'))
    config_ref.create(**config_data)
    inserted = next(config_ref.find(uid=config_data['uid']))
    # Make sure that it was inserted
    assert inserted is not None
    config_ref.delete([config_data['uid']])
    with pytest.raises(StopIteration):
        deleted = next(config_ref.find(uid=config_data['uid']))


def test_configuration_find_all(config_ref):
    config_data = dict(beamline_id='test_bl', uid=str(uuid.uuid4()),
                       active=True, time= ttime.time(),key='test_config',
                       params=dict(param1='test1', param2='test2'))
    config_ref.create(**config_data)
    inserted = next(config_ref.find(uid=config_data['uid']))
    # Make sure that it was inserted
    assert inserted is not None
    config_ref.delete([config_data['uid']])
    deleted = next(config_ref.find(uid=config_data['uid'], active_only=False))
    assert deleted is not None

{'fraction_non_alphanumeric': 0.1299786628733997, 'fraction_numerical': 0.007467994310099573, 'mean_word_length': 3.9559471365638768, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5553599', 'n_tokens_mistral': 1780, 'n_tokens_neox': 1741, 'n_words': 300}