示例#1
0
 def test_url_rotate(self):
     ''' Test the url rotates from http://xxx:9200 to correct url. '''
     query = ElasticQuery.filtered(Query.term("seqid", 1),
                                   Filter(Query.term("id", "rs768019142")))
     elastic = Search(query, idx=ElasticSettings.idx('DEFAULT'))
     self.assertTrue(elastic.search().hits_total == 1,
                     "Elastic filtered query retrieved marker")
     Search.index_exists('test', 'test2')
     ElasticUrl.URL_INDEX = 0  # reset
    def test_region_idx_loader(self):
        ''' Test loader has created and populated indices.  '''

        key = 'PRIVATE_REGIONS_GFF'

        if key in IDX.keys():
            idx = IDX[key]['indexName']
            Search.index_refresh(idx)
            self.assertTrue(Search.index_exists(idx=idx), 'Index exists: '+idx)
            ndocs = Search(idx=idx).get_count()['count']
            self.assertTrue(ndocs > 0, "Elastic count documents in " + idx + ": " + str(ndocs))
示例#3
0
 def test_idx_loader(self):
     ''' Test loader has created and populated indices.  '''
     for key in IDX:
         idx = IDX[key]['indexName']
         # check the index has documents, allow for the indexing to complete if necessary
         #             Search.index_refresh(idx)
         self.assertTrue(Search.index_exists(idx=idx),
                         'Index exists: ' + idx)
         ndocs = Search(idx=idx).get_count()['count']
         self.assertTrue(
             ndocs > 0,
             "Elastic count documents in " + idx + ": " + str(ndocs))
示例#4
0
    def test_region_idx_loader(self):
        ''' Test loader has created and populated indices.  '''

        key = 'PRIVATE_REGIONS_GFF'

        if key in IDX.keys():
            idx = IDX[key]['indexName']
            Search.index_refresh(idx)
            self.assertTrue(Search.index_exists(idx=idx),
                            'Index exists: ' + idx)
            ndocs = Search(idx=idx).get_count()['count']
            self.assertTrue(
                ndocs > 0,
                "Elastic count documents in " + idx + ": " + str(ndocs))
示例#5
0
    def test_create_restore_delete_snapshot(self):
        self.wait_for_running_snapshot()
        snapshot = 'test_' + ElasticSettings.getattr('TEST')
        repo = SnapshotTest.TEST_REPO

        # create a snapshot
        call_command('snapshot',
                     snapshot,
                     indices=IDX['MARKER']['indexName'],
                     repo=repo)
        Snapshot.wait_for_snapshot(repo, snapshot)
        self.assertTrue(Snapshot.exists(repo, snapshot),
                        "Created snapshot " + snapshot)
        # snapshot already exist so return false
        self.assertFalse(
            Snapshot.create_snapshot(repo, snapshot,
                                     IDX['MARKER']['indexName']))

        # delete index
        requests.delete(ElasticSettings.url() + '/' +
                        IDX['MARKER']['indexName'])
        self.assertFalse(Search.index_exists(IDX['MARKER']['indexName']),
                         "Removed index")
        # restore from snapshot
        call_command('restore_snapshot',
                     snapshot,
                     repo=repo,
                     indices=IDX['MARKER']['indexName'])
        Search.index_refresh(IDX['MARKER']['indexName'])
        self.assertTrue(Search.index_exists(IDX['MARKER']['indexName']),
                        "Restored index exists")

        # remove snapshot
        call_command('snapshot', snapshot, delete=True, repo=repo)
        Snapshot.wait_for_snapshot(repo, snapshot, delete=True, count=10)
        self.assertFalse(Snapshot.exists(repo, snapshot),
                         "Deleted snapshot " + snapshot)
示例#6
0
def marker_page(request, marker):
    ''' Render a marker page '''
    query = ElasticQuery.query_match("id", marker)
    elastic = Search(query)
    context = elastic.get_result()
    _add_info(context)

    # rs history lookup
    if Search.index_exists(
            idx=ElasticSettings.idx(name='MARKER', idx_type='HISTORY')):
        query = ElasticQuery.query_match("rscurrent", marker)
        rs_history = Search(query,
                            idx=ElasticSettings.idx(name='MARKER',
                                                    idx_type='HISTORY'))
        context['history'] = rs_history.get_result()

    # get gene(s) overlapping position
    position = context['data'][0]['start']
    chrom = 'chr' + str(context['data'][0]['seqid'])
    featurelocs = (
        Featureloc.objects.filter(fmin__lt=position)  # @UndefinedVariable
        .filter(fmax__gt=position)  # @UndefinedVariable
        .filter(srcfeature__uniquename=chrom)  # @UndefinedVariable
        .filter(feature__type__name='gene'))  # @UndefinedVariable

    genes = []
    for loc in featurelocs:
        genes.append(loc.feature)
    context['genes'] = genes
    # page title
    if len(context["data"]) == 1 and "id" in context["data"][0]:
        context['title'] = "Marker - " + context["data"][0]["id"]

    return render(request,
                  'marker/marker.html',
                  context,
                  content_type='text/html')
 def test_idx_exists(self):
     ''' Test that index_exists() method. '''
     self.assertTrue(Search.index_exists(idx=ElasticSettings.idx('DEFAULT')),
                     "Index exists")
     self.assertFalse(Search.index_exists("xyz123"))