def test_synchronize_cadi_entries_when_entry_doesnt_exist_creates_a_new_one(mock_parse_cadi_enty,
                                  mock_get_all_from_cadi,
                                  app, es, location, create_schema):
    schema = create_schema('deposits/records/cms-analysis-v0.0.1', experiment='CMS')
    role = assign_egroup_to_experiment('*****@*****.**', 'CMS')

    # deposit with this cadi id doesn't exist
    with raises(DepositDoesNotExist):
        get_deposit_by_cadi_id('ANA-00-001')

    synchronize_cadi_entries()

    current_search.flush_and_refresh('deposits-records')  

    # deposit with this cadi id created
    deposit = get_deposit_by_cadi_id('ANA-00-001')

    assert deposit['cadi_info'] == {'status': 'Free'}  # sets cadi info correctly
    assert deposit['basic_info']['cadi_id'] == 'ANA-00-001'  # sets cadi id
    assert deposit['general_title'] == 'ANA-00-001'

    # members of experiment got read access
    assert deposit['_access']['deposit-read'] == {'users': [],'roles': [role.id]}
    assert deposit['_access']['deposit-update'] == {'users': [], 'roles': []}
    assert deposit['_access']['deposit-admin'] == {'users': [], 'roles': []}

    # deposit doesnt have owner
    assert deposit['_deposit']['owners'] == []
Exemplo n.º 2
0
def test_get_deposit_by_cadi_id_when_no_match_raises_DepositDoesNotExist(
        app, es, create_deposit, superuser):
    create_deposit(superuser,
                   'cms-analysis', {
                       '$ana_type': 'cms-analysis',
                       'basic_info': {
                           'cadi_id': 'EXO-00-001'
                       }
                   },
                   mapping={
                       'mappings': {
                           'cms-analysis-v1.0.0': {
                               'properties': {
                                   "basic_info": {
                                       "type": "object",
                                       "properties": {
                                           "cadi_id": {
                                               "type": "keyword"
                                           }
                                       }
                                   }
                               }
                           }
                       }
                   })

    with raises(DepositDoesNotExist):
        get_deposit_by_cadi_id('EXO-00-002')
Exemplo n.º 3
0
def test_synchronize_cadi_entries_when_entry_exist_updates_cadi_info(
        appctx, db, es, superuser, create_deposit):
    create_deposit(
        superuser, 'cms-analysis', {
            'version': '0.0.1',
            '$ana_type': 'cms-analysis',
            'basic_info': {
                'cadi_id': 'ANA-00-001'
            }
        })

    # deposit with this cadi id already exists
    deposit = get_deposit_by_cadi_id('ANA-00-001')
    synchronize_cadi_entries()

    # deposit with this cadi id created
    updated_deposit = get_deposit_by_cadi_id('ANA-00-001')

    assert updated_deposit['cadi_info'] == {
        u'cadi_id': u'ANA-00-001',
        u'contact': u'',
        u'created': u'',
        u'description': u'',
        u'name': u'',
        u'paper': u'',
        u'pas': u'',
        u'publication_status': u'',
        u'status': u'Free',
        u'twiki': u''
    }  # sets cadi info correctly
    assert updated_deposit['_access'] == deposit[
        '_access']  # access didnt change
    assert updated_deposit['_deposit']['owners'] == deposit['_deposit'][
        'owners']  # deposit owner didn't change
def test_get_deposit_by_cadi_id_when_no_match_raises_DepositDoesNotExist(app, es, create_deposit, superuser):
    create_deposit(superuser, 'cms-analysis-v0.0.1', {
        '$ana_type': 'cms-analysis',
        'basic_info': { 'cadi_id': 'ANA-00-001' }
    })

    with raises(DepositDoesNotExist):
        get_deposit_by_cadi_id('ANA-00-002')
Exemplo n.º 5
0
def test_synchronize_cadi_entries_when_LDAP_error_occured_during_permissions_assigning_entry_was_not_saved_in_db_or_es(
        base_app, db, es, location, create_schema):
    create_schema('cms-analysis', experiment='CMS', version='0.0.1')

    synchronize_cadi_entries()

    current_search.flush_and_refresh('deposits-records')

    with raises(DepositDoesNotExist):
        get_deposit_by_cadi_id('EXO-00-001')
Exemplo n.º 6
0
def test_get_deposit_by_cadi_id_when_no_match_raises_DepositDoesNotExist(
        app, es, create_deposit, superuser):
    create_deposit(superuser, 'cms-analysis', {
        '$ana_type': 'cms-analysis',
        'basic_info': {
            'cadi_id': 'ANA-00-001'
        }
    })

    with raises(DepositDoesNotExist):
        get_deposit_by_cadi_id('ANA-00-002')
Exemplo n.º 7
0
def test_get_deposit_by_cadi_id_returns_correct_deposit(
        app, es, create_deposit, superuser):
    cadi_id = 'EXO-00-001'
    deposit = create_deposit(superuser,
                             'cms-analysis', {
                                 '$ana_type': 'cms-analysis',
                                 'basic_info': {
                                     'cadi_id': cadi_id
                                 }
                             },
                             mapping={
                                 'mappings': {
                                     'cms-analysis-v1.0.0': {
                                         'properties': {
                                             "basic_info": {
                                                 "type": "object",
                                                 "properties": {
                                                     "cadi_id": {
                                                         "type": "keyword"
                                                     }
                                                 }
                                             }
                                         }
                                     }
                                 }
                             })
    create_deposit(superuser, 'cms-analysis', {
        '$ana_type': 'cms-analysis',
        'basic_info': {
            'cadi_id': 'EXO-00-002'
        }
    })

    assert get_deposit_by_cadi_id(cadi_id) == deposit
Exemplo n.º 8
0
def test_synchronize_cadi_entries_when_entry_doesnt_exist_creates_a_new_one(
        base_app, es, location, create_schema):
    create_schema('cms-analysis', experiment='CMS', version='0.0.1')
    group_with_r_access = assign_egroup_to_experiment('*****@*****.**',
                                                      'CMS')
    group_with_rw_access = _datastore.find_or_create_role(
        '*****@*****.**')

    # deposit with this cadi id doesn't exist
    with raises(DepositDoesNotExist):
        get_deposit_by_cadi_id('ANA-00-001')

    synchronize_cadi_entries()

    current_search.flush_and_refresh('deposits-records')

    # deposit with this cadi id created
    deposit = get_deposit_by_cadi_id('ANA-00-001')

    assert deposit['cadi_info'] == {
        'cadi_id': 'ANA-00-001',
        'contact': '',
        'created': '',
        'description': '',
        'name': '',
        'paper': '',
        'pas': '',
        'publication_status': '',
        'status': 'Free',
        'twiki': ''
    }  # sets cadi info correctly
    assert deposit['basic_info']['cadi_id'] == 'ANA-00-001'  # sets cadi id
    assert deposit['general_title'] == 'ANA-00-001'

    # members of experiment got read access and cms-cap-admin egroup write access
    assert deposit['_access']['deposit-read'] == {
        'users': [],
        'roles': [group_with_r_access.id, group_with_rw_access.id]
    }
    assert deposit['_access']['deposit-update'] == {
        'users': [],
        'roles': [group_with_rw_access.id]
    }
    assert deposit['_access']['deposit-admin'] == {'users': [], 'roles': []}

    # deposit doesnt have owner
    assert deposit['_deposit']['owners'] == []
def test_synchronize_cadi_entries_when_entry_exist_updates_cadi_info(mock_parse_cadi_enty,
                                  mock_get_all_from_cadi,
                                  appctx, db, es, superuser, create_deposit):
    create_deposit(superuser, 'cms-analysis-v0.0.1', {
        '$ana_type': 'cms-analysis',
        'basic_info': { 'cadi_id': 'ANA-00-001' }
    })

    # deposit with this cadi id already exists
    deposit = get_deposit_by_cadi_id('ANA-00-001')

    synchronize_cadi_entries()

    # deposit with this cadi id created
    updated_deposit = get_deposit_by_cadi_id('ANA-00-001')

    assert updated_deposit['cadi_info'] == {'status': 'Free'}  # sets cadi info correctly
    assert updated_deposit['_access'] == deposit['_access'] # access didnt change 
    assert updated_deposit['_deposit']['owners'] == deposit['_deposit']['owners'] # deposit owner didn't change
def test_get_deposit_by_cadi_id_returns_correct_deposit(app, es, create_deposit, superuser):
    cadi_id = 'ANA-00-001'
    deposit = create_deposit(superuser, 'cms-analysis-v0.0.1', {
        '$ana_type': 'cms-analysis',
        'basic_info': { 'cadi_id': cadi_id }
    })
    create_deposit(superuser, 'cms-analysis-v0.0.1', {
        '$ana_type': 'cms-analysis',
        'basic_info': { 'cadi_id': 'ANA-00-002' }
    })

    assert get_deposit_by_cadi_id(cadi_id) == deposit
Exemplo n.º 11
0
def test_get_deposit_by_cadi_id_returns_correct_deposit(
        app, es, create_deposit, superuser):
    cadi_id = 'ANA-00-001'
    deposit = create_deposit(superuser, 'cms-analysis', {
        '$ana_type': 'cms-analysis',
        'basic_info': {
            'cadi_id': cadi_id
        }
    })
    create_deposit(superuser, 'cms-analysis', {
        '$ana_type': 'cms-analysis',
        'basic_info': {
            'cadi_id': 'ANA-00-002'
        }
    })

    assert get_deposit_by_cadi_id(cadi_id) == deposit
Exemplo n.º 12
0
def keywords(file):
    """Load CADI keywords and print not found IDs in a file."""
    data = extract_keywords_from_excel(file)
    not_found = []

    for item in data:
        cadi_id = item['cadi_id']
        del item['cadi_id']

        try:
            deposit = get_deposit_by_cadi_id(cadi_id)
            deposit['basic_info']['analysis_keywords'] = item

            deposit.commit()
            db.session.commit()
            click.secho(f"CADI ID {cadi_id} was successful.", fg='green')

        except DepositDoesNotExist:
            not_found.append(cadi_id)
            click.secho(f"CADI ID {cadi_id} not found.", fg='red')

        except DepositValidationError as e:
            errors = [err.res for err in e.errors]
            errors_str = ""
            try:
                errors_str = str(errors)
            except Exception:
                errors_str = "Can't tranform to string value"
            click.secho(f"CADI ID {cadi_id} - Validation Error on:", fg='red')
            click.secho(errors_str, fg='red')

    # write_path = os.path.join(os.getcwd(), 'not-found.txt')
    # with open(write_path, 'w') as out_file:
    #     out_file.writelines(
    #         f'{cadi_id}\n' for cadi_id in not_found
    #     )

    click.secho("Keywords extracted and saved.", fg='green')
Exemplo n.º 13
0
def test_synchronize_cadi_entries_when_entry_exist_updates_cadi_info(
        appctx, db, es, superuser, create_deposit):
    create_deposit(
        superuser, 'cms-analysis', {
            'version': '0.0.1',
            '$ana_type': 'cms-analysis',
            'basic_info': {
                'cadi_id': 'EXO-00-001'
            }
        })

    # deposit with this cadi id already exists
    deposit = get_deposit_by_cadi_id('EXO-00-000')

    synchronize_cadi_entries()

    updated_deposit = get_deposit_by_cadi_id('EXO-00-000')

    assert updated_deposit == {
        'version': '0.0.1',
        'basic_info': {
            'cadi_id': 'EXO-00-001'
        },
        '_deposit': {
            'id': deposit['_deposit']['id'],
            'status': 'draft',
            'owners': [superuser.id],
            'created_by': superuser.id
        },
        '$schema':
        'https://analysispreservation.cern.ch/schemas/deposits/records/cms-analysis-v1.0.0.json',
        '_experiment': None,
        '_access': {
            'deposit-read': {
                'users': [superuser.id],
                'roles': []
            },
            'deposit-update': {
                'users': [superuser.id],
                'roles': []
            },
            'deposit-admin': {
                'users': [superuser.id],
                'roles': []
            }
        },
        '_user_edited': True,
        '_files': [],
        'cadi_info': {
            'status': 'PUB',
            'contact': '*****@*****.**',
            'creator': '*****@*****.**',
            'publication_status': 'Free',
            'twiki': 'https://twiki.cern.ch/twikiurl',
            'pas': '******',
            'name': '2HDM Higgs studies (H->ZZ and A->Zh)',
            'description': 'Projections for 2HDM Higgs studies',
            'created': '2014-02-05',
            'updated': '2014-07-26',
            'updater': '',
            'awg': '', 'conference': '',
            'paper': 'http://cms.cern.ch:80/paper.pdf',
            'paper_tar': 'http://cms.cern.ch:80/paper.tgz',
            'hepData': ''
        }
    }
Exemplo n.º 14
0
def test_synchronize_cadi_entries_when_entry_doesnt_exist_creates_a_new_one_and_assigns_all_the_permissions_correctly(
        base_app, db, es, location, create_schema):
    create_schema('cms-analysis', experiment='CMS', version='0.0.1')

    owner = create_test_user('*****@*****.**')
    cms_members_group_with_r_access = assign_egroup_to_experiment(
        '*****@*****.**', 'CMS')
    cms_admin_groups_with_admin_access = [
        _datastore.find_or_create_role('*****@*****.**'),
        _datastore.find_or_create_role('*****@*****.**'),
        _datastore.find_or_create_role('*****@*****.**'),
    ]
    db.session.commit()

    # deposit with this cadi id doesn't exist
    with raises(DepositDoesNotExist):
        get_deposit_by_cadi_id('EXO-00-000')

    synchronize_cadi_entries()

    current_search.flush_and_refresh('deposits-records')

    # deposit with this cadi id created
    deposit = get_deposit_by_cadi_id('EXO-00-000')

    assert deposit == {
        'cadi_info': {
            'description':
            'Projections for 2HDM Higgs studies (H->ZZ and A->Zh) in 3000 fb-1',
            'name':
            '2HDM Higgs studies (H->ZZ and A->Zh)',
            'contact':
            '*****@*****.**',
            'creator':
            '*****@*****.**',
            'updater':
            '*****@*****.**',
            'created':
            '2014-02-05',
            'updated':
            '2014-07-26',
            'twiki':
            'https://twiki.cern.ch/twikiurl',
            'paper':
            'http://cms.cern.ch:80/paper.pdf',
            'paper_tar':
            'http://cms.cern.ch:80/paper.tgz',
            'pas':
            '******',
            'awg':
            'HIG',
            'publication_status':
            'Free',
            'status':
            'PUB',
            'conference':
            '',
            'hepData':
            '',
            'relatedNotes': [{
                'id':
                'AN-2014/000',
                'url':
                'http://cms.cern.ch/noteInfo.jsp?cmsnoteid=CMS+AN-2014%2F000'
            }, {
                'id':
                'AN-2013/000',
                'url':
                'http://cms.cern.ch/noteInfo.jsp?cmsnoteid=CMS+AN-2013%2F000'
            }]
        },
        'general_title': '2HDM Higgs studies (H->ZZ and A->Zh)',
        '_fetched_from': 'cadi',
        '_user_edited': False,
        'basic_info': {
            'cadi_id': 'EXO-00-000'
        },
        '$schema':
        'https://analysispreservation.cern.ch/schemas/deposits/records/cms-analysis-v0.0.1.json',
        '_deposit': {
            'id': deposit['_deposit']['id'],
            'status': 'draft',
            'owners': []
        },
        '_experiment': 'CMS',
        '_access': {
            'deposit-read': {
                'users': [owner.id],
                'roles': [cms_members_group_with_r_access.id] +
                [x.id for x in cms_admin_groups_with_admin_access]
            },
            'deposit-update': {
                'users': [owner.id],
                'roles': [x.id for x in cms_admin_groups_with_admin_access]
            },
            'deposit-admin': {
                'users': [owner.id],
                'roles': [x.id for x in cms_admin_groups_with_admin_access]
            }
        },
        '_files': []
    }