From 58246c3d2b7c11cea6ee53eaec79669b75bed3e5 Mon Sep 17 00:00:00 2001 From: Kial Jinnah Date: Fri, 15 Dec 2023 10:53:52 -0800 Subject: [PATCH 1/5] birthdate format fix / preferred field typo fix Signed-off-by: Kial Jinnah --- .../versions/20231212_1530_4ce87b7566ff_.py | 4 +-- btr-api/src/btr_api/models/person.py | 2 +- btr-api/src/btr_api/services/person.py | 6 ++--- .../postman/btr-api.postman_collection.json | 2 +- btr-api/tests/unit/services/test_person.py | 27 ++++++++++++++----- 5 files changed, 27 insertions(+), 14 deletions(-) diff --git a/btr-api/migrations/versions/20231212_1530_4ce87b7566ff_.py b/btr-api/migrations/versions/20231212_1530_4ce87b7566ff_.py index 6a4fae19..d4920f14 100644 --- a/btr-api/migrations/versions/20231212_1530_4ce87b7566ff_.py +++ b/btr-api/migrations/versions/20231212_1530_4ce87b7566ff_.py @@ -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)) @@ -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)) diff --git a/btr-api/src/btr_api/models/person.py b/btr-api/src/btr_api/models/person.py index bb69c4d9..c6abea23 100644 --- a/btr-api/src/btr_api/models/person.py +++ b/btr-api/src/btr_api/models/person.py @@ -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) diff --git a/btr-api/src/btr_api/services/person.py b/btr-api/src/btr_api/services/person.py index 54ccb6ca..034c725c 100644 --- a/btr-api/src/btr_api/services/person.py +++ b/btr-api/src/btr_api/services/person.py @@ -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') @@ -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, diff --git a/btr-api/tests/postman/btr-api.postman_collection.json b/btr-api/tests/postman/btr-api.postman_collection.json index 6ab88830..e7ec6a2a 100644 --- a/btr-api/tests/postman/btr-api.postman_collection.json +++ b/btr-api/tests/postman/btr-api.postman_collection.json @@ -229,7 +229,7 @@ } ], "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\": \"123@test.com\",\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\": \"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\": \"123@test.com\",\n \"fullName\": \"John Smith\",\n \"hasTaxNumber\": true,\n \"isTaxResident\": true,\n \"preferredName\": 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]" } ] } diff --git a/btr-api/tests/unit/services/test_person.py b/btr-api/tests/unit/services/test_person.py index ebec866f..ef9313bb 100644 --- a/btr-api/tests/unit/services/test_person.py +++ b/btr-api/tests/unit/services/test_person.py @@ -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@email.com', + 'birthDate': '1980-01-01', + 'taxNumber': '000 000 000' } owner_dict = { @@ -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) @@ -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) From 166c4099c8b72ba98b0f49b4feb963bda10c2dc9 Mon Sep 17 00:00:00 2001 From: Kial Jinnah Date: Fri, 15 Dec 2023 10:55:43 -0800 Subject: [PATCH 2/5] postman example update Signed-off-by: Kial Jinnah --- btr-api/tests/postman/btr-api.postman_collection.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/btr-api/tests/postman/btr-api.postman_collection.json b/btr-api/tests/postman/btr-api.postman_collection.json index e7ec6a2a..8ef91334 100644 --- a/btr-api/tests/postman/btr-api.postman_collection.json +++ b/btr-api/tests/postman/btr-api.postman_collection.json @@ -213,7 +213,7 @@ }, { "key": "Date", - "value": "Wed, 13 Dec 2023 21:40:11 GMT" + "value": "Fri, 15 Dec 2023 18:21:32 GMT" }, { "key": "Content-Type", @@ -221,7 +221,7 @@ }, { "key": "Content-Length", - "value": "907" + "value": "888" }, { "key": "Connection", @@ -229,7 +229,7 @@ } ], "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\": \"123@test.com\",\n \"fullName\": \"John Smith\",\n \"hasTaxNumber\": true,\n \"isTaxResident\": true,\n \"preferredName\": 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\": \"123@test.com\",\n \"fullName\": \"John Smith\",\n \"hasTaxNumber\": true,\n \"isTaxResident\": true,\n \"prefferedName\": null,\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]" } ] } From 870cd38974b4ac0c4d9184c382216871178671d9 Mon Sep 17 00:00:00 2001 From: Kial Jinnah Date: Fri, 15 Dec 2023 10:58:04 -0800 Subject: [PATCH 3/5] postman example update 2 Signed-off-by: Kial Jinnah --- btr-api/tests/postman/btr-api.postman_collection.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/btr-api/tests/postman/btr-api.postman_collection.json b/btr-api/tests/postman/btr-api.postman_collection.json index 8ef91334..1e0830c1 100644 --- a/btr-api/tests/postman/btr-api.postman_collection.json +++ b/btr-api/tests/postman/btr-api.postman_collection.json @@ -229,7 +229,7 @@ } ], "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\": \"2000-03-19\",\n \"citizenshipCA\": \"citizen\",\n \"citizenshipsExCa\": null,\n \"competency\": {\n \"decisionMaking\": true,\n \"financialAffairs\": true\n },\n \"email\": \"123@test.com\",\n \"fullName\": \"John Smith\",\n \"hasTaxNumber\": true,\n \"isTaxResident\": true,\n \"prefferedName\": null,\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]" + "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\": \"123@test.com\",\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]" } ] } From b51b883515eb23f950a290500113183e17702e92 Mon Sep 17 00:00:00 2001 From: Kial Jinnah Date: Fri, 15 Dec 2023 11:01:55 -0800 Subject: [PATCH 4/5] prevent coverage from failing pytest CI step as it runs afterwards in its own step Signed-off-by: Kial Jinnah --- .github/workflows/btr-api-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/btr-api-ci.yml b/.github/workflows/btr-api-ci.yml index 557380e1..ca266335 100644 --- a/.github/workflows/btr-api-ci.yml +++ b/.github/workflows/btr-api-ci.yml @@ -80,7 +80,7 @@ jobs: poetry run flask db migrate - name: Run tests - run: poetry run pytest --cov=./src --cov-report=xml + run: poetry run pytest - name: Check coverage run: poetry run coverage report From c5cb19ad51bbb7ad0a9d3f0cf6a9a983ea8030de Mon Sep 17 00:00:00 2001 From: Kial Jinnah Date: Fri, 15 Dec 2023 11:12:47 -0800 Subject: [PATCH 5/5] coverage ci flow fix Signed-off-by: Kial Jinnah --- .github/workflows/btr-api-ci.yml | 4 ++-- btr-api/setup.cfg | 3 --- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/.github/workflows/btr-api-ci.yml b/.github/workflows/btr-api-ci.yml index ca266335..43faef51 100644 --- a/.github/workflows/btr-api-ci.yml +++ b/.github/workflows/btr-api-ci.yml @@ -80,10 +80,10 @@ jobs: poetry run flask db migrate - name: Run tests - run: poetry run pytest + 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 diff --git a/btr-api/setup.cfg b/btr-api/setup.cfg index 02af1f04..6918e118 100644 --- a/btr-api/setup.cfg +++ b/btr-api/setup.cfg @@ -31,6 +31,3 @@ filterwarnings = markers = slow serial - -[coverage:report] -fail_under=80