Skip to content

Commit

Permalink
update tests for search_api
Browse files Browse the repository at this point in the history
  • Loading branch information
Patrick Wang authored and Patrick Wang committed Sep 14, 2023
1 parent c8c2f63 commit 8667477
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 19 deletions.
27 changes: 19 additions & 8 deletions search-api/tests/unit/api/internal/test_update_solr.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,20 +66,26 @@ def test_update_business_in_solr(session, client, jwt, mocker):


@integration_solr
def test_update_business_no_tax_id(session, client, jwt, mocker):
@pytest.mark.parametrize('test_name, legal_name, good_standing, tax_id', [
('remove-tax-id', 'ABCD Prop', 'true', None),
('update-good-standing', 'ABCD Prop', 'false', '123456789'),
('update-legal-name', 'ABCDE Prop', 'true', '123456789'),
])
def test_update_business_in_solr_with_varying_data(session, client, jwt, mocker, test_name, legal_name, good_standing, tax_id):
"""Assert that update operation is successful."""
no_tax_id = deepcopy(REQUEST_TEMPLATE)
del no_tax_id['business']['taxId']
no_tax_id['business']['identifier'] = 'FM1111111'
request_json = deepcopy(REQUEST_TEMPLATE)
request_json['business']['legalName'] = legal_name
request_json['business']['goodStanding'] = good_standing
request_json['business']['taxId'] = tax_id
api_response = client.put(f'/api/v1/internal/solr/update',
data=json.dumps(no_tax_id),
data=json.dumps(request_json),
headers=create_header(jwt, [SYSTEM_ROLE], **{'Accept-Version': 'v1',
'content-type': 'application/json'})
)
# check
assert api_response.status_code == HTTPStatus.OK
time.sleep(2) # wait for solr to register update
identifier = no_tax_id['business']['identifier']
identifier = request_json['business']['identifier']
search_response = client.get(f'/api/v1/businesses/search/facets?query=value:{identifier}',
headers=create_header(jwt, [SYSTEM_ROLE], **{'Accept-Version': 'v1',
'content-type': 'application/json'})
Expand Down Expand Up @@ -139,10 +145,15 @@ def test_update_business_in_solr_missing_data(session, client, jwt, mocker):


@integration_solr
def test_update_business_in_solr_invalid_data(session, client, jwt, mocker):
@pytest.mark.parametrize('test_name, party_type, good_standing', [
('valid-goodStanding-should-pass', 'organization', 'non-boolean'),
('invalid-goodStanding-should-fail', 'invalid type', 'true'),
])
def test_update_business_in_solr_invalid_data(session, client, jwt, mocker, test_name, party_type, good_standing):
"""Assert that error is returned."""
request_json = deepcopy(REQUEST_TEMPLATE)
request_json['parties'][0]['officer']['partyType'] = 'test'
request_json['parties'][0]['officer']['partyType'] = party_type
request_json['business']['goodStanding'] = good_standing
api_response = client.put(f'/api/v1/internal/solr/update',
data=json.dumps(request_json),
headers=create_header(jwt, [SYSTEM_ROLE], **{'Accept-Version': 'v1',
Expand Down
11 changes: 6 additions & 5 deletions search-api/tests/unit/services/test_solr/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from search_api.services.solr.solr_fields import SolrField


def create_solr_doc(identifier, name, state, legal_type, bn=None, parties=None) -> BusinessDoc:
def create_solr_doc(identifier, name, state, legal_type, bn=None, parties=None, goodStanding=None) -> BusinessDoc:
solr_parties = None
if parties:
solr_parties = []
Expand All @@ -36,16 +36,17 @@ def create_solr_doc(identifier, name, state, legal_type, bn=None, parties=None)
legalType=legal_type,
name=name,
status=state,
goodStanding=goodStanding,
bn=bn,
parties=solr_parties
)


SOLR_TEST_DOCS = [
create_solr_doc('CP1234567', 'test 1234', 'ACTIVE', 'CP', 'BN00012334'),
create_solr_doc('CP0234567', 'tester 1111', 'HISTORICAL', 'CP', '09876K'),
create_solr_doc('CP0034567', 'tests 2222', 'ACTIVE', 'CP'),
create_solr_doc('BC0004567', 'test 3333', 'ACTIVE', 'BEN', '00987766800988'),
create_solr_doc('CP1234567', 'test 1234', 'ACTIVE', 'CP', 'BN00012334', None, True),
create_solr_doc('CP0234567', 'tester 1111', 'HISTORICAL', 'CP', '09876K', None, True),
create_solr_doc('CP0034567', 'tests 2222', 'ACTIVE', 'CP', None, None, True),
create_solr_doc('BC0004567', 'test 3333', 'ACTIVE', 'BEN', '00987766800988', None, False),
create_solr_doc('BC0000567', '4444 test', 'HISTORICAL', 'BC', 'BN9000776557'),
create_solr_doc('BC0000067', 'single', 'ACTIVE', 'BEN', '242217'),
create_solr_doc('BC0000007', 'lots of words in here', 'ACTIVE', 'BEN', '124221'),
Expand Down
13 changes: 8 additions & 5 deletions search-api/tests/unit/services/test_solr/test_solr_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,17 @@ def test_solr_doc(test_name, identifier, state, name, legal_type, bn):


@integration_solr
@pytest.mark.parametrize('test_name,identifier,state,name,legal_type,bn', [
('test-1', 'CP1234577', 'ACTIVE', 'BASIC TEST 1', 'CP', '12345'),
@pytest.mark.parametrize('test_name,identifier,state,name,legal_type,bn,good_standing, expected_good_standing', [
('test-with-good_standing=true', 'CP1234577', 'ACTIVE', 'BASIC TEST 1', 'CP', '12345','true', True),
('test-with-good_standing=false', 'CP1234577', 'ACTIVE', 'BASIC TEST 2', 'CP', '12345','false', False),
('test-without-good_standing', 'CP1234577', 'ACTIVE', 'BASIC TEST 3', 'CP', '12345', None, None),
])
def test_solr_create_delete(app, test_name, identifier, state, name, legal_type, bn):
"""Assert that solr docs can be updates/searched/deleted."""
def test_solr_create_delete(app, test_name, identifier, state, name, legal_type, bn, good_standing, expected_good_standing):
"""Assert that solr docs can be created/deleted."""
search_solr.init_app(app)
search_solr.delete_all_docs()
# add new doc
new_doc = create_solr_doc(identifier, name, state, legal_type, bn)
new_doc = create_solr_doc(identifier, name, state, legal_type, bn, None, good_standing)
added = search_solr.create_or_replace_docs([new_doc])
assert added.status_code == HTTPStatus.OK
time.sleep(2) # takes up to 1 second for solr to register update
Expand All @@ -67,6 +69,7 @@ def test_solr_create_delete(app, test_name, identifier, state, name, legal_type,
assert docs[0][SolrField.NAME.value] == name
assert docs[0][SolrField.STATE.value] == state
assert docs[0][SolrField.TYPE.value] == legal_type
assert docs[0].get(SolrField.GOOD_STANDING.value) == expected_good_standing
# delete doc
deleted = search_solr.delete_docs([identifier])
assert deleted.status_code == HTTPStatus.OK
Expand Down
3 changes: 2 additions & 1 deletion search-api/tests/unit/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
"legalName": "ABCD Prop",
"legalType": "SP",
"taxId": "123456789",
"state": "ACTIVE"
"state": "ACTIVE",
"goodStanding": "false"
},
"parties":[{
"officer": {
Expand Down

0 comments on commit 8667477

Please sign in to comment.