Ejemplo n.º 1
0
    def test_get_criteria_details(self):
        config = IniParser().read_ini(MY_INI_FILE)
        idx = ElasticSettings.idx('REGION_CRITERIA')
        available_criterias = RegionCriteria.get_available_criterias(config=config)['region']
        idx_type = ','.join(available_criterias)

        doc_by_idx_type = ElasticUtils.get_rdm_docs(idx, idx_type, size=1)
        self.assertTrue(len(doc_by_idx_type) > 0)
        feature_id = getattr(doc_by_idx_type[0], 'qid')

        criteria_details = RegionCriteria.get_criteria_details(feature_id, config=config)

        hits = criteria_details['hits']
        first_hit = hits[0]
        _type = first_hit['_type']
        _index = first_hit['_index']
        _id = first_hit['_id']
        _source = first_hit['_source']

        disease_tag = _source['disease_tags'][0]
        self.assertTrue(feature_id, _id)
        self.assertIn(_type, idx_type)
        self.assertTrue(idx, _index)
        self.assertIn(disease_tag, list(_source.keys()))

        fdetails = _source[disease_tag][0]
        self.assertIn('fid', fdetails.keys())
        self.assertIn('fname', fdetails.keys())
Ejemplo n.º 2
0
def criteria_details(request):
    ''' Get criteria details for a given region ID. '''
    feature_id = request.POST.get('feature_id')
    criteria_details = RegionCriteria.get_criteria_details(feature_id)
    return JsonResponse(criteria_details)