Ejemplo n.º 1
0
    def test_post(self):

        _ID = '1ad2cba40cb25cd70d00aa8fba9cfaf3'
        VALID_V3_URL = \
            'https://raw.githubusercontent.com/schurerlab/'\
            'smartAPIs/master/LINCS_Data_Portal_smartAPIs.yml'

        try:
            smartapi = SmartAPI.get(_ID)
            smartapi.delete()
            refresh()
        except NotFoundError:
            pass

        self.request("/api/metadata/",
                     method='POST',
                     data={'url': VALID_V3_URL},
                     expect=401)
        self.request("/api/metadata/",
                     method='POST',
                     data={'url': MYGENE_URL},
                     headers=self.auth_user,
                     expect=409)
        self.request("/api/metadata/",
                     method='POST',
                     headers=self.auth_user,
                     expect=400)
        self.request("/api/metadata/",
                     method='POST',
                     data={'url': "http://invalidhost/file"},
                     headers=self.auth_user,
                     expect=400)
        self.request("/api/metadata/",
                     method='POST',
                     data={
                         'url': VALID_V3_URL,
                         'dryrun': True
                     },
                     headers=self.auth_user)
        refresh()
        assert not SmartAPI.exists(_ID)
        self.request("/api/metadata/",
                     method='POST',
                     data={'url': VALID_V3_URL},
                     headers=self.auth_user)
        refresh()
        assert SmartAPI.exists(_ID)

        try:
            smartapi = SmartAPI.get(_ID)
            smartapi.delete()
        except NotFoundError:
            pass
Ejemplo n.º 2
0
def test_search():
    """
    SmartAPI.exists(_id)
    SmartAPI.find(slug)
    SmartAPI.find(val, field)
    """
    assert SmartAPI.exists(MYGENE_ID)
    assert SmartAPI.exists(MYCHEM_ID)
    assert SmartAPI.find('mygene') == MYGENE_ID
    assert SmartAPI.find('mychem') == MYCHEM_ID
    assert SmartAPI.find('tester', 'username')
    assert SmartAPI.find('gene', 'tags.name') == MYGENE_ID
    assert SmartAPI.find('drug', 'tags.name') == MYCHEM_ID
    assert SmartAPI.find(MYGENE_URL, 'url') == MYGENE_ID
    assert SmartAPI.find(MYCHEM_URL, 'url') == MYCHEM_ID
Ejemplo n.º 3
0
    def test_delete(self):

        # setup
        assert SmartAPI.exists(MYGENE_ID)

        self.request("/api/metadata/" + MYGENE_ID, method='DELETE', expect=401)
        self.request("/api/metadata/" + MYGENE_ID,
                     method='DELETE',
                     headers=self.evil_user,
                     expect=403)
        self.request("/api/metadata/" + MYGENE_ID,
                     method='DELETE',
                     headers=self.auth_user)

        refresh()
        assert not SmartAPI.exists(MYGENE_ID)

        # teardown
        refresh()
        if not SmartAPI.exists(MYGENE_ID):  # recover the deleted file
            mygene = APIDoc(meta={'id': MYGENE_ID}, **MYGENE_ES)
            mygene._raw = decoder.compress(MYGENE_RAW)
            mygene.save()
        refresh()