Skip to content

Commit

Permalink
23362 Fetch Endpoint for FED Filings (bcgov#3125)
Browse files Browse the repository at this point in the history
* 23363 - Add search endpoint to filings

* 23363 - Update endpoint for FED

* 23363 - Add unit tests

* 23363 - Remove timezone from datetime import

* 23362-Simplify logic for effective date

* 23362 - Update tests assertions

* 23362-Changes-requested-from-pr
  • Loading branch information
meawong authored Dec 16, 2024
1 parent 7d55ce1 commit d9d8a35
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,24 @@ def patch_filings(identifier, filing_id=None):
return jsonify(filing.json), HTTPStatus.ACCEPTED


@bp.route('/filings/search/<int:filing_id>', methods=['GET'])
@cross_origin(origin='*')
@jwt.has_one_of_roles([UserRoles.staff])
def get_single_filing_by_filing_id(filing_id):
"""Return a single filing by filing ID."""
try:
filing_query = Filing.find_by_id(filing_id)

if not filing_query:
return {'message': f'Filing with ID {filing_id} not found.'}, HTTPStatus.NOT_FOUND

return jsonify(filing_query.json), HTTPStatus.OK

except Exception as err:
current_app.logger.error('Error retrieving filing data for ID %s: %s', filing_id, err)
return {'error': 'Unable to retrieve filing data.'}, HTTPStatus.INTERNAL_SERVER_ERROR


class ListFilingResource(): # pylint: disable=too-many-public-methods
"""Business Filings service."""

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,33 @@ def test_get_temp_business_filing(session, client, jwt, legal_type, filing_type,
assert rv.json['filing'][filing_type] == filing_json


def test_get_filing_not_found(session, client, jwt):
"""Assert that the request fails if the filing ID doesn't match an existing filing."""
rv = client.get('/api/v2/businesses/filings/search/99999',
headers=create_header(jwt, [STAFF_ROLE]))

assert rv.status_code == HTTPStatus.NOT_FOUND
assert rv.json == {'message': 'Filing with ID 99999 not found.'}


def test_get_filing_valid_filing_id(session, client, jwt):
"""Assert that a valid filing ID returns the correct filing."""

identifier = 'CP7654321'
b = factory_business(identifier)

filing_data = copy.deepcopy(ANNUAL_REPORT)
filing = factory_filing(b, filing_data)

rv = client.get(f'/api/v2/businesses/filings/search/{filing.id}',
headers=create_header(jwt, [STAFF_ROLE]))

assert rv.status_code == HTTPStatus.OK
assert 'filing' in rv.json
assert rv.json['filing']['annualReport'] == ANNUAL_REPORT['filing']['annualReport']
assert rv.json['filing']['business'] == ANNUAL_REPORT['filing']['business']


def test_get_one_business_filing_by_id(session, client, jwt):
"""Assert that the business info cannot be received in a valid JSONSchema format."""
identifier = 'CP7654321'
Expand Down

0 comments on commit d9d8a35

Please sign in to comment.