Пример #1
0
def test_get_sorted_second_page(requireMocking, libraries_with_confirmed):
    from cis import compounds

    first = compounds.get_sorted(
        {
            'pathParameters': {
                'library':
                urllib.parse.quote(libraries_with_confirmed[0]['library']),
                'version':
                urllib.parse.quote('fixed')
            },
            'queryStringParameters': {
                'limit': 10,
                'offset': 0
            }
        }, {})

    second = compounds.get_sorted(
        {
            'pathParameters': {
                'library':
                urllib.parse.quote(libraries_with_confirmed[0]['library']),
                'version':
                urllib.parse.quote('fixed')
            },
            'queryStringParameters': {
                'limit': 10,
                'offset': 10
            }
        }, {})

    assert first['statusCode'] == 200
    assert second['statusCode'] == 200

    assert json.loads(first['body']) != json.loads(second['body'])
Пример #2
0
def test_compound_get_hidden(requireMocking, libs_with_hidden_comps):
    from cis import compounds

    h_splashes = compounds.get_sorted(
        {
            'pathParameters': {
                'library': urllib.parse.quote(libs_with_hidden_comps[0]),
                'version': 'fixed',
                'tgt_type': 'unconfirmed'
            },
            'queryStringParameters': {
                'hidden': 'x'  # whatever value, value not used.
            }
        },
        {})

    assert h_splashes['statusCode'] == 200

    hidden = []
    h_list = json.loads(h_splashes['body'], use_decimal=True)
    for splash in h_list:
        cpd = compounds.get(
            {
                'pathParameters': {
                    'library': urllib.parse.quote(libs_with_hidden_comps[0]),
                    'version': 'fixed',
                    'splash': urllib.parse.quote(splash)
                }
            }, {})
        cpd = json.loads(cpd['body'])[0]
        hidden.append(cpd)

    assert all([x['hidden'] for x in hidden])
Пример #3
0
def splash_test_name(request, libraries_list):
    from cis import compounds
    result = request.config.cache.get('cis/compounds', None)

    lib = libraries_list[0]

    if result is not None:
        print(f'using cached object: {result}')
        return result
    else:
        print('loading all, takes forever and should be cached instead...')
        data = json.loads(
            compounds.get_sorted(
                {
                    'pathParameters': {
                        'library': urllib.parse.quote(lib)
                    },
                    'queryStringParameters': {
                        'limit': 100000
                    }
                }, {})['body'])

    for num, splash in enumerate(data):
        result = (data[num], lib)

        # request.config.cache.set("cis/compounds", result)
        return result

    raise Exception(f'did not find compounds in {lib}')
Пример #4
0
def test_get_name_filtered_default_order(requireMocking, compound_list):
    from cis import compounds

    splashes = compounds.get_sorted(
        {
            'pathParameters': {
                'library': urllib.parse.quote(compound_list[0]['method']),
                'version': urllib.parse.quote(compound_list[0]['version'])
            },
            'queryStringParameters': {
                'limit': 30,
                'name': compound_list[0]['name'][3:7]
            }
        }, {})

    assert splashes['statusCode'] == 200
    comps_obj = [
        json.loads(
            compounds.get(
                {
                    'pathParameters': {
                        'library': compound_list[0]['method'],
                        'splash': c
                    }
                }, {})['body'])[0] for c in json.loads(splashes['body'])
    ]
    assert len(comps_obj) >= 1
Пример #5
0
def splash_test_name_with_meta(soqtof_neg, request):
    from cis import compounds
    result = request.config.cache.get('cis/meta', None)

    if result is not None:
        print(f'using cached object: {result}')
        return result
    else:
        print('loading all, takes forever and should be cached instead...')
        data = json.loads(
            compounds.get_sorted(
                {
                    'pathParameters': {
                        'library': urllib.parse.quote(soqtof_neg)
                    },
                    'queryStringParameters': {
                        'limit': 100000
                    }
                }, {})['body'])

    for num, splash in enumerate(data):
        response = compounds.get_metas(
            {
                'pathParameters': {
                    'library': urllib.parse.quote(soqtof_neg),
                    'splash': splash
                }
            }, {})
        if response['statusCode'] == 200:
            result = (data[num], soqtof_neg)

            request.config.cache.set('cis/meta', result)
            return result

    raise Exception(f'did not find a standard with no_meta in {soqtof_neg}')
Пример #6
0
def test_query_silly1(requireMocking, libraries_with_unconfirmed):
    from cis import compounds

    response = compounds.get_sorted(
        {
            'pathParameters': {
                'library':
                urllib.parse.quote(
                    '15m splash one | qtof | csh c18 | positive'),
                'tgt_type':
                urllib.parse.quote('UNCONFIRMED'),
                'version':
                urllib.parse.quote('fixed')
            },
            'queryStringParameters': {
                'limit': 50,
                'offset': 0,
                'order_by': 'name',
                'identified': 'true',
                'name': 'unknown',
                'direction': 'asc'
            }
        }, {})

    assert response['statusCode'] in [200, 404]
    splashes = json.loads(response['body'])
    logger.info(splashes)

    assert len(splashes) >= 0
Пример #7
0
def test_query_silly2(requireMocking, libraries_with_unconfirmed):
    from cis import compounds

    # querying unidentified compounds with name, which should NOT happen
    response = compounds.get_sorted(
        {
            'pathParameters': {
                'library':
                urllib.parse.quote(libraries_with_unconfirmed[0]['library']),
                'tgt_type':
                urllib.parse.quote('UNCONFIRMED'),
                'version':
                urllib.parse.quote('fixed')
            },
            'queryStringParameters': {
                'limit': 50,
                'offset': 0,
                'order_by': 'name',
                'identified': 'false',  # this is the default
                'name': 'test',
                'direction': 'asc'
            }
        },
        {})

    assert response['statusCode'] == 404
Пример #8
0
def depr_test_get_sorted_with_range(requireMocking, compound_list_with_istd):
    from cis import compounds

    splashes = compounds.get_sorted(
        {
            'pathParameters': {
                'library': urllib.parse.quote(
                    compound_list_with_istd[0]['method']),
                'version': urllib.parse.quote('fixed')
            },
            'queryStringParameters': {
                'limit': 150,
                'order_by': 'pmz',
                'pmzvalue': float(compound_list_with_istd[0]['mass']) + 0.004,
                'pmzaccuracy': 0.01
            }
        }, {})

    assert splashes['statusCode'] == 200
    comps_obj = [
        json.loads(
            compounds.get(
                {
                    'pathParameters': {
                        'library': compound_list_with_istd[0]['method'],
                        'splash': c
                    }
                }, {})['body'])[0] for c in json.loads(splashes['body'])
    ]
    assert len(comps_obj) > 0

    assert comps_obj[0]['precursor_mass'] >= float(
        compound_list_with_istd[0]['mass']) - 0.05
    assert comps_obj[-1]['precursor_mass'] <= float(
        compound_list_with_istd[0]['mass']) + 0.05
Пример #9
0
def depr_test_query_bug2(requireMocking, libraries_with_unconfirmed):
    from cis import compounds

    response = compounds.get_sorted(
        {
            'pathParameters': {
                'library':
                urllib.parse.quote(libraries_with_unconfirmed[0]['library']),
                'tgt_type':
                urllib.parse.quote('UNCONFIRMED'),
                'version':
                urllib.parse.quote('fixed')
            },
            'queryStringParameters': {
                'limit': 50,
                'offset': 0,
                'order_by': 'name',
                'identified': 'true',  # this is the default
                'direction': 'asc'
            }
        },
        {})

    assert response['statusCode'] == 200

    splashes = json.loads(response['body'])

    assert len(splashes) > 0
Пример #10
0
def test_get_sorted_by_type(requireMocking, libraries_with_confirmed):
    from cis import compounds

    response = compounds.get_sorted(
        {
            'pathParameters': {
                'library':
                urllib.parse.quote(libraries_with_confirmed[0]['library']),
                'tgt_type':
                urllib.parse.quote('confirmed'),
                'version':
                urllib.parse.quote(urllib.parse.quote('fixed'))
            },
            'queryStringParameters': {
                'limit': 50,
                'order_by': 'splash'
            }
        }, {})

    splashes = json.loads(response['body'])

    cmp = compounds.get(
        {
            'pathParameters': {
                'library':
                urllib.parse.quote(libraries_with_confirmed[0]['library']),
                'splash':
                urllib.parse.quote(splashes[0]),
                'version':
                urllib.parse.quote('fixed')
            }
        }, {})

    tgt_type = json.loads(cmp['body'])[0]['target_type']
    assert tgt_type == 'CONFIRMED'
Пример #11
0
def test_get_sorted_names_identified_confirmed(requireMocking,
                                               libraries_with_confirmed):
    from cis import compounds

    response = compounds.get_sorted(
        {
            'pathParameters': {
                'library':
                urllib.parse.quote(libraries_with_confirmed[0]['library'])
            },
            'queryStringParameters': {
                'identified': 'true'
            }
        }, {})

    assert response['statusCode'] == 200
    result = json.loads(response['body'])
    for c in result:
        cc = compounds.get(
            {
                'pathParameters': {
                    'library':
                    urllib.parse.quote(libraries_with_confirmed[0]['library']),
                    'splash':
                    c
                }
            }, {})

        cc = json.loads(cc['body'], use_decimal=True)[0]
        assert len(cc['associated_names']) > 0
Пример #12
0
def depr_test_get_name_filtered_with_range(requireMocking,
                                           compound_list_with_istd):
    from cis import compounds

    splashes = compounds.get_sorted(
        {
            'pathParameters': {
                'library': urllib.parse.quote(
                    compound_list_with_istd[0]['method']),
                'version': urllib.parse.quote('fixed')
            },
            'queryStringParameters': {
                'limit': 30,
                'order_by': 'pmz',
                'name': compound_list_with_istd[0]['name'],
                'pmzvalue': compound_list_with_istd[0]['mass']
            }
        }, {})

    assert splashes['statusCode'] == 200
    comps_obj = [
        json.loads(
            compounds.get(
                {
                    'pathParameters': {
                        'library':
                        urllib.parse.quote(
                            compound_list_with_istd[0]['method']),
                        'splash':
                        c
                    }
                }, {})['body'])[0] for c in json.loads(splashes['body'])
    ]
    assert len(comps_obj) >= 1
Пример #13
0
def test_get_ranges_gibberish(requireMocking, libraries_list, compound_list):
    from cis import compounds

    response = compounds.get_sorted(
        {
            'pathParameters': {
                'library': urllib.parse.quote(libraries_list[0]),
                'version': urllib.parse.quote('fixed')
            },
            'queryStringParameters': {
                'pmzvalue': 'boom'
            }
        }, {})

    assert response['statusCode'] == 400

    response = compounds.get_sorted(
        {
            'pathParameters': {
                'library': urllib.parse.quote(libraries_list[0]),
                'version': urllib.parse.quote('fixed')
            },
            'queryStringParameters': {
                'rivalue': 'blah - blah'
            }
        }, {})

    assert response['statusCode'] == 400

    response = compounds.get_sorted(
        {
            'pathParameters': {
                'library': urllib.parse.quote(libraries_list[0]),
                'version': urllib.parse.quote('fixed')
            },
            'queryStringParameters': {
                'rivalue': float(compound_list[0]['ri']),
                'riaccuracy': 'hacked'
            }
        }, {})

    assert response['statusCode'] == 400
Пример #14
0
def test_get_sorted_no_library(requireMocking):
    from cis import compounds

    response = compounds.get_sorted(
        {
            'pathParameters': {},
            'queryStringParameters': {}
        }, {})

    assert response['statusCode'] == 400
    assert json.loads(
        response['body'])['error'] == 'you need to provide a "library" name'
Пример #15
0
def test_get_compounds_by_type_comparison(requireMocking,
                                          libraries_with_different_tgt_types):
    from cis import compounds

    response = compounds.get_sorted(
        {
            'pathParameters': {
                'library':
                urllib.parse.quote(libraries_with_different_tgt_types[0]),
                'tgt_type':
                urllib.parse.quote('UNCONFIRMED')
            },
            'queryStringParameters': {
                'limit': 10,
                'offset': 0,
                'order_by': 'tgt_id',
                'direction': 'asc'
            }
        }, {})
    assert response['statusCode'] == 200
    unconfirmed = json.loads(response['body'])
    response = compounds.get_sorted(
        {
            'pathParameters': {
                'library':
                urllib.parse.quote(libraries_with_different_tgt_types[0]),
                'tgt_type':
                'confirmed'
            },
            'queryStringParameters': {
                'limit': 10,
                'offset': 0,
                'order_by': 'tgt_id',
                'direction': 'asc'
            }
        }, {})
    assert response['statusCode'] == 200
    confirmed = json.loads(response['body'])

    assert all([u not in confirmed for u in unconfirmed])
Пример #16
0
def test_filter_with_ri_and_pmz(requireMocking, compound_list):
    from cis import compounds
    unconf = list(
        filter(lambda x: x['target_type'] == 'UNCONFIRMED', compound_list))

    without = compounds.get_sorted(
        {
            'pathParameters': {
                'library': urllib.parse.quote(unconf[0]['method']),
                'version': urllib.parse.quote('fixed'),
                'tgt_type':
                'unconfirmed'  # only type with identified name, ATM
            },
            'queryStringParameters': {}
        },
        {})
    assert without['statusCode'] == 200

    filtered = compounds.get_sorted(
        {
            'pathParameters': {
                'library': urllib.parse.quote(unconf[0]['method']),
                'version': urllib.parse.quote('fixed'),
                'tgt_type':
                'unconfirmed'  # only type with identified name, ATM
            },
            'queryStringParameters': {
                'rivalue': unconf[0]['ri'],
                'pmzvalue': unconf[0]['mass']
            }
        },
        {})
    assert filtered['statusCode'] == 200

    assert json.loads(without['body'], use_decimal=True) != json.loads(
        filtered['body'], use_decimal=True)
Пример #17
0
def test_invalid_identified_names(requireMocking, libraries_list):
    from cis import compounds

    response = compounds.get_sorted(
        {
            'pathParameters': {
                'library': urllib.parse.quote(libraries_list[0]),
                'version': urllib.parse.quote('fixed')
            },
            'queryStringParameters': {
                'identified': 'blah'
            }
        }, {})

    assert response['statusCode'] == http.HTTPStatus.INTERNAL_SERVER_ERROR
    assert json.loads(response['body'])['error'] == [
        "Invalid value for queryString 'identified'. Please use 'true' or 'false'."
    ]
Пример #18
0
def test_get_filtered_version(requireMocking, libraries_list):
    from cis import compounds

    response = compounds.get_sorted(
        {
            'pathParameters': {
                'library': libraries_list[5],
                'version': '1',
                'tgt_type': 'istd'
            },
            'queryStringParameters': {}
        }, {})

    assert response['statusCode'] in [200, 404]
    splashes = json.loads(response['body'])
    logger.info(splashes)

    assert len(splashes) >= 0
Пример #19
0
def test_get_sorted_names_any_identified_confirmed(requireMocking,
                                                   libraries_with_confirmed):
    from cis import compounds

    response = compounds.get_sorted(
        {
            'pathParameters': {
                'library':
                urllib.parse.quote(libraries_with_confirmed[0]['library'])
            },
            'queryStringParameters': {
                'order_by': 'name',
                'direction': 'desc'
            }
        }, {})

    if response['statusCode'] == 404:
        pytest.skip(
            'It is possible that we do not have unconfirmed compounds in the db'
        )
    else:
        assert response['statusCode'] == 200

        comps = []
        result = json.loads(response['body'])
        for c in result:
            cc = compounds.get(
                {
                    'pathParameters': {
                        'library':
                        urllib.parse.quote(
                            libraries_with_confirmed[0]['library']),
                        'splash':
                        urllib.parse.quote(c)
                    }
                }, {})

            cc = json.loads(cc['body'], use_decimal=True)[0]
            comps.append(cc)

        names = list(map(lambda x: x['preferred_name'], comps))
        assert any([n.lower().startswith('unknown') for n in names])
Пример #20
0
def test_get_sorted_queryString_none(requireMocking,
                                     libraries_with_different_tgt_types):
    from cis import compounds

    response = compounds.get_sorted(
        {
            'pathParameters': {
                'library':
                urllib.parse.quote(libraries_with_different_tgt_types[-1]),
                'version':
                'fixed',
                'tgt_type':
                'unconfirmed'
            },
            'queryStringParameters': None
        }, {})

    assert response['statusCode'] == 200
    compounds = json.loads(response['body'])
    assert len(compounds) > 0
Пример #21
0
def test_get_sorted_big_page(requireMocking, libraries_with_confirmed):
    from cis import compounds

    response = compounds.get_sorted(
        {
            'pathParameters': {
                'library':
                urllib.parse.quote(libraries_with_confirmed[0]['library']),
                'version':
                urllib.parse.quote('fixed')
            },
            'queryStringParameters': {
                'limit': 100
            }
        }, {})

    assert response['statusCode'] == 200

    compounds = json.loads(response['body'])
    assert len(compounds) > 10
Пример #22
0
def depr_test_get_filtered_adduct_only(requireMocking, comps_with_adducts):
    from cis import compounds

    response = compounds.get_sorted(
        {
            'pathParameters': {
                'library': urllib.parse.quote(comps_with_adducts[0]['method']),
                'version': urllib.parse.quote('fixed'),
                'tgt_type': comps_with_adducts[0]['target_type']
            },
            'queryStringParameters': {
                'adduct': 'M+H'
            }
        }, {})

    assert response['statusCode'] == 200
    splashes = json.loads(response['body'])

    logger.info(splashes)
    assert len(splashes) >= 1
Пример #23
0
def test_get_filtered_lowercase_adduct_only(requireMocking, libraries_list):
    from cis import compounds

    response = compounds.get_sorted(
        {
            'pathParameters': {
                'library': urllib.parse.quote(libraries_list[4]),
                'version': urllib.parse.quote('fixed'),
                'tgt_type': 'unconfirmed'
            },
            'queryStringParameters': {
                'adduct': urllib.parse.quote('[m+h]+')
            }
        }, {})

    assert response['statusCode'] in [200, 404]
    pprint(response['body'])
    splashes = json.loads(response['body'])

    logger.info(splashes)
    assert len(splashes) >= 0
Пример #24
0
def test_get_sorted_defaults(requireMocking,
                             libraries_with_different_tgt_types):
    from cis import compounds

    response = compounds.get_sorted(
        {
            'pathParameters': {
                'library':
                urllib.parse.quote(libraries_with_different_tgt_types[0]),
                'version':
                'fixed'
            },
            'queryStringParameters': {
                'limit': 10,
                'order_by': 'tgt_ri',
                'direction': 'asc'
            }
        }, {})

    assert response['statusCode'] == 200

    compounds = json.loads(response['body'])
    assert len(compounds) == 10
Пример #25
0
def test_get_sorted_names_identified_unconfirmed(requireMocking,
                                                 libraries_with_unconfirmed):
    from cis import compounds

    response = compounds.get_sorted(
        {
            'pathParameters': {
                'library':
                urllib.parse.quote(libraries_with_unconfirmed[0]['library']),
                'tgt_type':
                'unconfirmed'
            },
            'queryStringParameters': {
                'identified': 'true'
            }
        }, {})

    if response['statusCode'] == 404:
        pytest.skip(
            'It is possible that we do not have unconfirmed compounds in the db'
        )

    result = json.loads(response['body'])
    for c in result:
        cc = compounds.get(
            {
                'pathParameters': {
                    'library':
                    urllib.parse.quote(
                        libraries_with_unconfirmed[0]['library']),
                    'splash':
                    c
                }
            }, {})

        cc = json.loads(cc['body'], use_decimal=True)[0]
        assert len(cc['associated_names']) > 0