Skip to content

Commit

Permalink
Merge branch 'main' into feature/26_update_auth_user_model
Browse files Browse the repository at this point in the history
  • Loading branch information
lchen-2101 committed Sep 14, 2023
2 parents 9b840aa + 42fbf3a commit 1687cf1
Show file tree
Hide file tree
Showing 9 changed files with 164 additions and 56 deletions.
28 changes: 0 additions & 28 deletions .github/ISSUE_TEMPLATE/default-issue-template.md

This file was deleted.

31 changes: 31 additions & 0 deletions .github/workflows/coverage.yml
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
11 changes: 11 additions & 0 deletions .github/workflows/linters.yml
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
47 changes: 47 additions & 0 deletions .github/workflows/tests.yml
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
19 changes: 19 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,26 @@ asyncio_mode = "auto"
pythonpath = [
"src"
]
addopts = [
"--cov-report=term-missing",
"--cov-branch",
"--cov-report=xml",
"--cov-report=term",
"--cov=src",
"-vv",
"--strict-markers",
"-rfE",
]
testpaths = [
"tests",
]

[tool.coverage.run]
relative_files = true
source = ["src"]

[tool.coverage.report]
skip_empty = true

[build-system]
requires = ["poetry-core"]
Expand Down
6 changes: 5 additions & 1 deletion src/oauth2/oauth2_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@ def get_claims(self, token: str) -> Dict[str, str] | None:
key=self._get_keys(),
issuer=os.getenv("KC_REALM_URL"),
audience=os.getenv("AUTH_CLIENT"),
options={"verify_at_hash": False, "verify_aud": False, "verify_iss": False},
options={
"verify_at_hash": False,
"verify_aud": False,
"verify_iss": False,
},
)
except jose.ExpiredSignatureError:
pass
Expand Down
2 changes: 2 additions & 0 deletions tests/api/routers/test_institutions_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ def test_get_institution_authed(

def test_add_domains_unauthed(self, app_fixture: FastAPI, unauthed_user_mock: Mock):
client = TestClient(app_fixture)

lei_path = "testLeiPath"
res = client.post(
f"/v1/institutions/{lei_path}/domains/", json=[{"domain": "testDomain"}]
Expand All @@ -129,6 +130,7 @@ def test_add_domains_authed(
FinancialInstitutionDomainDao(domain="test.bank", lei="TESTBANK123")
]
client = TestClient(app_fixture)

lei_path = "testLeiPath"
res = client.post(
f"/v1/institutions/{lei_path}/domains/", json=[{"domain": "testDomain"}]
Expand Down
18 changes: 14 additions & 4 deletions tests/entities/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,19 @@ async def td():


@pytest.fixture(scope="function")
async def session(engine: AsyncEngine):
Session = async_scoped_session(
async def transaction_session(session_generator: async_scoped_session):
async with session_generator() as session:
yield session


@pytest.fixture(scope="function")
async def query_session(session_generator: async_scoped_session):
async with session_generator() as session:
yield session


@pytest.fixture(scope="function")
def session_generator(engine: AsyncEngine):
return async_scoped_session(
async_sessionmaker(engine, expire_on_commit=False), current_task
)
async with Session() as session:
yield session
58 changes: 35 additions & 23 deletions tests/entities/repos/test_institutions_repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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
)

0 comments on commit 1687cf1

Please sign in to comment.