Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion colin-api/src/colin_api/models/business_snapshot.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,14 @@ def _normalize_party(cls, party: Party) -> Dict:
'officer': {**raw['officer'], 'id': raw['id'], 'email': None},
'deliveryAddress': cls._normalize_address(raw['deliveryAddress']),
'mailingAddress': cls._normalize_address(raw['mailingAddress']),
'roles': raw['roles'] or [],
'roles': [
{
'roleType': role.get('roleType'),
'appointmentDate': cls._to_iso_date(role.get('appointmentDate')),
'cessationDate': cls._to_iso_date(role.get('cessationDate')),
}
for role in (raw['roles'] or [])
],
}

@classmethod
Expand Down Expand Up @@ -201,3 +208,12 @@ def _to_iso_datetime(value: Optional[str]) -> Optional[str]:
if value and value.endswith('-00:00'):
return value[:-6] + '+00:00'
return value

@staticmethod
def _to_iso_date(value) -> Optional[str]:
"""Coerce a role date to YYYY-MM-DD preserving None."""
if value is None:
return None
if isinstance(value, datetime):
return value.strftime('%Y-%m-%d')
return str(value)[:10]
2 changes: 1 addition & 1 deletion colin-api/src/colin_api/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@
Development release segment: .devN
"""

__version__ = '2.172.1' # pylint: disable=invalid-name
__version__ = '2.172.2' # pylint: disable=invalid-name
23 changes: 22 additions & 1 deletion colin-api/tests/unit/api/test_business_snapshot.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@
# limitations under the License.

"""Tests to assure the business snapshot end-point."""
from datetime import datetime

from colin_api.exceptions import BusinessNotFoundException, PartiesNotFoundException
from colin_api.models import Business, Party, ShareObject
from tests.unit import LEAR_ADDRESS, build_business, bypass_auth
from tests.unit import LEAR_ADDRESS, build_business, build_director, bypass_auth


SNAPSHOT_URL = '/api/v1/businesses/BC0870226/snapshot'
Expand Down Expand Up @@ -109,6 +111,25 @@ def test_get_snapshot_reports_future_effective_filing(client, mocker, authorized
assert 'effective_dt' in mock_db.cursor.execute.call_args.args[0]


def test_get_snapshot_normalizes_role_dates(client, mocker, authorized, mock_db,
mock_lookups): # pylint: disable=unused-argument
"""Assert a raw datetime role date (the founding-date fallback) is normalized to YYYY-MM-DD."""
director = build_director()
director.roles = [{
'roleType': 'Director',
'appointmentDate': datetime(2013, 4, 24, 0, 0),
'cessationDate': None
}]
mocker.patch.object(Party, 'get_current', return_value=[director])

rv = client.get(SNAPSHOT_URL)

assert rv.status_code == 200
assert rv.json['parties'][0]['roles'] == [
{'roleType': 'Director', 'appointmentDate': '2013-04-24', 'cessationDate': None}
]


def test_get_snapshot_without_parties(client, mocker, authorized, mock_db,
mock_lookups): # pylint: disable=unused-argument
"""Assert a corp with no current directors on file still returns a snapshot."""
Expand Down
Loading