Skip to content

Commit

Permalink
feat: initial gh actions
Browse files Browse the repository at this point in the history
  • Loading branch information
lchen-2101 committed Sep 12, 2023
1 parent f4e05b2 commit a24c15b
Show file tree
Hide file tree
Showing 6 changed files with 142 additions and 29 deletions.
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
15 changes: 15 additions & 0 deletions .github/workflows/linters.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: Linters

on: [push]

jobs:
black:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: psf/black@stable
ruff:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- 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
14 changes: 13 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,19 @@ 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",
]

[build-system]
requires = ["poetry-core"]
Expand Down
18 changes: 13 additions & 5 deletions tests/entities/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,17 @@ async def td():


@pytest.fixture(scope="function")
async def session(engine: AsyncEngine):
Session = async_scoped_session(
async_sessionmaker(engine, expire_on_commit=False), current_task
)
async with Session() as 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
)
46 changes: 23 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,48 @@ 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):

Check failure on line 37 in tests/entities/repos/test_institutions_repo.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (E501)

tests/entities/repos/test_institutions_repo.py:37:89: E501 Line too long (94 > 88 characters)
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")

Check failure on line 43 in tests/entities/repos/test_institutions_repo.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (E501)

tests/entities/repos/test_institutions_repo.py:43:89: E501 Line too long (95 > 88 characters)
)
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")

Check failure on line 50 in tests/entities/repos/test_institutions_repo.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (E501)

tests/entities/repos/test_institutions_repo.py:50:89: E501 Line too long (97 > 88 characters)
)
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):

Check failure on line 56 in tests/entities/repos/test_institutions_repo.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (E501)

tests/entities/repos/test_institutions_repo.py:56:89: E501 Line too long (101 > 88 characters)
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, "test@yahoo.com") is False
assert await repo.is_email_domain_allowed(session, "test@gmail.com") is True
transaction_session.add(denied_domain)
await transaction_session.commit()
assert await repo.is_email_domain_allowed(transaction_session, "test@yahoo.com") is False

Check failure on line 69 in tests/entities/repos/test_institutions_repo.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (E501)

tests/entities/repos/test_institutions_repo.py:69:89: E501 Line too long (97 > 88 characters)
assert await repo.is_email_domain_allowed(transaction_session, "test@gmail.com") is True

Check failure on line 70 in tests/entities/repos/test_institutions_repo.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (E501)

tests/entities/repos/test_institutions_repo.py:70:89: E501 Line too long (96 > 88 characters)

0 comments on commit a24c15b

Please sign in to comment.