Skip to content
Snippets Groups Projects
conftest.py 1.77 KiB
Newer Older
  • Learn to ignore specific revisions
  • Swen Vermeul's avatar
    Swen Vermeul committed
    import pytest
    import time
    
    Swen Vermeul's avatar
    Swen Vermeul committed
    import random
    
    Swen Vermeul's avatar
    Swen Vermeul committed
    
    from pybis import Openbis
    
    openbis_url = 'https://localhost:8443'
    admin_username = 'admin'
    admin_password = 'changeit'
    
    
    Swen Vermeul's avatar
    Swen Vermeul committed
    @pytest.yield_fixture(scope="module")
    def url():
        yield openbis_url
    
    @pytest.yield_fixture(scope="module")
    def username():
        yield admin_username
    
    @pytest.yield_fixture(scope="module")
    def password():
        yield admin_password
    
    
    Swen Vermeul's avatar
    Swen Vermeul committed
    @pytest.yield_fixture(scope="module")
    def openbis_instance():
        instance = Openbis(url=openbis_url, verify_certificates=False)
    
    Swen Vermeul's avatar
    Swen Vermeul committed
        instance.login(admin_username, admin_password)
    
    Swen Vermeul's avatar
    Swen Vermeul committed
        print("\nLOGGING IN...")
    
    Swen Vermeul's avatar
    Swen Vermeul committed
        print(instance.is_session_active())
    
    Swen Vermeul's avatar
    Swen Vermeul committed
    
        timestamp = time.strftime('%a_%y%m%d_%H%M%S').upper()
        space_code = 'test_space_' + timestamp
        space = instance.new_space(code=space_code)
        space.save()
    
        project_code = "TEST-PROJECT-{:04d}".format(random.randint(0, 9999))
        project = instance.new_project(code=project_code, space=space)
        project.save()
    
        experiment_code = "TEST-EXPERIMENT-{:04d}".format(random.randint(0, 9999))
    
    Swen Vermeul's avatar
    Swen Vermeul committed
        experiment = instance.new_experiment(
            code=experiment_code,
            type='DEFAULT_EXPERIMENT',
            project=project,
        )
    
    Swen Vermeul's avatar
    Swen Vermeul committed
        experiment.save()
    
        sample_code = "TEST-SAMPLE-{:04d}".format(random.randint(0, 9999))
    
    Swen Vermeul's avatar
    Swen Vermeul committed
        sample = instance.new_sample(
            code=sample_code, 
            type='UNKNOWN',
            space=space, 
            experiment=experiment,
        )
    
    Swen Vermeul's avatar
    Swen Vermeul committed
        sample.save()
    
        instance.login(admin_username, admin_password)
    
        yield instance
    
        # cleanup after tests have been running
        sample.delete("test on {}".format(timestamp))
        experiment.delete("test on {}".format(timestamp))
        project.delete("test on {}".format(timestamp))
        space.delete("test on {}".format(timestamp))
        instance.logout()
        print("LOGGED OUT...")