-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
8 changed files
with
164 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
name: Coverage | ||
|
||
on: | ||
workflow_run: | ||
workflows: ["Tests"] | ||
types: | ||
- completed | ||
|
||
jobs: | ||
coverage: | ||
name: Run tests & display coverage | ||
runs-on: ubuntu-latest | ||
if: github.event.workflow_run.event == 'pull_request' && github.event.workflow_run.conclusion == 'success' | ||
permissions: | ||
# Gives the action the necessary permissions for publishing new | ||
# comments in pull requests. | ||
pull-requests: write | ||
# Gives the action the necessary permissions for editing existing | ||
# comments (to avoid publishing multiple comments in the same PR) | ||
contents: write | ||
# Gives the action the necessary permissions for looking up the | ||
# workflow that launched this workflow, and download the related | ||
# artifact that contains the comment to be published | ||
actions: read | ||
steps: | ||
- name: Post comment | ||
uses: py-cov-action/python-coverage-comment-action@v3 | ||
with: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
GITHUB_PR_RUN_ID: ${{ github.event.workflow_run.id }} | ||
verbose: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
name: Linters | ||
|
||
on: [push] | ||
|
||
jobs: | ||
linting: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- uses: psf/black@stable | ||
- uses: chartboost/ruff-action@v1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
name: Tests | ||
|
||
on: | ||
pull_request: | ||
push: | ||
branches: | ||
- "main" | ||
|
||
jobs: | ||
unit-tests: | ||
runs-on: ubuntu-latest | ||
permissions: | ||
# Gives the action the necessary permissions for publishing new | ||
# comments in pull requests. | ||
pull-requests: write | ||
# Gives the action the necessary permissions for pushing data to the | ||
# python-coverage-comment-action branch, and for editing existing | ||
# comments (to avoid publishing multiple comments in the same PR) | ||
contents: write | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Set up Python 3.11 | ||
uses: actions/setup-python@v4 | ||
with: | ||
python-version: 3.11 | ||
- name: Install dependencies | ||
run: | | ||
python -m pip install --upgrade pip | ||
pip install poetry | ||
poetry config virtualenvs.create false | ||
poetry install --no-root | ||
- name: Launch tests & generate report | ||
run: poetry run pytest | ||
- name: Coverage comment | ||
id: coverage_comment | ||
uses: py-cov-action/python-coverage-comment-action@v3 | ||
with: | ||
GITHUB_TOKEN: ${{ github.token }} | ||
verbose: true | ||
- name: Store Pull Request comment to be posted | ||
uses: actions/upload-artifact@v3 | ||
if: steps.coverage_comment.outputs.COMMENT_FILE_WRITTEN == 'true' | ||
with: | ||
# If you use a different name, update COMMENT_ARTIFACT_NAME accordingly | ||
name: python-coverage-comment-action | ||
# If you use a different name, update COMMENT_FILENAME accordingly | ||
path: python-coverage-comment-action.txt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,7 +14,7 @@ class TestInstitutionsRepo: | |
@pytest.fixture(scope="function", autouse=True) | ||
async def setup( | ||
self, | ||
session: AsyncSession, | ||
transaction_session: AsyncSession, | ||
): | ||
fi_dao = FinancialInstitutionDao( | ||
name="Test Bank 123", | ||
|
@@ -23,48 +23,60 @@ async def setup( | |
FinancialInstitutionDomainDao(domain="test.bank", lei="TESTBANK123") | ||
], | ||
) | ||
session.add(fi_dao) | ||
await session.commit() | ||
transaction_session.add(fi_dao) | ||
await transaction_session.commit() | ||
|
||
async def test_get_institutions(self, session: AsyncSession): | ||
res = await repo.get_institutions(session) | ||
async def test_get_institutions(self, query_session: AsyncSession): | ||
res = await repo.get_institutions(query_session) | ||
assert len(res) == 1 | ||
|
||
async def test_get_institutions_by_domain(self, session: AsyncSession): | ||
res = await repo.get_institutions(session, domain="test.bank") | ||
async def test_get_institutions_by_domain(self, query_session: AsyncSession): | ||
res = await repo.get_institutions(query_session, domain="test.bank") | ||
assert len(res) == 1 | ||
|
||
async def test_get_institutions_by_domain_not_existing(self, session: AsyncSession): | ||
res = await repo.get_institutions(session, domain="testing.bank") | ||
async def test_get_institutions_by_domain_not_existing( | ||
self, query_session: AsyncSession | ||
): | ||
res = await repo.get_institutions(query_session, domain="testing.bank") | ||
assert len(res) == 0 | ||
|
||
async def test_add_institution(self, session: AsyncSession): | ||
async def test_add_institution(self, transaction_session: AsyncSession): | ||
await repo.upsert_institution( | ||
session, FinancialInstitutionDao(name="New Bank 123", lei="NEWBANK123") | ||
transaction_session, | ||
FinancialInstitutionDao(name="New Bank 123", lei="NEWBANK123"), | ||
) | ||
res = await repo.get_institutions(session) | ||
res = await repo.get_institutions(transaction_session) | ||
assert len(res) == 2 | ||
|
||
async def test_update_institution(self, session: AsyncSession): | ||
async def test_update_institution(self, transaction_session: AsyncSession): | ||
await repo.upsert_institution( | ||
session, FinancialInstitutionDao(name="Test Bank 234", lei="TESTBANK123") | ||
transaction_session, | ||
FinancialInstitutionDao(name="Test Bank 234", lei="TESTBANK123"), | ||
) | ||
res = await repo.get_institutions(session) | ||
res = await repo.get_institutions(transaction_session) | ||
assert len(res) == 1 | ||
assert res[0].name == "Test Bank 234" | ||
|
||
async def test_add_domains(self, session: AsyncSession): | ||
async def test_add_domains( | ||
self, transaction_session: AsyncSession, query_session: AsyncSession | ||
): | ||
await repo.add_domains( | ||
session, | ||
transaction_session, | ||
"TESTBANK123", | ||
[FinancialInsitutionDomainCreate(domain="bank.test")], | ||
) | ||
fi = await repo.get_institution(session, "TESTBANK123") | ||
fi = await repo.get_institution(query_session, "TESTBANK123") | ||
assert len(fi.domains) == 2 | ||
|
||
async def test_domain_allowed(self, session: AsyncSession): | ||
async def test_domain_allowed(self, transaction_session: AsyncSession): | ||
denied_domain = DeniedDomainDao(domain="yahoo.com") | ||
session.add(denied_domain) | ||
await session.commit() | ||
assert await repo.is_email_domain_allowed(session, "[email protected]") is False | ||
assert await repo.is_email_domain_allowed(session, "[email protected]") is True | ||
transaction_session.add(denied_domain) | ||
await transaction_session.commit() | ||
assert ( | ||
await repo.is_email_domain_allowed(transaction_session, "[email protected]") | ||
is False | ||
) | ||
assert ( | ||
await repo.is_email_domain_allowed(transaction_session, "[email protected]") | ||
is True | ||
) |