Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

birthdate format fix / preferred field typo fix #84

Merged
merged 5 commits into from
Dec 18, 2023
Merged
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
2 changes: 1 addition & 1 deletion .github/workflows/btr-api-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ jobs:
run: poetry run pytest --cov=./src --cov-report=xml

- name: Check coverage
run: poetry run coverage report
run: poetry run coverage report --fail-under=80

- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
Expand Down
4 changes: 2 additions & 2 deletions btr-api/migrations/versions/20231212_1530_4ce87b7566ff_.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def upgrade():
batch_op.drop_column('additional_text')

with op.batch_alter_table('persons', schema=None) as batch_op:
batch_op.add_column(sa.Column('preffered_name', sa.String(length=300), nullable=True))
batch_op.add_column(sa.Column('preferred_name', sa.String(length=300), nullable=True))
batch_op.add_column(sa.Column('birth_date', sa.Date(), nullable=True))
batch_op.add_column(sa.Column('email', sa.String(length=150), nullable=True))
batch_op.add_column(sa.Column('citizenships_ex_ca', postgresql.JSONB(astext_type=sa.Text()), nullable=True))
Expand Down Expand Up @@ -77,7 +77,7 @@ def downgrade():
batch_op.drop_column('citizenships_ex_ca')
batch_op.drop_column('email')
batch_op.drop_column('birth_date')
batch_op.drop_column('preffered_name')
batch_op.drop_column('preferred_name')

with op.batch_alter_table('ownership_details', schema=None) as batch_op:
batch_op.add_column(sa.Column('additional_text', sa.VARCHAR(length=2000), autoincrement=False, nullable=True))
Expand Down
3 changes: 0 additions & 3 deletions btr-api/setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,3 @@ filterwarnings =
markers =
slow
serial

[coverage:report]
fail_under=80
2 changes: 1 addition & 1 deletion btr-api/src/btr_api/models/person.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class Person(db.Model, BtrModelBase):
uuid = Column(UUID(as_uuid=True), default=uuid.uuid4) # used as external reference

full_name = Column(String(300), index=True, nullable=True)
preffered_name = Column(String(300), nullable=True)
preferred_name = Column(String(300), nullable=True)
family_name = Column(String(100), nullable=True)
given_name = Column(String(100), nullable=True)
patronymic_name = Column(String(100), nullable=True)
Expand Down
6 changes: 3 additions & 3 deletions btr-api/src/btr_api/services/person.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def from_dict(json_dict: dict) -> PersonModel:
"""Create Person from json dict"""
person = PersonModel()
person.full_name = json_dict.get('fullName')
person.preffered_name = json_dict.get('prefferedName')
person.preferred_name = json_dict.get('preferredName')
person.family_name = json_dict.get('familyName')
person.given_name = json_dict.get('givenName')
person.patronymic_name = json_dict.get('patronymicName')
Expand Down Expand Up @@ -78,8 +78,8 @@ def to_dict(person: PersonModel) -> dict:
return {
'uuid': person.uuid,
'fullName': person.full_name,
'prefferedName': person.preffered_name,
'birthDate': person.birth_date,
'preferredName': person.preferred_name,
'birthDate': person.birth_date.isoformat() if person.birth_date else None,
'competency': person.competency,
'email': person.email,
'hasTaxNumber': person.tax_number is not None,
Expand Down
6 changes: 3 additions & 3 deletions btr-api/tests/postman/btr-api.postman_collection.json
Original file line number Diff line number Diff line change
Expand Up @@ -213,23 +213,23 @@
},
{
"key": "Date",
"value": "Wed, 13 Dec 2023 21:40:11 GMT"
"value": "Fri, 15 Dec 2023 18:21:32 GMT"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldnt we b e using dates in ISO format ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep you're right -- think I just need to run the example again

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh wait nvm this is just in the header value (automatic from postman)

},
{
"key": "Content-Type",
"value": "application/json"
},
{
"key": "Content-Length",
"value": "907"
"value": "888"
},
{
"key": "Connection",
"value": "close"
}
],
"cookie": [],
"body": "[\n {\n \"controlType\": {\n \"directors\": {\n \"directControl\": true,\n \"inConcertControl\": true,\n \"indirectControl\": true,\n \"significantInfluence\": false\n },\n \"other\": \"\",\n \"sharesVotes\": {\n \"beneficialOwner\": false,\n \"inConcertControl\": true,\n \"indirectControl\": false,\n \"registeredOwner\": true\n }\n },\n \"endDate\": null,\n \"missingInfoReason\": null,\n \"percentOfShares\": 20,\n \"percentOfVotes\": 10,\n \"profile\": {\n \"address\": {\n \"city\": \"Vancouver\",\n \"country\": {\n \"alpha_2\": \"CA\",\n \"name\": \"Canada\"\n },\n \"line1\": \"111 test street\",\n \"line2\": null,\n \"postalCode\": \"V0E 1H5\",\n \"region\": \"BC\"\n },\n \"birthDate\": \"Sun, 19 Mar 2000 00:00:00 GMT\",\n \"citizenshipCA\": \"citizen\",\n \"citizenshipsExCa\": null,\n \"competency\": {\n \"decisionMaking\": true,\n \"financialAffairs\": true\n },\n \"email\": \"[email protected]\",\n \"fullName\": \"John Smith\",\n \"hasTaxNumber\": true,\n \"isTaxResident\": true,\n \"prefferedName\": null,\n \"taxNumber\": \"000 000 000\",\n \"uuid\": \"14d7608b-7d04-4a72-bca7-57cf713206f1\"\n },\n \"startDate\": \"2020-04-21\",\n \"uuid\": \"4ea1e7f1-6333-498f-b4a5-217032342cf7\"\n }\n]"
"body": "[\n {\n \"controlType\": {\n \"directors\": {\n \"directControl\": true,\n \"inConcertControl\": true,\n \"indirectControl\": true,\n \"significantInfluence\": false\n },\n \"other\": \"\",\n \"sharesVotes\": {\n \"beneficialOwner\": false,\n \"inConcertControl\": true,\n \"indirectControl\": false,\n \"registeredOwner\": true\n }\n },\n \"endDate\": null,\n \"missingInfoReason\": null,\n \"percentOfShares\": 20,\n \"percentOfVotes\": 10,\n \"profile\": {\n \"address\": {\n \"city\": \"Vancouver\",\n \"country\": {\n \"alpha_2\": \"CA\",\n \"name\": \"Canada\"\n },\n \"line1\": \"111 test street\",\n \"line2\": null,\n \"postalCode\": \"V0E 1H5\",\n \"region\": \"BC\"\n },\n \"birthDate\": \"2000-03-19\",\n \"citizenshipCA\": \"citizen\",\n \"citizenshipsExCa\": null,\n \"competency\": {\n \"decisionMaking\": true,\n \"financialAffairs\": true\n },\n \"email\": \"[email protected]\",\n \"fullName\": \"John Smith\",\n \"hasTaxNumber\": true,\n \"isTaxResident\": true,\n \"preferredName\": \"John\",\n \"taxNumber\": \"000 000 000\",\n \"uuid\": \"1ff28004-894e-43dc-af03-86aeb925d95e\"\n },\n \"startDate\": \"2020-04-21\",\n \"uuid\": \"482564ad-311e-4b48-85d3-d1199d2dc6b1\"\n }\n]"
}
]
}
Expand Down
27 changes: 20 additions & 7 deletions btr-api/tests/unit/services/test_person.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,16 @@
"""
import pytest

from btr_api.models import Person
from btr_api.services.person import PersonSerializer, PersonService

from tests.unit import nested_session

person_example = {
'fullName': 'This is persons full name',
'familyName': None,
'givenName': None,
'patronymicName': None,
'birthDate': '1980-01-01'
'preferredName': 'Preferred Name',
'email': '[email protected]',
'birthDate': '1980-01-01',
'taxNumber': '000 000 000'
}

owner_dict = {
Expand All @@ -26,7 +25,8 @@
("test ownership_details dic is converted to model", person_example),
],
)
def test_convert_dict_to_model(client, session, test_name, person_details_dict):
def test_convert_dict_to_model(session, test_name, person_details_dict):
"""Assure the from_dict serializer works as expected."""
with nested_session(session):
model = PersonSerializer.from_dict(person_details_dict)

Expand All @@ -42,13 +42,26 @@ def test_convert_dict_to_model(client, session, test_name, person_details_dict):
assert model.created_at is not None


@pytest.mark.parametrize("test_name, person_details_dict", [
("basic", person_example),
])
def test_convert_model_to_dict(client, session, test_name, person_details_dict):
"""Assure the to_dict serializer works as expected."""
with nested_session(session):
model = PersonSerializer.from_dict(person_details_dict)
model.save()
model_dict = PersonSerializer.to_dict(model)
for key in person_details_dict:
assert person_details_dict[key] == model_dict[key]


@pytest.mark.parametrize(
"test_name, submission_details_dict",
[
("test ownership_details dic is converted to model", owner_dict),
],
)
def test_create_model_from_json(session, test_name, submission_details_dict):
def test_create_model_from_owner(session, test_name, submission_details_dict):
"""Assure the create person method works as expected."""
with nested_session(session):
person = PersonService.create_person_from_owner(owner_dict)
Expand Down
Loading