def test_order_field_detection(self) -> None: init_field_type_registry() doc = self.setup_document() field = DocumentField() field.requires_text_annotations = False field.stop_words = None field.text_unit_type = 'sentences' text_unit_repo = MockTextUnitRepository() text_unit_repo.units = [TextUnit(), TextUnit()] text_unit_repo.units[0].text = "But those cushion's velvet lining" text_unit_repo.units[1].text = "She shall press! Ah! Nevermore..." for tu in text_unit_repo.units: tu.document = doc tu.unit_type = field.text_unit_type detect_repo = MockFieldDetectorRepository() detector = self.make_doc_field_detector() detect_repo.detectors = [detector] old_tu_repo = RegexpsOnlyFieldDetectionStrategy.text_unit_repo RegexpsOnlyFieldDetectionStrategy.text_unit_repo = text_unit_repo old_repo_detect = RegexpsOnlyFieldDetectionStrategy.field_detector_repo RegexpsOnlyFieldDetectionStrategy.field_detector_repo = detect_repo try: detected = RegexpsOnlyFieldDetectionStrategy.\ detect_field_value(None, doc, field) finally: RegexpsOnlyFieldDetectionStrategy.text_unit_repo = old_tu_repo RegexpsOnlyFieldDetectionStrategy.field_detector_repo = old_repo_detect self.assertEqual(1, len(detected))
def detect_values_in_document(self, text_units: List[MockTextUnit], detector: DocumentFieldDetector, **doc_field_kwargs): init_field_type_registry() field = self.make_doc_field(**doc_field_kwargs) detector.field = field doc = self.setup_document(text_units) detect_repo = MockFieldDetectorRepository() detect_repo.detectors = [detector] text_unit_repo = MockTextUnitRepository() text_unit_repo.units = text_units for tu in text_unit_repo.units: tu.document = doc tu.unit_type = field.text_unit_type old_repo_tu = RegexpsOnlyFieldDetectionStrategy.text_unit_repo RegexpsOnlyFieldDetectionStrategy.text_unit_repo = text_unit_repo old_repo_detect = RegexpsOnlyFieldDetectionStrategy.field_detector_repo RegexpsOnlyFieldDetectionStrategy.field_detector_repo = detect_repo try: detected = RegexpsOnlyFieldDetectionStrategy.detect_field_value(None, doc, field, {}) finally: RegexpsOnlyFieldDetectionStrategy.text_unit_repo = old_repo_tu RegexpsOnlyFieldDetectionStrategy.field_detector_repo = old_repo_detect return detected
def detect_values_in_document(self, text_units: List[TextUnitMock], detector: DocumentFieldDetector): init_field_type_registry() doc = self.setup_document(text_units) field = DocumentField() field.requires_text_annotations = False field.stop_words = None field.text_unit_type = 'sentences' field.type = 'multi_choice' field.allow_values_not_specified_in_choices = True text_unit_repo = MockTextUnitRepository() text_unit_repo.units = text_units for tu in text_unit_repo.units: tu.document = doc tu.unit_type = field.text_unit_type detect_repo = MockFieldDetectorRepository() detect_repo.detectors = [detector] old_tu_repo = RegexpsOnlyFieldDetectionStrategy.text_unit_repo RegexpsOnlyFieldDetectionStrategy.text_unit_repo = text_unit_repo old_repo_detect = RegexpsOnlyFieldDetectionStrategy.field_detector_repo RegexpsOnlyFieldDetectionStrategy.field_detector_repo = detect_repo try: detected = RegexpsOnlyFieldDetectionStrategy. \ detect_field_value(None, doc, field, {}) finally: RegexpsOnlyFieldDetectionStrategy.text_unit_repo = old_tu_repo RegexpsOnlyFieldDetectionStrategy.field_detector_repo = old_repo_detect return detected
def non_test_formula_ok(self): from apps.document.field_type_registry import init_field_type_registry init_field_type_registry() document_field = DocumentField.objects.get( code='ws_accept_reject_sender_based') formula = "'accept' if ('Glee' in (ws_email_subject or '') or 'R&B' in (ws_email_subject or '')) " + \ "and (ws_lit_client or ws_lit_contact or ws_lit_subsidiary) else ('unsure' or some_var)" fields_to_values = {'ws_email_subject': 'No Subject'} r = DocumentFieldAdmin.calculate_formula_result_on_values( check_return_value=True, document_field=document_field, fields_to_values=fields_to_values, formula=formula) self.assertEqual(1, len(r.warnings))
# Manually add debug patterns if settings.DEBUG: # This allows the error pages to be debugged during development, just visit # these urls in browser to see how these error pages look like. urlpatterns += [ url(r'^' + settings.BASE_URL + '400/$', default_views.bad_request, kwargs={'exception': Exception('Bad Request!')}), url(r'^' + settings.BASE_URL + '403/$', default_views.permission_denied, kwargs={'exception': Exception('Permission Denied')}), url(r'^' + settings.BASE_URL + '404/$', default_views.page_not_found, kwargs={'exception': Exception('Page not Found')}), url(r'^' + settings.BASE_URL + '500/$', default_views.server_error), ] if 'debug_toolbar' in settings.INSTALLED_APPS: import debug_toolbar urlpatterns += [ # url(r'^' + settings.BASE_URL + '__debug__/', include(debug_toolbar.urls)), path('__debug__/', include(debug_toolbar.urls)), ] if not migrating(): init_decorators() init_app_vars() init_field_type_registry() init_field_registry()
def setUpClass(cls): super().setUpClass() init_field_type_registry()