Skip to content

Commit

Permalink
using csv.writer rather than simple text write to add in string escap…
Browse files Browse the repository at this point in the history
…ing on results
  • Loading branch information
mikejcorey committed Oct 24, 2024
1 parent 861adbd commit 985d404
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions apps/deed/management/commands/run_term_search_test.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
import csv
import json
import boto3
import datetime
Expand Down Expand Up @@ -34,7 +35,7 @@ def add_arguments(self, parser):
help='Only test DeedPages that have been flagged as conventional hits.')

def get_test_deedpages(self, workflow=None, n=100, bool_hits_only=False):
"""Get a random sample of n (default 100) existing OCR JSON objects generated by Textract in the preliminary stages of the Deed Machine."""
"""Get a random sample of n (default 100) existing OCR JSON objects generated by Textract in the preliminary stages of the Deed Machine. Manually excluding legacy Ramsey County workflow, which does not include OCR text and thus can't be tested."""

print(f'Gathering list of {n} OCRed images ...')

Expand All @@ -48,9 +49,9 @@ def get_test_deedpages(self, workflow=None, n=100, bool_hits_only=False):
out_values = ['workflow__slug', 's3_lookup', 'page_ocr_json', 'page_ocr_text', 'page_image_web', 'page_stats', 'public_uuid', 'bool_match']

if len(kwargs) > 0:
random_deedpages = DeedPage.objects.filter(**kwargs).order_by('?').values(*out_values)[:n]
random_deedpages = DeedPage.objects.filter(**kwargs).exclude(workflow__workflow_name="Ramsey County").order_by('?').values(*out_values)[:n]
else:
random_deedpages = DeedPage.objects.all().order_by('?').values(*out_values)[:n]
random_deedpages = DeedPage.objects.exclude(workflow__workflow_name="Ramsey County").order_by('?').values(*out_values)[:n]

return random_deedpages

Expand Down Expand Up @@ -160,7 +161,8 @@ def trigger_lambda(self, deedpage_obj):
test_response['match_context'] = '"' + json.dumps(match_context).replace('"', "'") + '"'

with open(self.term_test_result_path, 'a') as done_manifest:
done_manifest.write(','.join(test_response.values()) + '\n')
writer = csv.writer(done_manifest)
writer.writerow(test_response.values())

return test_response['test_status']

Expand Down

0 comments on commit 985d404

Please sign in to comment.