def test_parent_property(self, mock): mock.return_value = {'type': ['property', 'parent/property']} with self.assertNumQueries(4): generate_data_dictionary(self.domain) self.assertEqual(CaseType.objects.filter(domain=self.domain).count(), 1) self.assertEqual(CaseProperty.objects.filter(case_type__domain=self.domain).count(), 1)
def test_empty_type(self, mock): mock.return_value = {'': ['prop']} with self.assertNumQueries(2): generate_data_dictionary(self.domain) self.assertEqual(CaseType.objects.filter(domain=self.domain).count(), 0) self.assertEqual(CaseProperty.objects.filter(case_type__domain=self.domain).count(), 0)
def generate_data_dictionary(request, domain): try: util.generate_data_dictionary(domain) except util.OldExportsEnabledException: return JsonResponse({ "failed": "Data Dictionary requires access to new exports" }, status=400) return JsonResponse({"status": "success"})
def test_one_type(self, mock): mock.return_value = {'type': ['property']} with self.assertNumQueries(4): generate_data_dictionary(self.domain) self.assertEqual( CaseType.objects.filter(domain=self.domain).count(), 1) self.assertEqual( CaseProperty.objects.filter(case_type__domain=self.domain).count(), 1)
def test_no_types(self, mock): mock.return_value = {} with self.assertNumQueries(1): generate_data_dictionary(self.domain) self.assertEqual( CaseType.objects.filter(domain=self.domain).count(), 0) self.assertEqual( CaseProperty.objects.filter(case_type__domain=self.domain).count(), 0)
def handle(self, **options): failed_domains = [] domains = options['domains'] or [d['key'] for d in Domain.get_all(include_docs=False)] print('Generating data dictionary for {} domains'.format(len(domains))) for domain in with_progress_bar(domains): try: generate_data_dictionary(domain) except OldExportsEnabledException: failed_domains.append(domain) print('--- Failed Domains ---') for domain in failed_domains: print(domain)
def handle(self, **options): print('Generating data dictionary for domains') failed_domains = [] for domain_dict in with_progress_bar( Domain.get_all(include_docs=False)): domain = domain_dict['key'] try: generate_data_dictionary(domain) except OldExportsEnabledException: failed_domains.append(domain) print('--- Failed Domains ---') for domain in failed_domains: print(domain)
def test_already_existing_property(self, mock): mock.return_value = {'type': ['property']} case_type = CaseType(domain=self.domain, name='type') case_type.save() CaseProperty(case_type=case_type, name='property').save() self.assertEqual(CaseType.objects.filter(domain=self.domain).count(), 1) self.assertEqual(CaseProperty.objects.filter(case_type__domain=self.domain).count(), 1) with self.assertNumQueries(3): generate_data_dictionary(self.domain) self.assertEqual(CaseType.objects.filter(domain=self.domain).count(), 1) self.assertEqual(CaseProperty.objects.filter(case_type__domain=self.domain).count(), 1)
def generate_data_dictionary(request, domain): if data_dictionary_rebuild_rate_limiter.allow_usage(domain): data_dictionary_rebuild_rate_limiter.report_usage(domain) try: util.generate_data_dictionary(domain) except util.OldExportsEnabledException: return JsonResponse({ "failed": "Data Dictionary requires access to new exports" }, status=400) return JsonResponse({"status": "success"}) else: return JsonResponse({ "failed": "Rate limit exceeded. Please try again later." }, status=429)