Skip to content

Commit

Permalink
Testing: Bin Tests use fixtures; Fix #6529
Browse files Browse the repository at this point in the history
  • Loading branch information
voetberg committed Jun 21, 2024
1 parent ba10250 commit f84a8c3
Show file tree
Hide file tree
Showing 2 changed files with 2,189 additions and 2,338 deletions.
105 changes: 104 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@

import pytest

from rucio.common.types import InternalScope
from rucio.common.utils import generate_uuid
from rucio.tests.common import did_name_generator

_del_test_prefix = functools.partial(re.compile(r'^[Tt][Ee][Ss][Tt]_?').sub, '')
# local imports in the fixtures to make this file loadable in e.g. client tests

Expand All @@ -29,7 +33,7 @@

def pytest_configure(config):
config.addinivalue_line('markers', 'dirty: marks test as dirty, i.e. tests are leaving structures behind')
config.addinivalue_line('markers', 'noparallel(reason, groups): marks test being unable to run in parallel to other tests' )
config.addinivalue_line('markers', 'noparallel(reason, groups): marks test being unable to run in parallel to other tests')

if config.pluginmanager.hasplugin("xdist"):
from .ruciopytest import xdist_noparallel_scheduler
Expand Down Expand Up @@ -586,3 +590,102 @@ def metrics_mock():
mock.patch('rucio.core.monitor.TIMINGS', new={}), \
mock.patch('prometheus_client.values.ValueClass', new=values.MutexValue):
yield registry


@pytest.fixture
def account_name_generator():
from rucio.common.utils import generate_uuid
return lambda: 'jdoe-' + str(generate_uuid()).lower()[:16]


@pytest.fixture
def scope_name_generator():
from rucio.common.utils import generate_uuid
return lambda: 'mock_' + str(generate_uuid()).lower()[:16]


@pytest.fixture
def rse_name_generator():
def generator(size=10):
return 'MOCK-' + ''.join(choice(ascii_uppercase) for _ in range(size))
return generator


@pytest.fixture
def client_rse_factory(rse_client, rse_name_generator):
"""
Makes an rse factory that does not require a new db session
"""
class MockRSEFactory:
@staticmethod
def make_posix_rse():
rse_name = rse_name_generator()
rse_client.add_rse(rse_name)
def_rse_id = rse_client.get_rse(rse=rse_name)['id']

protocol_parameters = {
'scheme': "file",
'hostname': '%s.cern.ch' % def_rse_id,
'port': 0,
'prefix': '/test_%s/' % def_rse_id,
'impl': 'rucio.rse.protocols.posix.Default',
'domains': {
'wan': {
'read': 1,
'write': 1,
'delete': 1,
'third_party_copy_read': 1,
'third_party_copy_write': 1,
},
'lan': {
'read': 1,
'write': 1,
'delete': 1,
}
}
}
rse_client.add_protocol(rse_name, protocol_parameters)
return rse_name, def_rse_id

yield MockRSEFactory


@pytest.fixture
def client_dataset_factory(file_factory, rucio_client, mock_scope, vo):
"""Make and upload a dataset without a db session"""
class MockDatasetFactory:
@staticmethod
def upload_test_dataset(rse_name, name=None, scope=None, size=2, nb_files=2):
from rucio.client.uploadclient import UploadClient

if not scope:
scope = mock_scope
elif isinstance(scope, str):
scope = InternalScope(scope, vo=vo)

dataset_name = did_name_generator('dataset')
upload_items = []
dataset_files = []

for _ in range(0, nb_files):

path = file_factory.file_generator(size=size)
name = did_name_generator('file')

dataset_files.append({
"name": name,
"scope": scope,
"bytes": 1})
upload_items.append({
'path': path,
'rse': rse_name,
'dataset_scope': str(scope),
'dataset_name': dataset_name,
'did_scope': str(scope),
'did_name': name,
'guid': generate_uuid()})

UploadClient(rucio_client).upload(upload_items)
return upload_items

yield MockDatasetFactory
Loading

0 comments on commit f84a8c3

Please sign in to comment.