コード例 #1
0
def test_reject_meta(requireMocking, compound_without_associated_meta):
    from cis import compound_metas as cm, compounds

    cmp = compounds.get({
        'pathParameters': {
            'library': compound_without_associated_meta['method'],
            'splash': compound_without_associated_meta['splash'],
            'version': compound_without_associated_meta['version']
        }
    }, {})
    assert cmp['statusCode'] == 200

    cmp = json.loads(cmp['body'])[0]
    meta = cmp['associated_metas'][0]

    response = cm.reject_meta({
        'pathParameters': {
            'meta_id': urllib.parse.quote(str(meta['id'])),
            'compound_id': urllib.parse.quote(str(cmp['id'])),
            'rejected': urllib.parse.quote('true')
        }
    }, {})
    assert response['statusCode'] == 204

    cmp = json.loads(compounds.get({
        'pathParameters': {
            'library': compound_without_associated_meta['method'],
            'splash': compound_without_associated_meta['splash'],
            'version': compound_without_associated_meta['version']
        }
    }, {})['body'])[0]

    assert any([c['rejected'] is True for c in cmp['associated_metas']])
コード例 #2
0
def test_compound_register_dup_meta(requireMocking, compound_without_associated_meta):
    from cis import compound_metas as cm, compounds

    res = cm.register_meta({
        'pathParameters': {
            'library': compound_without_associated_meta['method'],
            'splash': compound_without_associated_meta['splash'],
            'version': compound_without_associated_meta['version'],
            'identifiedBy': 'test-diego',
            'name': 'meta_name',
            'value': 'meta_value'
        }
    }, {})

    assert res['statusCode'] == 204

    response = compounds.get({
        'pathParameters': {
            'library': compound_without_associated_meta['method'],
            'splash': compound_without_associated_meta['splash'],
            'version': compound_without_associated_meta['version']
        }
    }, {})

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

    metas = [a['name'] for a in result['associated_metas']]
    assert metas.count('meta_name') == 1
コード例 #3
0
def test_compound_register_comment(requireMocking,
                                   compound_without_associated_comments):
    from cis import compound_comments as cc, compounds

    response = cc.register_comment(
        {
            'pathParameters': {
                'library': compound_without_associated_comments['method'],
                'splash': compound_without_associated_comments['splash'],
                'version': compound_without_associated_comments['version'],
                'identifiedBy': 'test-diego'
            },
            'body':
            json.dumps(
                {'comment': 'my long winded test comment, not so long though'})
        }, {})
    assert response['statusCode'] is http.HTTPStatus.NO_CONTENT

    response = compounds.get(
        {
            'pathParameters': {
                'library': compound_without_associated_comments['method'],
                'splash': compound_without_associated_comments['splash'],
                'version': compound_without_associated_comments['version']
            }
        }, {})
    assert response['statusCode'] is 200

    result = json.loads(response['body'])[0]

    assert len(result['associated_comments']) > 0
    assert result['associated_comments'][-1]['identifiedBy'] == 'test-diego'
    assert result['associated_comments'][-1][
        'comment'] == 'my long winded test comment, not so long though'
コード例 #4
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])
コード例 #5
0
def test_compound_delete_all_metas(requireMocking, compound_without_associated_meta):
    from cis import compound_metas as cm, compounds

    res = cm.delete_metas({
        'pathParameters': {
            'library': compound_without_associated_meta['method'],
            'splash': compound_without_associated_meta['splash'],
            'version': compound_without_associated_meta['version']
        }
    }, {})

    assert res['statusCode'] == 204

    response = compounds.get({
        'pathParameters': {
            'library': compound_without_associated_meta['method'],
            'splash': compound_without_associated_meta['splash'],
            'version': compound_without_associated_meta['version']
        }
    }, {})

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

    assert len(result['associated_metas']) == 0
コード例 #6
0
def test_compound_register_dup_name(requireMocking,
                                    compound_without_associated_name):
    from cis import compound_names as cn, compounds

    res = cn.register_name(
        {
            'pathParameters': {
                'library': compound_without_associated_name['method'],
                'splash': compound_without_associated_name['splash'],
                'identifiedBy': 'test-diego',
                'name': 'test name'
            }
        }, {})

    assert res['statusCode'] == 204

    response = compounds.get(
        {
            'pathParameters': {
                'library': compound_without_associated_name['method'],
                'splash': compound_without_associated_name['splash']
            }
        }, {})

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

    names = [a['name'] for a in result['associated_names']]
    assert names.count('test name') == 1
コード例 #7
0
def test_compound_register_name(requireMocking,
                                compound_without_associated_name):
    from cis import compound_names as cn, compounds

    response = cn.register_name(
        {
            'pathParameters': {
                'library': compound_without_associated_name['method'],
                'splash': compound_without_associated_name['splash'],
                'name': 'test name',
                'identifiedBy': 'test-diego'
            },
        }, {})
    assert response['statusCode'] == 204

    response = compounds.get(
        {
            'pathParameters': {
                'library': compound_without_associated_name['method'],
                'splash': compound_without_associated_name['splash']
            }
        }, {})

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

    assert len(result['associated_names']) > 0
    assert any([n['name'] == 'test name' for n in result['associated_names']])
    assert result['associated_names'][0]['identifiedBy'] == 'test-diego'
    assert result['associated_names'][0]['rejected'] is False
コード例 #8
0
def test_compound_register_name_with_comment(requireMocking,
                                             compound_without_associated_name):
    from cis import compound_names as cn, compounds

    response = cn.register_name(
        {
            'pathParameters': {
                'library': compound_without_associated_name['method'],
                'splash': compound_without_associated_name['splash'],
                'name': 'other test name',
                'identifiedBy': 'test-other'
            },
            'body': json.dumps({'comment': 'blah blah'}),
        }, {})

    assert response['statusCode'] == 204
    response = compounds.get(
        {
            'pathParameters': {
                'library': compound_without_associated_name['method'],
                'splash': compound_without_associated_name['splash']
            }
        }, {})

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

    assert len(result['associated_names']) > 0

    obj = list(
        filter(lambda x: x['name'] == 'other test name',
               result['associated_names']))
    assert obj[0]['comment'] == 'blah blah'
コード例 #9
0
def test_compound_with_duplicates(requireMocking, conn,
                                  compound_list_with_dupes):
    from cis import compound_duplicates as cd, compounds as c

    result = cd.compounds_with_duplicates(
        {
            'pathParameters': {
                'library': compound_list_with_dupes[0]['library']
            }
        }, {})

    assert result['statusCode'] == http.HTTPStatus.OK
    first = json.loads(result['body'])[0]

    duped = c.get(
        {
            'pathParameters': {
                'library': first['library'],
                'splash': first['splash'],
                'version': first['version']
            }
        }, {})

    assert duped['statusCode'] == http.HTTPStatus.OK
    item = json.loads(duped['body'])
    assert len(item[0]['duplicates']) > 0
    assert compound_list_with_dupes[0]['splash'] == item[0]['splash']
コード例 #10
0
def test_compound_register_meta_with_comment(requireMocking, compound_without_associated_meta):
    from cis import compound_metas as cm, compounds

    response = cm.register_meta({
        'pathParameters': {
            'library': compound_without_associated_meta['method'],
            'splash': compound_without_associated_meta['splash'],
            'version': compound_without_associated_meta['version'],
            'name': 'other test meta',
            'value': 'other value',
            'identifiedBy': 'test-other'
        },
        'body': 'blah blah',
    }, {})

    assert response['statusCode'] == 204
    response = compounds.get({
        'pathParameters': {
            'library': compound_without_associated_meta['method'],
            'splash': compound_without_associated_meta['splash'],
            'version': compound_without_associated_meta['version']
        }
    }, {})

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

    assert len(result['associated_metas']) > 0

    obj = list(filter(lambda x: {
        x['name'] == 'other test meta' and x['value'] == 'other value'
    }, result['associated_metas']))
    assert any([o['comment'] == 'blah blah' for o in obj])
コード例 #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 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
コード例 #13
0
def test_delete_all_comments(requireMocking,
                             compound_without_associated_comments):
    from cis import compound_comments as cc, compounds

    resp = cc.delete_comments(
        {
            'pathParameters': {
                'library': compound_without_associated_comments['method'],
                'splash': compound_without_associated_comments['splash'],
                'version': compound_without_associated_comments['version']
            }
        }, {})
    assert resp['statusCode'] == http.HTTPStatus.NO_CONTENT

    response = compounds.get(
        {
            'pathParameters': {
                'library': compound_without_associated_comments['method'],
                'splash': compound_without_associated_comments['splash'],
                'version': compound_without_associated_comments['version']
            }
        }, {})

    result = json.loads(response['body'])[0]
    assert len(result['associated_comments']) == 0
コード例 #14
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
コード例 #15
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
コード例 #16
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'
コード例 #17
0
def test_unreject_assoc_name(requireMocking, compound_without_associated_name):
    from cis import compound_names as cn, compounds

    cmp = compounds.get(
        {
            'pathParameters': {
                'library': compound_without_associated_name['method'],
                'splash': compound_without_associated_name['splash'],
                'version': compound_without_associated_name['version']
            }
        }, {})
    assert cmp['statusCode'] == 200

    cmp = json.loads(cmp['body'])[0]
    name = next(
        filter(lambda x: x['rejected'] is True, cmp['associated_names']))

    response = cn.reject_name(
        {
            'pathParameters': {
                'name_id': urllib.parse.quote(str(name['id'])),
                'compound_id': urllib.parse.quote(str(cmp['id'])),
                'rejected': urllib.parse.quote('false')
            }
        }, {})
    assert response['statusCode'] == http.HTTPStatus.NO_CONTENT

    cmp = json.loads(
        compounds.get(
            {
                'pathParameters': {
                    'library': compound_without_associated_name['method'],
                    'splash': compound_without_associated_name['splash'],
                    'version': compound_without_associated_name['version']
                }
            }, {})['body'])[0]

    assert all([c['rejected'] is False for c in cmp['associated_names']])
コード例 #18
0
def test_get_specific_compound_doesnt_exist(requireMocking, compound_list):
    from cis import compounds

    response = compounds.get(
        {
            'pathParameters': {
                'library': urllib.parse.quote(compound_list[0]['method']),
                'splash':
                f"{urllib.parse.quote(compound_list[0]['splash'])}_not_real",
                'version': urllib.parse.quote(compound_list[0]['version'])
            }
        }, {})

    assert response['statusCode'] == 404
コード例 #19
0
def test_get_specific_compound(requireMocking, compound_list):
    from cis import compounds

    response = compounds.get(
        {
            'pathParameters': {
                'library': urllib.parse.quote(compound_list[0]['method']),
                'splash': urllib.parse.quote(compound_list[0]['splash']),
                'version': urllib.parse.quote(compound_list[0]['version'])
            }
        }, {})

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

    assert result['method'] == compound_list[0]['method']
    assert result['splash'] == compound_list[0]['splash']
    assert result['version'] == compound_list[0]['version']
コード例 #20
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])
コード例 #21
0
def depr_test_get_compound_with_statuses(requireMocking):
    from cis import compounds

    result = compounds.get(
        {
            'pathParameters': {
                'library':
                urllib.parse.quote(
                    '15m splash one | qtof | csh c18 | positive'),
                'splash':
                urllib.parse.quote(
                    'splash10-014i-1111090000-707bb63ea4a95b81163e'),
                'version':
                urllib.parse.quote('fixed')
            }
        }, {})

    assert result['statusCode'] == http.HTTPStatus.OK

    statuses = json.loads(result['body'])[0].get('associated_statuses', [])

    assert len(statuses) > 0
    pprint(statuses)
コード例 #22
0
def depr_test_get_compound_with_dupes(requireMocking,
                                      compound_list_with_dupes):
    from cis import compounds

    pprint(compound_list_with_dupes)

    duped = compounds.get(
        {
            'pathParameters': {
                'library':
                urllib.parse.quote(compound_list_with_dupes[0]['library']),
                'splash':
                urllib.parse.quote(compound_list_with_dupes[0]['splash']),
                'version':
                urllib.parse.quote(compound_list_with_dupes[0]['version'])
            }
        }, {})

    if duped['statusCode'] == 404:
        pytest.skip('No compounds with duplicates in database')
    else:
        assert all(
            [len(d['duplicates']) > 0 for d in json.loads(duped['body'])])
コード例 #23
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