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

Fix CI and move lint/docs to separate action for readability #1296

Merged
merged 6 commits into from
Mar 25, 2024
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
26 changes: 26 additions & 0 deletions .github/workflows/check-doc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Check doc

on:
push:
branches: [ 'master', 'stable-*' ]
pull_request:
branches: [ 'master', 'stable-*' ]

jobs:

test_doc:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.11"
cache: 'pip'
cache-dependency-path: '**/pyproject.toml'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install tox
- name: Check we can generate documentation
run: tox -e docs
4 changes: 2 additions & 2 deletions .github/workflows/dockerhub.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: CI to Docker Hub
name: Docker build

on:
push:
Expand All @@ -18,7 +18,7 @@ jobs:
- name: Test image # Checks we are able to run the container.
run: docker compose -f docker-compose.test.yml run sut

build:
build_upload:
runs-on: ubuntu-latest
needs: test
if: github.event_name != 'pull_request'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Test & Docs
name: Lint & unit tests

on:
push:
Expand All @@ -7,14 +7,31 @@ on:
branches: [ 'master', 'stable-*' ]

jobs:
build:

lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.11"
cache: 'pip'
cache-dependency-path: '**/pyproject.toml'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install tox
- name: Run Lint
run: tox -e lint

# Use postgresql and MariaDB versions of Debian buster
test:
# Dependency on linting to avoid running our expensive matrix test for nothing
needs: lint
runs-on: ubuntu-latest
# Use postgresql and MariaDB versions of Debian bookworm
services:
postgres:
image: postgres:11
image: postgres:15
ports:
- 5432:5432
env:
Expand All @@ -24,7 +41,7 @@ jobs:
options:
--health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
mariadb:
image: mariadb:10.3
image: mariadb:10.11
env:
MARIADB_ROOT_PASSWORD: ihatemoney
MARIADB_DATABASE: ihatemoney_ci
Expand All @@ -39,24 +56,29 @@ jobs:
python-version: [3.7, 3.8, 3.9, "3.10", "3.11", "3.12"]
dependencies: [normal]
database: [sqlite]
# Test other databases only with one version of Python (Debian buster has 3.7)
# Installation breaks with python 3.12, see https://github.com/spiral-project/ihatemoney/issues/1297
exclude:
- python-version: "3.12"
dependencies: normal
database: sqlite
# Test other databases with only a few versions of Python (Debian bullseye has 3.9, bookworm has 3.11)
include:
- python-version: 3.7
- python-version: 3.9
dependencies: normal
database: postgresql
- python-version: 3.7
- python-version: 3.9
dependencies: normal
database: mariadb
- python-version: 3.11
dependencies: normal
database: postgresql
- python-version: 3.11
dependencies: normal
database: mariadb
# Try a few variants with the minimal versions supported
- python-version: 3.7
dependencies: minimal
database: sqlite
- python-version: 3.7
dependencies: minimal
database: postgresql
- python-version: 3.7
dependencies: minimal
database: mariadb
- python-version: 3.9
dependencies: minimal
database: sqlite
Expand All @@ -66,6 +88,12 @@ jobs:
- python-version: "3.11"
dependencies: minimal
database: sqlite
- python-version: "3.11"
dependencies: minimal
database: postgresql
- python-version: "3.11"
dependencies: minimal
database: mariadb
- python-version: "3.12"
dependencies: minimal
database: sqlite
Expand Down Expand Up @@ -101,6 +129,3 @@ jobs:
if: matrix.database == 'mariadb'
env:
TESTING_SQLALCHEMY_DATABASE_URI: 'mysql+pymysql://root:ihatemoney@localhost:3306/ihatemoney_ci'
- name: Run Lint & Docs
run: tox -e lint_docs
if: matrix.python-version == '3.12'
7 changes: 6 additions & 1 deletion ihatemoney/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,12 @@ class BillForm(FlaskForm):
payed_for = SelectMultipleField(
_("For whom?"), validators=[DataRequired()], coerce=int
)
bill_type = SelectField(_("Bill Type"), choices=BillType.choices(), coerce=BillType, default=BillType.EXPENSE)
bill_type = SelectField(
_("Bill Type"),
choices=BillType.choices(),
coerce=BillType,
default=BillType.EXPENSE,
)
submit = SubmitField(_("Submit"))
submit2 = SubmitField(_("Submit and add a new one"))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ def upgrade():
billtype_enum = sa.Enum(BillType)
billtype_enum.create(op.get_bind(), checkfirst=True)

op.add_column("bill", sa.Column("bill_type", billtype_enum, server_default=BillType.EXPENSE.name))
op.add_column(
"bill",
sa.Column("bill_type", billtype_enum, server_default=BillType.EXPENSE.name),
)
op.add_column("bill_version", sa.Column("bill_type", sa.UnicodeText()))


Expand All @@ -28,4 +31,4 @@ def downgrade():
op.drop_column("bill_version", "bill_type")

billtype_enum = sa.Enum(BillType)
billtype_enum.drop(op.get_bind())
billtype_enum.drop(op.get_bind())
11 changes: 7 additions & 4 deletions ihatemoney/models.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from collections import defaultdict
from enum import Enum
import datetime
from enum import Enum
import itertools

from dateutil.parser import parse
Expand All @@ -22,7 +22,7 @@

from ihatemoney.currency_convertor import CurrencyConverter
from ihatemoney.monkeypath_continuum import PatchedTransactionFactory
from ihatemoney.utils import generate_password_hash, get_members, same_bill, FormEnum
from ihatemoney.utils import generate_password_hash, get_members, same_bill
from ihatemoney.versioning import (
ConditionalVersioningManager,
LoggingMode,
Expand Down Expand Up @@ -51,6 +51,7 @@
],
)


class BillType(Enum):
EXPENSE = "Expense"
REIMBURSEMENT = "Reimbursement"
Expand Down Expand Up @@ -131,7 +132,9 @@ def full_balance(self):
if bill.bill_type == BillType.EXPENSE:
should_receive[bill.payer.id] += bill.converted_amount
for ower in bill.owers:
should_pay[ower.id] += (ower.weight * bill.converted_amount / total_weight)
should_pay[ower.id] += (
ower.weight * bill.converted_amount / total_weight
)

if bill.bill_type == BillType.REIMBURSEMENT:
should_receive[bill.payer.id] += bill.converted_amount
Expand Down Expand Up @@ -563,7 +566,7 @@ def create_demo_project():
("Alice", 20, ("Amina", "Alice"), "Beer !", "Expense"),
("Amina", 50, ("Amina", "Alice", "Georg"), "AMAP", "Expense"),
)
for (payer, amount, owers, what, bill_type) in operations:
for payer, amount, owers, what, bill_type in operations:
db.session.add(
Bill(
amount=amount,
Expand Down
8 changes: 3 additions & 5 deletions ihatemoney/tests/api_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1017,7 +1017,6 @@ def test_amount_too_high(self):
def test_validate_bill_type(self):
self.api_create("raclette")
self.api_add_member("raclette", "zorglub")


req = self.client.post(
"/api/projects/raclette/bills",
Expand All @@ -1029,7 +1028,7 @@ def test_validate_bill_type(self):
"bill_type": "wrong_bill_type",
"amount": "50",
},
headers=self.get_auth("raclette")
headers=self.get_auth("raclette"),
)

self.assertStatus(400, req)
Expand All @@ -1044,7 +1043,7 @@ def test_validate_bill_type(self):
"bill_type": "Expense",
"amount": "50",
},
headers=self.get_auth("raclette")
headers=self.get_auth("raclette"),
)

self.assertStatus(201, req)
Expand All @@ -1063,7 +1062,7 @@ def test_default_bill_type(self):
"payed_for": ["1"],
"amount": "50",
},
headers=self.get_auth("raclette")
headers=self.get_auth("raclette"),
)

self.assertStatus(201, req)
Expand All @@ -1076,4 +1075,3 @@ def test_default_bill_type(self):
# Bill type should now be "Expense"
got = json.loads(req.data.decode("utf-8"))
assert got["bill_type"] == "Expense"

Loading
Loading