def test_query_no_search(self): self.assertEqual( self.choice_provider.query(ChoiceQueryContext('', 2, page=0)), [Choice('1', 'One'), Choice('2', 'Two')]) self.assertEqual( self.choice_provider.query(ChoiceQueryContext('', 2, page=1)), [Choice('3', 'Three')])
def test_query_no_registry_access(self): self.assertEqual([Choice(value='A', display='A')], self.choice_provider.query( ChoiceQueryContext( query='A', offset=0, user=self.web_user_no_registry_access))) self.assertEqual([Choice(value='A', display='A')], self.choice_provider.query( ChoiceQueryContext( query='', offset=0, user=self.web_user_no_registry_access))) self.assertEqual([Choice(value='A', display='A')], self.choice_provider.query( ChoiceQueryContext( query='D', offset=0, user=self.web_user_no_registry_access)))
def choice_list_api(request, domain, report_id, filter_id): report_filter = _get_report_filter(domain, report_id, filter_id) if hasattr(report_filter, 'choice_provider'): query_context = ChoiceQueryContext( query=request.GET.get('q', None), limit=int(request.GET.get('limit', 20)), page=int(request.GET.get('page', 1)) - 1, user=request.couch_user) return json_response([ choice._asdict() for choice in report_filter.choice_provider.query(query_context) ]) else: # mobile UCR hits this API for invalid filters. Just return no choices. return json_response([])
def choice_list_api(request, domain, report_id, filter_id): report = get_report_config_or_404(report_id, domain)[0] report_filter = report.get_ui_filter(filter_id) if report_filter is None: raise Http404(_(u'Filter {} not found!').format(filter_id)) if hasattr(report_filter, 'choice_provider'): query_context = ChoiceQueryContext( query=request.GET.get('q', None), limit=int(request.GET.get('limit', 20)), page=int(request.GET.get('page', 1)) - 1) return json_response([ choice._asdict() for choice in report_filter.choice_provider.query(query_context) ]) else: # mobile UCR hits this API for invalid filters. Just return no choices. return json_response([])
def get(self, request, domain, *args, **kwargs): user = self.request.couch_user query_context = ChoiceQueryContext( query=request.GET.get('q', None), limit=int(request.GET.get('limit', 20)), page=int(request.GET.get('page', 1)) - 1, user=user) location_choice_provider = LocationChoiceProvider( StubReport(domain=domain), None) location_choice_provider.configure({'include_descendants': True}) return JsonResponse({ 'results': [{ 'id': location.value, 'text': location.display } for location in location_choice_provider.query(query_context)], 'total': location_choice_provider.query_count(query_context, user) })
def test_domain_with_no_grants(self): user = self.make_web_user_with_registry_role( '*****@*****.**', self.domain_c, has_registry_access=True) config = RegistryDataSourceConfiguration( domain="C", table_id='foo', referenced_doc_type='CommCareCase', registry_slug=self.registry.slug, ) config.save() report = RegistryReportConfiguration(domain="C", config_id=config._id) self.choice_provider = DomainChoiceProvider(report, None) self.assertEqual([Choice(value='C', display='C')], self.choice_provider.query( ChoiceQueryContext(query='', offset=0, user=user))) config.delete()
def test_query_search(self): self._test_query(ChoiceQueryContext('yes', limit=10, page=0))
def test_query_search(self): self._test_query(ChoiceQueryContext('o', limit=10, offset=0)) self._test_query(ChoiceQueryContext('l', limit=10, offset=0)) self._test_query(ChoiceQueryContext('no-match', limit=10, offset=0)) self._test_query(ChoiceQueryContext('o', limit=3, offset=2))
def test_query_search(self): self._test_query(ChoiceQueryContext('e', 2, page=0)) self._test_query(ChoiceQueryContext('e', 2, page=1))
def test_query_no_search_second_short_page(self): self._test_query(ChoiceQueryContext('', 2, page=1))
def test_query_no_search_first_short_page(self): self._test_query(ChoiceQueryContext('', 2, page=0))
def test_query_no_search_all(self): self._test_query(ChoiceQueryContext('', limit=20, page=0))
def test_disabled_query_search(self): self._test_query( ChoiceQueryContext(query='targaryen', limit=10, page=0))
def test_not_login_as_user(self): query_context = ChoiceQueryContext(query='*****@*****.**', offset=0) self.assertNotEqual(self.choice_provider.query(query_context), self.static_choice_provider.query(query_context))
def test_login_as_user(self): self._test_query( ChoiceQueryContext(query='*****@*****.**', offset=0))
def test_query_search(self): self._test_query( ChoiceQueryContext("A", limit=1, page=0, user=self.web_user))