Skip to content

Commit

Permalink
19803 - Tweaks for simple org for EFT (#2723)
Browse files Browse the repository at this point in the history
* Change status -> statuses. Also return status on the response

* fix unit test

* Add in new parameter, excludeStatuses, minor unit test

* Remove redundant comments

* Fix lint
seeker25 authored Feb 14, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent 144152e commit 327fd67
Showing 5 changed files with 30 additions and 21 deletions.
5 changes: 3 additions & 2 deletions auth-api/src/auth_api/models/dataclass.py
Original file line number Diff line number Diff line change
@@ -123,14 +123,15 @@ class OrgSearch: # pylint: disable=too-many-instance-attributes


@dataclass
class SimpleOrgSearch:
class SimpleOrgSearch: # pylint: disable=too-many-instance-attributes
"""Used for searching organizations."""

id: str
name: str
branch_name: str
search_text: str
status: str
statuses: List[str] = field()
exclude_statuses: bool
page: int
limit: int

9 changes: 6 additions & 3 deletions auth-api/src/auth_api/resources/v1/org.py
Original file line number Diff line number Diff line change
@@ -111,16 +111,19 @@ def search_simple_orgs():
name = request.args.get('name', None)
branch_name = request.args.get('branchName', None)
search_text = request.args.get('searchText', None)
status = request.args.get('status', OrgStatus.ACTIVE.value)
statuses = request.args.getlist('statuses') or [OrgStatus.ACTIVE.value]
exclude_statuses = request.args.get('excludeStatuses', False)

response, status = SimpleOrgService.search(SimpleOrgSearch(
id=org_id,
name=name,
branch_name=branch_name,
search_text=search_text,
status=status,
statuses=statuses,
exclude_statuses=exclude_statuses,
page=page,
limit=limit)), http_status.HTTP_200_OK
limit=limit
)), http_status.HTTP_200_OK

current_app.logger.info('>search_simple_orgs')
return jsonify(response), status
4 changes: 3 additions & 1 deletion auth-api/src/auth_api/schemas/simple_org.py
Original file line number Diff line number Diff line change
@@ -25,6 +25,7 @@ class SimpleOrgInfoSchema: # pylint: disable=too-few-public-methods
id: int
name: str
branch_name: str
status: str

@classmethod
def from_row(cls, row: Org):
@@ -34,4 +35,5 @@ def from_row(cls, row: Org):
"""
return cls(id=row.id,
name=row.name,
branch_name=row.branch_name)
branch_name=row.branch_name,
status=row.status_code)
6 changes: 5 additions & 1 deletion auth-api/src/auth_api/services/simple_org.py
Original file line number Diff line number Diff line change
@@ -39,6 +39,7 @@ def __init__(self, model):
"""Return a simple org service instance."""
self._model = model

# Currently this method is only being used by EFT linking.
@classmethod
def search(cls, search_criteria: SimpleOrgSearch):
"""Search org records and returned a simplified result set."""
@@ -47,7 +48,10 @@ def search(cls, search_criteria: SimpleOrgSearch):

query = query.filter_conditionally(search_criteria.id, OrgModel.id, is_like=True)
query = query.filter_conditionally(search_criteria.name, OrgModel.name, is_like=True)
query = query.filter_conditionally(search_criteria.status, OrgModel.status_code)
if search_criteria.exclude_statuses:
query = query.filter(OrgModel.status_code.notin_(search_criteria.statuses))
else:
query = query.filter(OrgModel.status_code.in_(search_criteria.statuses))

# OrgModel.branch_name default value is '', so we need to check for this
if search_criteria.branch_name:
27 changes: 13 additions & 14 deletions auth-api/tests/unit/api/test_simple_org.py
Original file line number Diff line number Diff line change
@@ -37,8 +37,6 @@ def assert_simple_org(result_dict: dict, org: OrgModel):

def test_simple_org_search(client, jwt, session, keycloak_mock): # pylint:disable=unused-argument
"""Assert that an org can be searched using multiple syntax."""
# Create active org

org_inactive = OrgModel(name='INACTIVE TST ORG',
branch_name='INACTIVE TST BRANCH NAME',
type_code=OrgType.PREMIUM.value,
@@ -64,8 +62,19 @@ def test_simple_org_search(client, jwt, session, keycloak_mock): # pylint:disab

headers = factory_auth_header(jwt=jwt, claims=TestJwtClaims.manage_eft_role)

# Assert status filter by inactive orgs
rv = client.get(f'/api/v1/orgs/simple?status={OrgStatus.INACTIVE.value}',
rv = client.get(f'/api/v1/orgs/simple?statuses={OrgStatus.INACTIVE.value}',
headers=headers, content_type='application/json')

result = rv.json
assert rv.status_code == http_status.HTTP_200_OK
assert result['items']
assert len(result['items']) == 1
assert result['page'] == 1
assert result['total'] == 1
assert result['limit'] == 10
assert_simple_org(result['items'][0], org_inactive)

rv = client.get(f'/api/v1/orgs/simple?statuses={OrgStatus.ACTIVE.value}&excludeStatuses=true',
headers=headers, content_type='application/json')

result = rv.json
@@ -92,7 +101,6 @@ def test_simple_org_search(client, jwt, session, keycloak_mock): # pylint:disab
assert_simple_org(result['items'][2], org_no_branch_1)
assert_simple_org(result['items'][3], org_no_branch_2)

# Assert search id
rv = client.get(f'/api/v1/orgs/simple?id={org_no_branch_1.id}', headers=headers, content_type='application/json')

result = rv.json
@@ -104,7 +112,6 @@ def test_simple_org_search(client, jwt, session, keycloak_mock): # pylint:disab
assert result['limit'] == 10
assert_simple_org(result['items'][0], org_no_branch_1)

# Assert search id
rv = client.get(f'/api/v1/orgs/simple?id={org_no_branch_1.id}', headers=headers, content_type='application/json')

result = rv.json
@@ -116,7 +123,6 @@ def test_simple_org_search(client, jwt, session, keycloak_mock): # pylint:disab
assert result['limit'] == 10
assert_simple_org(result['items'][0], org_no_branch_1)

# Assert search name
rv = client.get('/api/v1/orgs/simple?name=Name 2', headers=headers, content_type='application/json')

result = rv.json
@@ -129,7 +135,6 @@ def test_simple_org_search(client, jwt, session, keycloak_mock): # pylint:disab
assert_simple_org(result['items'][0], org_branch_2)
assert_simple_org(result['items'][1], org_no_branch_2)

# Assert search branch name
rv = client.get('/api/v1/orgs/simple?branchName=branch', headers=headers, content_type='application/json')

result = rv.json
@@ -142,7 +147,6 @@ def test_simple_org_search(client, jwt, session, keycloak_mock): # pylint:disab
assert_simple_org(result['items'][0], org_branch_1)
assert_simple_org(result['items'][1], org_branch_2)

# Assert search branch name
rv = client.get('/api/v1/orgs/simple?branchName=ch 1', headers=headers, content_type='application/json')

result = rv.json
@@ -154,7 +158,6 @@ def test_simple_org_search(client, jwt, session, keycloak_mock): # pylint:disab
assert result['limit'] == 10
assert_simple_org(result['items'][0], org_branch_1)

# Assert search text with id
rv = client.get(f'/api/v1/orgs/simple?searchText={org_no_branch_2.id}', headers=headers,
content_type='application/json')

@@ -167,7 +170,6 @@ def test_simple_org_search(client, jwt, session, keycloak_mock): # pylint:disab
assert result['limit'] == 10
assert_simple_org(result['items'][0], org_no_branch_2)

# Assert search text with name
rv = client.get('/api/v1/orgs/simple?searchText=name 1', headers=headers, content_type='application/json')

result = rv.json
@@ -180,7 +182,6 @@ def test_simple_org_search(client, jwt, session, keycloak_mock): # pylint:disab
assert_simple_org(result['items'][0], org_branch_1)
assert_simple_org(result['items'][1], org_no_branch_1)

# Assert search text with branch name
rv = client.get('/api/v1/orgs/simple?searchText=ch 1', headers=headers, content_type='application/json')

result = rv.json
@@ -192,7 +193,6 @@ def test_simple_org_search(client, jwt, session, keycloak_mock): # pylint:disab
assert result['limit'] == 10
assert_simple_org(result['items'][0], org_branch_1)

# Assert page 1
rv = client.get('/api/v1/orgs/simple?page=1&limit=1', headers=headers, content_type='application/json')

result = rv.json
@@ -204,7 +204,6 @@ def test_simple_org_search(client, jwt, session, keycloak_mock): # pylint:disab
assert result['limit'] == 1
assert_simple_org(result['items'][0], org_branch_1)

# Assert page 2
rv = client.get('/api/v1/orgs/simple?page=2&limit=1', headers=headers, content_type='application/json')

result = rv.json

0 comments on commit 327fd67

Please sign in to comment.