Skip to content

Commit

Permalink
Update mur document test case
Browse files Browse the repository at this point in the history
  • Loading branch information
pkfec authored and fec-jli committed Mar 13, 2023
1 parent a587b0d commit e7ac02b
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 45 deletions.
2 changes: 1 addition & 1 deletion manifests/manifest_api_dev.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
applications:
- name: api
instances: 2
instances: 1
memory: 2G
disk_quota: 1G
stack: cflinuxfs3
Expand Down
66 changes: 31 additions & 35 deletions tests/integration/test_current_cases.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,36 +269,36 @@ def test_admin_fine(self, get_bucket):
def test_mur_with_participants_and_documents(self, get_bucket, get_credential):
case_id = 1
mur_subject = 'Fraudulent misrepresentation'
filename = "Some File.pdf"
expected_document = {
"document_id": 1,
"case_id": 1,
"filename": "Some File.pdf",
"category": "Statement of Reasons",
"date": datetime(2017, 2, 9, 0, 0),
"ocrtext": "Some Text",
"text": "Some Text",
"description": "Some Description",
"doc_order_id": 5
}
expected_mur = {
"type": "murs",
'no': '1',
'no': 1,
'case_serial': 1,
'name': 'MUR with participants',
'mur_type': 'current',
'published_flg': True,
'election_cycles': [2016],
'doc_id': 'mur_1',
'doc_id': 1,
'subjects': [mur_subject],
'respondents': ["Bilbo Baggins", "Thorin Oakenshield"],
"documents": [expected_document],
}
participants = [
("Complainant", "Gollum"),
("Respondent", "Bilbo Baggins"),
("Respondent", "Thorin Oakenshield"),
]
filename = "Some File.pdf"
documents = [
(
'A Category',
'Some text',
'legal/murs/{0}/{1}'.format('1', filename.replace(' ', '-')),
),
(
'Another Category',
'Different text',
'legal/murs/{0}/{1}'.format('1', filename.replace(' ', '-')),
),
]

self.create_case(
case_id,
Expand All @@ -310,24 +310,19 @@ def test_mur_with_participants_and_documents(self, get_bucket, get_credential):
for entity_id, participant in enumerate(participants):
role, name = participant
self.create_participant(case_id, entity_id, role, name)
for document_id, document in enumerate(documents):
category, ocrtext, url = document
self.create_document(case_id, document_id, category, ocrtext, filename)
self.create_document(1, expected_document, filename)

actual_mur = next(get_cases('MUR'))

# ?? to do list:
# for key in expected_mur:
# assert actual_mur[key] == expected_mur[key]
actual_document = actual_mur["documents"]
for i, actual_doc in enumerate(actual_document):
for j, expected_doc in enumerate(expected_document):
assert actual_document[actual_doc] == expected_document[expected_doc]

assert participants == [
(p['role'], p['name']) for p in actual_mur['participants']
]

# assert [(d[0], d[1], len(d[1])) for d in documents] == [
# (d['category'], d['text'], d['length']) for d in actual_mur['documents']
# ]

@patch('webservices.env.env.get_credential', return_value='BUCKET_NAME')
@patch('webservices.legal_docs.current_cases.get_bucket')
def test_mur_with_disposition(self, get_bucket, get_credential):
Expand Down Expand Up @@ -686,19 +681,20 @@ def create_violation(
regulatory_citation,
)

def create_document(
self, case_id, document_id, category, ocrtext, filename='129812.pdf'
):
def create_document(self, case_id, document, filename='201801_C.pdf'):
self.connection.execute(
"INSERT INTO fecmur.document (document_id, doc_order_id, case_id, category, ocrtext, fileimage, filename) "
"VALUES (%s, %s, %s, %s, %s, %s, %s)",
document_id,
document_id,
"""
INSERT INTO fecmur.document
(document_id, case_id, filename, category, document_date, ocrtext, description, doc_order_id)
VALUES (%s, %s, %s, %s, %s, %s, %s, %s)""",
document["document_id"],
case_id,
category,
ocrtext,
ocrtext,
filename,
document["category"],
document["date"],
document["text"],
document["description"],
document["doc_order_id"],
)

def create_calendar_event(self, entity_id, event_date, event_id, case_id):
Expand Down
19 changes: 11 additions & 8 deletions webservices/legal_docs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@

def initialize_legal_data(index_name=None):
"""
When first time load legal data, run this command with downtime (2 hours)
- Create a XXXX_INDEX on Elasticsearch
'INDEX_DICT' description:
1) CASE_INDEX include DOCUMENT_TYPE=('statutes','regulations','murs','adrs','admin_fines')
Expand Down Expand Up @@ -95,25 +96,27 @@ def initialize_legal_data(index_name=None):
logger.info(" Invalid index '{0}', unable to initialize this index.".format(index_name))


def refresh_legal_data_zero_downtime(index_name=None):
def update_mapping_and_reload_legal_data(index_name=None):
"""
When mapping change, run this command with short downtime(5 mins)
Eight steps process:
1. Create a XXXX_SWAP_INDEX
2. Switch original_alias(XXXX_ALIAS) point to XXXX_SWAP_INDEX
3. Load the legal data into original_alias(==XXXX_SWAP_INDEX)
4. Swith the SEARCH_ALIAS point to XXXX_SWAP_INDEX
4. Switch the SEARCH_ALIAS point to XXXX_SWAP_INDEX
5. Re-create original_index (XXXX_INDEX)
6. Re-index XXXX_INDEX based on XXXX_SWAP_INDEX
7. Switch aliases (XXXX_ALIAS,SEARCH_ALIAS) point back to XXXX_INDEX
8. Delete XXXX_SWAP_INDEX
-How to call task command:
a) cf run-task api --command "python cli.py refresh_legal_data_zero_downtime case_index" -m 4G
--name refresh_case_data
b) cf run-task api --command "python cli.py refresh_legal_data_zero_downtime ao_index" -m 4G
--name refresh_ao_data
c) cf run-task api --command "python cli.py refresh_legal_data_zero_downtime arch_mur_index" -m 4G
--name refresh_arch_mur_data
a) cf run-task api --command "python cli.py update_mapping_and_reload_legal_data case_index" -m 4G
--name update_mapping_reload_data_case
b) cf run-task api --command "python cli.py update_mapping_and_reload_legal_data ao_index" -m 4G
--name update_mapping_reload_data_ao
c) cf run-task api --command "python cli.py update_mapping_and_reload_legal_data arch_mur_index" -m 4G
--name update_mapping_reload_data_arch_mur
"""

index_name = index_name or CASE_INDEX
Expand Down
2 changes: 1 addition & 1 deletion webservices/legal_docs/es_management.py
Original file line number Diff line number Diff line change
Expand Up @@ -799,7 +799,7 @@ def create_es_snapshot(index_name):
}
configure_snapshot_repository(repo_name)
snapshot_name = "{0}_{1}".format(
prefix_snapshot, datetime.datetime.today().strftime("%Y%m%d%H%M")
datetime.datetime.today().strftime("%Y%m%d%H%M"), prefix_snapshot
)
logger.info(" Creating snapshot {0} ...".format(snapshot_name))
result = es_client.snapshot.create(
Expand Down

0 comments on commit e7ac02b

Please sign in to comment.